Skip to content

Commit

Permalink
New:
Browse files Browse the repository at this point in the history
+ Added Language: Hindi
+ Added iPhone to iOS matching
+ Added different DTS Audio formats: DTS, DTS-ES, DTS-HD, DTS:X
+ Added all Audio channels as separate Audio formats: 2.0, 2.1, 3.1, 5.1, 7.1, 9.1
+ Added Flag: SE = Special edition
+ Added Flag: Criterion
+ Added Flag: HLG (like HDR)
+ Added Flag: Superbit
+ Added Audio: EAC3
+ Added Audio: DDP (Dolby Digital Plus)
+ Added Source: VODRip
+ Added OS: Ubuntu
+ Added pattern for sports to fix type to TV

New P2P Stuff:
+ Added Source: ABC (American Broadcasting Company)
+ Added Source: Amazon + Amazon Freevee
+ Added Source: BBC + BBC iPlayer (British Broadcasting Company)
+ Added Source: BMS (BookMyShow)
+ Added Source: CBS (CBS Corporation)
+ Added Source: CC (Comedy Central)
+ Added Source: CRAV (Crave)
+ Added Source: CR (Crunchyroll)
+ Added Source: DCU (DC Universe)
+ Added Source: DSNP (Disney Plus)
+ Added Source: DSNY (Disney Networks)
+ Added Source: DSCP (Discovery Plus)
+ Added Source: GPLAY (Google Play)
+ Added Source: HMAX (HBO Max)
+ Added Source: HDCAM
+ Added Source: HTSR (Hotstar)
+ Added Source: Hulu
+ Added Source: iT (iTunes)
+ Added Source: LGP (Lionsgate Play)
+ Added Source: MA (Movies Anywhere)
+ Added Source: MTV (MTV Networks)
+ Added Source: Mubi
+ Added Source: NBC (National Broadcasting Company)
+ Added Source: NF (Netflix)
+ Added Source: PMTP (Paramount Plus)
+ Added Source: PCOK (Peacock)
+ Added Source: SHO (Showtime)
+ Added Source: Stan
+ Added Source: STR (Starz)
+ Added Source: TBS (Turner Broadcasting System)
+ Added Source: WOWTV
+ Added Source: YTRed (YouTube Red)
+ Added Flag: HC (Hardcoded Subtitles)

Improvements:
~ Improved eBook: renamed 'episode' to 'issue' on toString method
~ Improved HDR pattern
~ Improved AAC pattern
~ Improved AC3 pattern
~ Improved CAM pattern
~ Improved all Dolby Digital Audio patterns
~ Improved DV pattern
~ Improved HDTC pattern
~ Improved HDDVD pattern
~ Improved UHDBD pattern
~ Improved MD pattern (mic dubbed)
~ Improved HEVC pattern
~ Improved VC1 pattern
~ Improved WEB source pattern
~ Improved Language detection for EN: US, GBR
~ Improved Type matching for game sources

Fixes:
~ Fixed App version matching
~ Fixed App title matching
~ Fixed WEB source matching
  • Loading branch information
pr0pz committed Jul 22, 2023
1 parent 53d0c27 commit b554e35
Show file tree
Hide file tree
Showing 4 changed files with 242 additions and 67 deletions.
76 changes: 63 additions & 13 deletions ReleaseParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* @package ReleaseParser
* @author Wellington Estevo
* @version 1.0.5
* @version 1.1.0
*/

class ReleaseParser extends ReleasePatterns
Expand Down Expand Up @@ -142,6 +142,10 @@ public function __toString(): string
}
}

// Set ebook episode to Issue
if ( $this->get( 'type' ) === 'eBook' && $information === 'episode' )
$information = 'Issue';

