/grammarParse.p6 Secret
Created
April 17, 2018 00:04
Star
You must be signed in to star a gist
for learning exercise, trying to parse a torrent name
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use v6; | |
| use Grammar::Debugger; | |
| grammar PTN { | |
| token TOP {[ | |
| <year> | |
| | <season> | |
| | <episode> | |
| | <resolution> | |
| | <quality> | |
| | <codec> | |
| | <audio> | |
| | <group> | |
| | <region> | |
| | <extended> | |
| | <hardcoded> | |
| | <proper> | |
| | <repack> | |
| | <container> | |
| | <widescreen> | |
| | <language> | |
| | <sbs> | |
| | <unrated> | |
| | <size> | |
| | <threeD> | |
| | <sep> | |
| ]* } | |
| token season {:i s? (<[0..9]> ** 1..2 ) } | |
| token episode {:i <[ex]> (<[0..9]> ** 2) [<-[0..9]>| $] } | |
| token year { <[ \[ \(]>? [19 <[0..9]> | 20 <[0..1]>] <[0..9]> <[ \] \)]>? } | |
| token resolution {:i <[0..9]> ** 3..4 p } | |
| token quality { :i ( [PPV\.]? <[HP]>DTV | [HD]? CAM | B[DR]Rip | [HD"-"?]? TS | [PPV]? WEB \-? DL [DVDRip]? | |
| | HDRip | DVDRip | DvDScr | CamRip | W <[EB]> BRip | BluRay | telesync ) } | |
| token codec {:i ([xvid | <[hx]> ] \.? 26 <[45]>) } | |
| token audio {:i ([MP3 | DD5 \.? 1 | Dual <[\- \s ]>] Audio | LiNE | DTS | AAC <[ \. ]> LC | AAC [\.? 2\.0]? | AC3 [\.5\.1]?) } | |
| token group {:i (\- \s? (<-[\-]>+ [\- \= \{ <-[\-]>+ \-?$]?))$ } | |
| token region {:i (R <[0..9]>) } | |
| token extended {:i (EXTENDED [.CUT]?) } | |
| token hardcoded {:i (HC) } | |
| token proper {:i (PROPER) } | |
| token repack {:i (REPACK) } | |
| token container {:i ([MKV | AVI | MP4]) } | |
| token widescreen {:i (WS) } | |
| token language {:i (rus\.eng | ita\.eng) } | |
| token sbs {:i ([Half"-"]? SBS) } | |
| token unrated {:i (UNRATED) } | |
| token size {:i (\d+ [\. \d+]? [GB|MB]) } | |
| token threeD {:i (3D) } | |
| token sep { \s | "." } | |
| } | |
| my $match = PTN.parse('s02e03.1080p hdtv AAC2 2015.REPACK x265'); # this matches just fine. As you may notice, there is no title of show | |
| say $match; | |
| $match = PTN.parse('The Simpsons s02e03.1080p hdtv AAC2 2015.REPACK x265'); #this fails because I don't know how to account for an unknown title |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment