Giter VIP home page Giter VIP logo

Comments (3)

mcronce avatar mcronce commented on August 22, 2024

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.

Bas-Man avatar Bas-Man commented on August 22, 2024

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.

Bas-Man avatar Bas-Man commented on August 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.