// Value set?
if ( isset( $information_value ) )
{
Expand Down Expand Up @@ -214,6 +218,12 @@ private function parseLanguage()
// Check for language tag (exclude "grand" for formula1 rls)
\preg_match( $regex, $this->release, $matches );


if ( preg_last_error() && \str_contains( $regex, '?<!' ) )
{
echo $regex . PHP_EOL;
}

if ( !empty( $matches ) )
$language_codes[] = $language_code_key;
}
Expand Down Expand Up @@ -503,8 +513,11 @@ private function parseGroup()
*/
private function parseVersion()
{
\preg_match( '/[._-]' . self::REGEX_VERSION . '[._-]/i', $this->release, $matches );
if ( !empty( $matches ) ) $this->set( 'version', $matches[1] );
// Cleanup release name for better matching
$release_name_cleaned = $this->cleanup( $this->release, [ 'flags', 'device' ] );

\preg_match( '/[._-]' . self::REGEX_VERSION . '[._-]/i', $release_name_cleaned, $matches );
if ( !empty( $matches ) ) $this->set( 'version', \trim( $matches[1], '.' ) );
}


Expand Down Expand Up @@ -761,7 +774,8 @@ private function guessTypeByParsedAttributes(): string
// Games = if device was found or game related flags
else if (
!empty( $this->get( 'device' ) ) ||
$this->hasAttribute( [ 'DLC', 'DLC Unlocker' ], 'flags' ) )
$this->hasAttribute( [ 'DLC', 'DLC Unlocker' ], 'flags' ) ||
$this->hasAttribute( self::SOURCES_GAMES, 'source' ) )
{
$type = 'Game';
}
Expand All @@ -780,9 +794,11 @@ private function guessTypeByParsedAttributes(): string
{
$type = 'XXX';
}

// Check for Sports programs
//$sports = [ 'NFL', 'NHL', 'MLB', 'Formula1', 'Premier.League', 'La[._-]?Liga', 'Eredivisie', 'Bundesliga', 'Ligue[._-]?1'];
// If matches sports, probably TV
else if ( \preg_match( self::REGEX_SPORTS, $this->get( 'release' ) ) )
{
$type = 'TV';
}

return $type;
}
Expand Down Expand Up @@ -932,7 +948,7 @@ private function parseTitle()
$regex_used = 'REGEX_TITLE_APP';

// Search and replace pattern in regex pattern for better macthing
$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'device', 'flags', 'format', 'group', 'language', 'os', 'source' ] );
//$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'device', 'flags', 'format', 'group', 'language', 'os', 'source' ] );

// Match title
\preg_match( $regex_pattern, $release_name_cleaned, $matches );
Expand Down Expand Up @@ -967,7 +983,8 @@ private function parseTitle()
$regex_used .= ' + REGEX_TITLE_TV_EPISODE';

// Search and replace pattern in regex pattern for better macthing
$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'flags', 'format', 'language', 'resolution', 'source' ] );
//$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'flags', 'format', 'language', 'resolution', 'source' ] );
$release_name_cleaned = $this->cleanup( $release_name_cleaned, [ 'audio', 'flags', 'format', 'language', 'resolution', 'source' ] );

// Match episode title
\preg_match( $regex_pattern, $release_name_cleaned, $matches );
Expand Down Expand Up @@ -1167,7 +1184,7 @@ private function parseTitle()
$regex_used = 'REGEX_TITLE_MOVIE';

// Search and replace pattern in regex pattern for better macthing
$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'flags', 'format', 'language', 'resolution', 'source', 'year' ] );
$regex_pattern = $this->cleanupPattern( $this->release, $regex_pattern, [ 'flags', 'format', 'language', 'resolution', 'source', 'year', 'audio' ] );

// Match title
\preg_match( $regex_pattern, $release_name_cleaned, $matches );
Expand Down Expand Up @@ -1228,8 +1245,8 @@ private function parseAttribute( array $attribute )
// We need to catch the web source
if ( $attr_key === 'WEB' )
{
$attr_pattern = $attr_pattern . '[._\)-](%year%|%format%|%language%|%group%)';
$attr_pattern = $this->cleanupPattern( $this->release, $attr_pattern, [ 'format', 'group', 'language', 'year' ] );
$attr_pattern = $attr_pattern . '[._\)-](%year%|%format%|%language%|%group%|%audio%)';
$attr_pattern = $this->cleanupPattern( $this->release, $attr_pattern, [ 'format', 'group', 'language', 'year', 'audio' ] );
}

