Comments (3)
Haha I haven't had a chance to clean this up and make it PR ready yet but if there's interest I will prioritize :)
from torrent-name-parser.
Haha I haven't had a chance to clean this up and make it PR ready yet but if there's interest I will prioritize :)
I am not sure if this would interest you. but you might be able to simplify this code block at the regex matching level
impl FromStr for Codec {
type Err = Error;
fn from_str(input: &str) -> Result<Self, Self::Err> {
match input {
"X264"|"x264"|"H264"|"h264"|"H.264"|"h.264" => Ok(Self::X264),
"X265"|"x265"|"H265"|"h265"|"H.265"|"h.265" => Ok(Self::X265),
"HEVC"|"HEVc"|"HEvC"|"HEvc"|"HeVC"|"HeVc"|"HevC"|"Hevc" => Ok(Self::X265),
"hEVC"|"hEVc"|"hEvC"|"hEvc"|"heVC"|"heVc"|"hevC"|"hevc" => Ok(Self::X265),
"XVID"|"XVId"|"XViD"|"XVid"|"XvID"|"XvId"|"XviD"|"Xvid" => Ok(Self::Xvid),
"xVID"|"xVId"|"xViD"|"xVid"|"xvID"|"xvId"|"xviD"|"xvid" => Ok(Self::Xvid),
s => Err(Error::InvalidCodec(s.into()))
}
}
replace the codec regex with
pub static ref CODEC: Pattern =
r"(?i)(?:(?P<x264>[xh][.]?264)|(?P<x265>[xh]\.?265)|(?P<hevc>hevc)|(?P<xvid>xvid))";
This regex matches all 44 string patterns you are using. Though looking at the code you would need to a function that returned a Enum::Codec instead of a str.... and bases that on a .name("x254").or....
So might not be so useful.
Here is the link to a tool I used to test the regex link
from torrent-name-parser.
Haha I haven't had a chance to clean this up and make it PR ready yet but if there's interest I will prioritize :)
I am not sure if this would interest you. but you might be able to simplify this code block at the regex matching level
Another option might be the regex set which allows you to test which pattern matched.
See here
let set = RegexSet::new(&[
r"[xh]\.264",
r"[xh]\.265",
...
...,
]).unwrap();
// You can also test whether a particular regex matched:
let matches = set.matches("foobar");
assert!(!matches.matched(5));
assert!(matches.matched(6));
from torrent-name-parser.
Related Issues (18)
- Add Country as a field that can be captured? HOT 2
- Shorten some Regex patterns by enabling case-insensitive option (?i) HOT 1
- Re-implement Metadata::from using trait FromStr which provides the parse() call. HOT 2
- Season & Episode converted from string to digits HOT 3
- Add support for file extensions (avi, mkv, mp4 and so on) HOT 4
- Thoughts of additional functionality for discussion HOT 4
- Episode Regex Matching Multiple Episode / use of full word `episode` HOT 3
- Fail to match on file with .SXX. for Season pattern
- How to solve title name reconstruction HOT 1
- Update Regex version to 1.5.5 CVE-2022-24713 HOT 1
- Is it possible to decipher the whole paths ? HOT 1
- Needs a license file. HOT 1
- Show Title "The Last of Us" not parsed correctly. HOT 1
- Warning: Future code incompatibility. HOT 1
- resolution not detected
- Recognize "WEB" (without "-DL" or "Rip") as a quality HOT 2
- Parse season and episode number when they are separated by `-`. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from torrent-name-parser.