// Transform all attribute values to array (simpler, so we just loop everything)
Expand All @@ -1238,7 +1255,7 @@ private function parseAttribute( array $attribute )

// Loop attribute values
foreach ( $attr_pattern as $pattern )
{
{
// Check if pattern is inside release name
\preg_match( '/[._\(-]' . $pattern . '[._\)-]/i', $this->release, $matches );
//\preg_match( '/[._\(-]' . $pattern . '[._\)-]/i', $this->release, $matches, \PREG_OFFSET_CAPTURE );
Expand Down Expand Up @@ -1334,6 +1351,21 @@ private function cleanup( string $release_name, $informations ): string
// Get proper attr value
switch ( $information )
{
case 'audio':
// Check if we need to loop array
if ( \is_array( $information_value ) )
{
foreach ( $information_value as $audio )
{
$attributes[] = self::AUDIO[ $audio ];
}
}
else
{
$attributes[] = self::AUDIO[ $information_value ];
}
break;

case 'daymonth':
// Clean up day and month number from rls
$attributes = [
Expand All @@ -1342,6 +1374,10 @@ private function cleanup( string $release_name, $informations ): string
$information_value->format( 'm' )
];
break;

case 'device':
$attributes[] = self::DEVICE[ $information_value ];
break;

case 'format':
// Check if we need to loop array
Expand Down Expand Up @@ -1649,6 +1685,20 @@ private function cleanupAttributes()
$this->set( 'version', \null );
}
}
else if ( $this->get( 'type' ) === 'App' )
{
// Remove audio if it's an App (falsely parsed from release name)
if ( $this->get( 'audio' ) !== \null )
{
$this->set( 'audio', \null );
}

// Remove source if it's inside title
if ( $this->get( 'source' ) !== null && \str_contains( $this->get( 'title' ), $this->get( 'source' ) ) )
{
$this->set( 'source', null );
}
}
}


Expand Down
92 changes: 77 additions & 15 deletions ReleaseParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
* @package ReleaseParser
* @author Wellington Estevo
* @version 1.0.5
* @version 1.1.0
*/

/**
Expand Down Expand Up @@ -51,7 +51,7 @@ function release_parser_test()
// Apps
[
new ReleaseParser( 'RSP.OGG.Vorbis.Player.OCX.v2.5.0-Lz0', 'Apps' ),
'Title: RSP OGG Vorbis Player OCX / Group: Lz0 / Audio: OGG / Version: 2.5.0 / Type: App'
'Title: RSP OGG Vorbis Player OCX / Group: Lz0 / Version: 2.5.0 / Type: App'
],
[
new ReleaseParser( 'ActiveState.Visual.Python.for.VS.2003.v1.8.1.2082.WinNT2K.Incl.Keygenerator-TMG', 'Games' ),
Expand All @@ -69,19 +69,27 @@ function release_parser_test()
new ReleaseParser( 'QUIZWARE.PRACTICE.TESTS.FOR.COMPUTER.ASSOCIATES.CERTIFICATIONS.V4.84-JGT', 'ebook' ),
'Title: Quizware Practice Tests For Computer Associates Certifications / Group: JGT / Version: 4.84 / Type: App'
],
[
new ReleaseParser( 'SurCode.DVD.Professional.DTS.Encoder.v1.0.21.Retail-iNTENSiON', 'Apps' ),
'Title: SurCode DVD Professional DTS Encoder / Group: iNTENSiON / Flags: Retail / Version: 1.0.21 / Type: App'
],
[
new ReleaseParser( 'Schweighofer.Win1A.Lohn.v23.10.4.0.German.WinALL.Incl.Keygen-BLiZZARD', 'Apps' ),
'Title: Schweighofer Win1A Lohn / Group: BLiZZARD / Flags: KEYGEN / Os: Windows / Version: 23.10.4.0 / Language: German / Type: App'
],

// Movies (usually a lot of flags for testing)
[
new ReleaseParser( 'Harry.Potter.und.die.Kammer.des.Schreckens.TS.Line.Dubbed.German.INTERNAL.VCD.CD2.REPACK-TGSC', 'Apps' ),
'Title: Harry Potter und die Kammer des Schreckens / Group: TGSC / Flags: Internal, Line dubbed, Repack / Source: TS / Format: VCD / Language: German / Type: Movie'
'Title: Harry Potter und die Kammer des Schreckens / Group: TGSC / Flags: Internal, Line dubbed, Repack / Source: Telesync / Format: VCD / Language: German / Type: Movie'
],
[
new ReleaseParser( 'Sweet.Home.Alabama.SCREENER.Line.Dubbed.German.VCD-TGSC', 'Screener' ),
'Title: Sweet Home Alabama / Group: TGSC / Flags: Line dubbed / Source: DVD Screener / Format: VCD / Language: German / Type: Movie'
],
[
new ReleaseParser( 'Die.Bourne.Verschwoerung.German.2004.INTERNAL.No.Bock.uff.Proper.READ.NFO.AC3.Dubbed.DL.DVDR-Cinemaniacs', 'DVDR' ),
'Title: Die Bourne Verschwoerung / Group: Cinemaniacs / Year: 2004 / Flags: AC3 Dubbed, Internal, Proper, READNFO / Source: DVD / Format: DVDR / Language: German, Multilingual / Type: Movie'
'Title: Die Bourne Verschwoerung / Group: Cinemaniacs / Year: 2004 / Flags: Dubbed, Internal, Proper, READNFO / Source: DVD / Format: DVDR / Audio: AC3 / Language: German, Multilingual / Type: Movie'
],
[
new ReleaseParser( 'Gegen.den.Strom.2018.German.AC3D.DL.1080p.BluRay.x264-SAVASTANOS', 'X264' ),
Expand All @@ -104,6 +112,18 @@ function release_parser_test()
'Title: Wonder Woman 1984 / Group: pmHD / Year: 2020 / Flags: Dolby Vision, HDR, IMAX, Remux / Source: UHDBD / Format: HEVC / Resolution: 2160p / Audio: Dolby trueHD / Language: German, Multilingual / Type: Movie'
],

// Movies #8 - Multiple Audio
[
new ReleaseParser( 'Cloudy.With.A.Chance.Of.Meatballs.2009.NORDIC.DTS-HD.DTS.AC3.NORDICSUBS.1080p.BluRay.x264-TUSAHD', 'X264' ),
'Title: Cloudy With A Chance Of Meatballs / Group: TUSAHD / Year: 2009 / Flags: Subbed / Source: Bluray / Format: x264 / Resolution: 1080p / Audio: AC3, DTS, DTS-HD / Language: Nordic / Type: Movie'
],

// Movies #9 - P2P lota of stuff
[
new ReleaseParser( 'Angel.Heart.1987.German.DTSMAD.5.1.DL.2160p.UHD.BluRay.HDR.DV.HEVC.Remux-HDSource', 'BLuray' ),
'Title: Angel Heart / Group: HDSource / Year: 1987 / Flags: Dolby Vision, HDR, Remux, UHD / Source: Bluray / Format: HEVC / Resolution: 2160p / Audio: DTS-HD MA, 5.1 / Language: German, Multilingual / Type: Movie'
],

// TV
[ // Multiple episodes: 01-02
new ReleaseParser( 'Full.Metal.Panic.Eps.01-02.INTERNAL.SVCD.DVDrip.DUBBED.DIRFIX-USAnime', 'SVCD' ),
Expand Down Expand Up @@ -138,6 +158,11 @@ function release_parser_test()
'Title: 72 Cutest Animals / Group: BiGiNT / Season: 1 / Episode: 0 / Flags: Doku / Source: WEB / Format: x264 / Resolution: 1080p / Language: German, Multilingual / Type: TV'
],

[ // P2P with multi Audio and no extra title
new ReleaseParser( 'Gilmore.Girls.S05E01.720p.WEB-DL.AAC2.0.H.264-tK', 'tv' ),
'Title: Gilmore Girls / Group: tK / Season: 5 / Episode: 1 / Source: WEB / Format: h264 / Resolution: 720p / Audio: AAC, 2.0 / Type: TV'
],

// TV SPorts
[
new ReleaseParser( 'NFL.2021.09.26.49ers.Vs.Packers.1080p.WEB.h264-SPORTSNET', 'tv' ),
Expand All @@ -151,6 +176,10 @@ function release_parser_test()
new ReleaseParser( 'WWE.Friday.Night.Smackdown.2021-09-10.German.HDTVRiP.x264-SPORTY', 'tv' ),
'Title: WWE Friday Night Smackdown / Group: SPORTY / Year: 2021 / Date: 10.09.2021 / Source: HDTV / Format: x264 / Language: German / Type: TV'
],
[ // Only year and no TV source
new ReleaseParser( 'Formula1.2023.Hungarian.Grand.Prix.Practice.Two.1080p.WEB.h264-VERUM', 'X264' ),
'Show: Formula1 / Title: Hungarian Grand Prix Practice Two / Group: VERUM / Year: 2023 / Source: WEB / Format: h264 / Resolution: 1080p / Type: TV'
],

// Anime
[
Expand Down Expand Up @@ -219,27 +248,27 @@ function release_parser_test()
],
[ // Comic with title, title_extra and issue number (No.04)
new ReleaseParser( 'Viper.Comics.-.Ichabod.Jones.Monster.Hunter.No.04.2012.Hybrid.Comic.eBook-BitBook', 'ebook' ),
'Author: Viper Comics / Title: Ichabod Jones Monster Hunter / Group: BitBook / Year: 2012 / Episode: 4 / Flags: Comic, eBook / Format: Hybrid / Type: eBook'
'Author: Viper Comics / Title: Ichabod Jones Monster Hunter / Group: BitBook / Year: 2012 / Issue: 4 / Flags: Comic, eBook / Format: Hybrid / Type: eBook'
],
[ // Basic magazine with issue number (No.314)
new ReleaseParser( 'EDGE.No.314.2018.HYBRiD.MAGAZiNE.eBook-PAPERCLiPS', 'ebook' ),
'Title: EDGE / Group: PAPERCLiPS / Year: 2018 / Episode: 314 / Flags: eBook, Magazine / Format: Hybrid / Type: eBook'
'Title: EDGE / Group: PAPERCLiPS / Year: 2018 / Issue: 314 / Flags: eBook, Magazine / Format: Hybrid / Type: eBook'
],
[ // Other version of issue number (N119)
new ReleaseParser( 'Prog.N119.2021.RETAiL.MAGAZiNE.eBook-PRiNTER', 'ebook' ),
'Title: Prog / Group: PRiNTER / Year: 2021 / Episode: 119 / Flags: eBook, Magazine, Retail / Type: eBook'
'Title: Prog / Group: PRiNTER / Year: 2021 / Issue: 119 / Flags: eBook, Magazine, Retail / Type: eBook'
],
[ // Other version of issue number (Band)
new ReleaseParser( 'Die.Enwor.Saga.Band.05.-.Das.Schwarze.Schiff.German.Ebook-Elements', 'ebook' ),
'Author: Die Enwor Saga / Title: Das Schwarze Schiff / Group: Elements / Episode: 5 / Flags: eBook / Language: German / Type: eBook'
'Author: Die Enwor Saga / Title: Das Schwarze Schiff / Group: Elements / Issue: 5 / Flags: eBook / Language: German / Type: eBook'
],
[ // Other version of issue number (Issue)
new ReleaseParser( 'The.Amazing.Spiderman.Issue.501.January.2004.Comic.eBook-Dementia', 'ebook' ),
'Title: The Amazing Spiderman / Group: Dementia / Year: 2004 / Date: 01.01.2004 / Episode: 501 / Flags: Comic, eBook / Type: eBook'
'Title: The Amazing Spiderman / Group: Dementia / Year: 2004 / Date: 01.01.2004 / Issue: 501 / Flags: Comic, eBook / Type: eBook'
],
[ // Other version of issue number
new ReleaseParser( 'Simpsons.Comics.Ausgabe.15.Januar.1998.German.Comic.eBook-HS', 'ebook' ),
'Title: Simpsons Comics / Group: HS / Year: 1998 / Date: 01.01.1998 / Episode: 15 / Flags: Comic, eBook / Language: German / Type: eBook'
'Title: Simpsons Comics / Group: HS / Year: 1998 / Date: 01.01.1998 / Issue: 15 / Flags: Comic, eBook / Language: German / Type: eBook'
],
[ // title + title_extra + special date formatting (15 Januar 2004)
new ReleaseParser( 'Concorde.-.Die.Traumer.15.Januar.2004.Presseheft.German.Ebook-Elements', 'ebook' ),
Expand All @@ -251,7 +280,7 @@ function release_parser_test()
],
[ // Issue is 0
new ReleaseParser( 'IDW.-.Machete.No.0.2010.Hybrid.Comic.eBook-BitBook', 'ebook' ),
'Author: IDW / Title: Machete / Group: BitBook / Year: 2010 / Episode: 0 / Flags: Comic, eBook / Format: Hybrid / Type: eBook'
'Author: IDW / Title: Machete / Group: BitBook / Year: 2010 / Issue: 0 / Flags: Comic, eBook / Format: Hybrid / Type: eBook'
],

// Abook
Expand Down Expand Up @@ -327,15 +356,48 @@ function release_parser_test()
function release_parser_test_single()
{
echo \PHP_EOL . 'Starting ReleaseParser Single test ...' . \PHP_EOL . \PHP_EOL;
$release = new ReleaseParser( 'Ultimate.Expedition.S01E01.Weve.All.Got.A.Screw.Loose.2160p.iNTERNAL.WEB.HDR.VP9-13', 'TV-HD' );
$release_name = 'SurCode.DVD.Professional.DTS.Encoder.v1.0.21.Retail-iNTENSiON';
$release = new ReleaseParser( $release_name );

// Check if expectation matches parsed.
echo '[Original] ' . $release_name . \PHP_EOL;
echo ' [Parsed] ' . $release . \PHP_EOL;
echo '[Expected] Show: Ultimate Expedition / Title: Weve All Got A Screw Loose / Group: 13 / Season: 1 / Episode: 1 / Flags: HDR, Internal / Format: VP9 / Resolution: 2160p / Type: TV' . \PHP_EOL . \PHP_EOL;
echo '[Expected] Title: SurCode DVD Professional DTS Encoder / Group: iNTENSiON / Flags: Retail / Version: 1.0.21 / Type: App' . \PHP_EOL . \PHP_EOL;

\print_r( $release );
}


/**
* Read release names fomr file for faster checking.
* Filename: releases.txt
*
* @test
*/

function release_parser_test_file()
{
$handle = \fopen( __DIR__ . '/releases.txt', 'r');

if ( $handle )
{
$counter = 1;
while ( ($line = \fgets( $handle ) ) !== \false)
{
echo $counter . ' > ' . $line;
echo $counter . ' > ' . new ReleaseParser( $line ) . \PHP_EOL . \PHP_EOL;
$counter++;
}

fclose( $handle );
}
else
{
echo 'Failed to open the file';
}
}

// Do tests.
release_parser_test();
release_parser_test_single();
//release_parser_test_single();
//release_parser_test_file();
Loading

0 comments on commit b554e35

Please sign in to comment.