Skip to content

Commit

Permalink
version 1.2.2
Browse files Browse the repository at this point in the history
+ Added more sports:
	+ DTM
	+ Porsche Carrera Cup
	+ Porsche Sprint
	+ AEW
	+ WRC
+ Added TRAiNER flag
+ Added Game flags
+ Added 1920p resolution
~ Improved
	- Cover flag matching
	- Docu flag matching
	- FInal flag matching
	- type matching
~ Changed DOC flag to DOX (Games, Apps)
~ Changed DOKU to DOCU (internationalised)
~ Changed sports matching
  • Loading branch information
pr0pz committed Aug 23, 2023
1 parent 6a598a6 commit b930009
Show file tree
Hide file tree
Showing 5 changed files with 226 additions and 127 deletions.
138 changes: 68 additions & 70 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.2.1
* @version 1.2.2
*/

class ReleaseParser extends ReleasePatterns
Expand Down Expand Up @@ -71,8 +71,11 @@ public function __construct( string $release_name, string $section = '' )
$this->parseResolution(); // For Video rls: Resolution (720, 1080p...)
$this->parseAudio(); // For Video rls: Audio format
$this->parseLanguage(); // Array with language code as key and name as value (in english)

$this->parseSource(); // Source (2nd time, for right web source)
$this->parseFlags(); // Flags (2nd time)
$this->parseLanguage(); // Language (2nd time)

$this->parseType( $section );
$this->parseTitle(); // Title and extra title
$this->cleanupAttributes(); // Clean up unneeded and falsely parsed attributes
Expand Down Expand Up @@ -146,12 +149,12 @@ public function __toString(): string
else
{
// Sports without extra title
if ( $this->get( 'type' ) === 'Sports' && $information === 'title' )
if ( $type === 'sports' && $information === 'title' )
$information = 'Name';
}

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

// Value set?
Expand Down Expand Up @@ -669,6 +672,21 @@ private function parseEpisode()
}


/**
* Parse Sports type.
*
* @return bool
*/
private function isSports()
{
foreach( self::SPORTS as $sport )
{
if ( \preg_match( '/^' . $sport . '[._-]/i', $this->release ) )
return \true;
}
return \false;
}

/**
* Parse the release type by section.
*
Expand Down Expand Up @@ -697,42 +715,42 @@ private function guessTypeByParsedAttributes(): string
{
$type = '';

// Ebook = ebook related flag
if ( $this->hasAttribute( self::FLAGS_EBOOK, 'flags' ) )
{
$type = 'eBook';
}
// Abook = Abook related flag
else if( $this->hasAttribute( 'ABOOK', 'flags' ) )
{
$type = 'ABook';
}
// Anime related flags
else if ( $this->hasAttribute( self::FLAGS_ANIME, 'flags' ) )
{
$type = 'Anime';
}
// Match sports events
else if ( $this->isSports() )
{
$type = 'Sports';
}
// Could be an xxx movie
else if ( $this->hasAttribute( self::FLAGS_XXX, 'flags' ) )
{
$type = 'XXX';
}
// Do We have an episode?
if (
else if (
!empty( $this->get( 'episode' ) ) ||
!empty( $this->get( 'season' ) ) ||
$this->hasAttribute( self::SOURCES_TV, 'source' ) )
{
// Default to TV
$type = 'TV';

// Match sports events
if ( \preg_match( self::REGEX_SPORTS, $this->release ) )
{
$type = 'Sports';
}
// Anime (can have episodes) = if we additionaly have an anime flag in rls name
else if ( $this->hasAttribute( self::FLAGS_ANIME, 'flags' ) )
{
$type = 'Anime';
}
// Ebook (can have episodes) = if we additionaly have an ebook flag in rls name
else if( $this->hasAttribute( self::FLAGS_EBOOK, 'flags' ) )
{
$type = 'eBook';
}
// Abook (can have episodes) = if we additionaly have an abook flag in rls name
else if( $this->hasAttribute( 'ABOOK', 'flags' ) )
{
$type = 'ABook';
}
// Imageset (set number)
else if ( $this->hasAttribute( self::FLAGS_XXX, 'flags' ) )
{
$type = 'XXX';
}
// Description with date inside brackets is nearly always music or musicvideo
else if ( \preg_match( self::REGEX_DATE_MUSIC, $this->get( 'release' ) ) )
if ( \preg_match( self::REGEX_DATE_MUSIC, $this->get( 'release' ) ) )
{
$type = 'MusicVideo';
}
Expand All @@ -749,22 +767,13 @@ private function guessTypeByParsedAttributes(): string
$type = 'Music';
}
}
// Match sports events
else if ( \preg_match( self::REGEX_SPORTS, $this->release ) )
{
$type = 'Sports';
}
// Has date and a resolution? probably TV
else if (
!empty( $this->get( 'date' ) ) &&
!empty( $this->get( 'resolution' ) ) )
{
// Default to TV
$type = 'TV';

// Could be an xxx movie
if ( $this->hasAttribute( self::FLAGS_XXX, 'flags' ) )
$type = 'XXX';
}
// Check for MVid formats
else if ( $this->hasAttribute( self::FORMATS_MVID, 'format' ) )
Expand All @@ -783,16 +792,6 @@ private function guessTypeByParsedAttributes(): string
{
$type = 'Music';
}
// Ebook = ebook related flag
else if ( $this->hasAttribute( self::FLAGS_EBOOK, 'flags' ) )
{
$type = 'eBook';
}
// Abook = Abook related flag
else if ( $this->hasAttribute( 'ABOOK', 'flags' ) )
{
$type = 'ABook';
}
// Font = Font related flag
else if ( $this->hasAttribute( [ 'FONT', 'FONTSET' ], 'flags' ) )
{
Expand All @@ -801,7 +800,7 @@ 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( self::FLAGS_GAMES, 'flags' ) ||
$this->hasAttribute( self::SOURCES_GAMES, 'source' ) )
{
$type = 'Game';
Expand All @@ -817,16 +816,6 @@ private function guessTypeByParsedAttributes(): string
{
$type = 'App';
}
// Porn = if JAV flag
else if ( $this->hasAttribute( self::FLAGS_XXX, 'flags' ) )
{
$type = 'XXX';
}
// If matches sports, probably TV
else if ( \preg_match( self::REGEX_SPORTS, $this->get( 'release' ) ) )
{
$type = 'TV';
}

return $type;
}
Expand Down Expand Up @@ -1013,6 +1002,7 @@ private function parseTitle()
// TV series
case 'tv':
case 'sports':
case 'docu':

// Setup regex pattern
$regex_pattern = self::REGEX_TITLE_TV;
Expand Down Expand Up @@ -1322,13 +1312,18 @@ private function parseAttribute( array $attribute, string $type = '' )
// Some special flags
if ( $type === 'flags' )
{
// Final flag is only right if language comes right after
if ( $attr_key === 'Final' )
$pattern = $this->cleanupPattern( $this->release, $pattern, 'language' );

// New Flag is only right if followed by some movie informations
if ( $attr_key === 'New' || $attr_key === 'V2' || $attr_key === 'V3' )
$pattern = $this->cleanupPattern( $this->release, $pattern, [ 'format', 'source', 'language', 'resolution' ] );
// Special flags that should only match if followed by specific information
if (
$attr_key === 'Final' ||
$attr_key === 'New' ||
$attr_key === 'V2' ||
$attr_key === 'V3' ||
$attr_key === 'Cover' ||
$attr_key === 'Docu'
)
{
$pattern = $this->cleanupPattern( $this->release, $pattern, [ 'flags', 'format', 'source', 'language', 'resolution' ] );
}
}

// All separators
Expand Down Expand Up @@ -1768,15 +1763,17 @@ private function cleanupPattern( string $release_name, string $regex_pattern, $i
*/
private function cleanupAttributes()
{
if ( $this->get( 'type' ) === 'Movie' )
$type = \strtolower( $this->get( 'type' ) );

if ( $type === 'movie' )
{
// Remove version if it's a movie (falsely parsed from release name)
if ( $this->get( 'version' ) !== \null )
{
$this->set( 'version', \null );
}
}
else if ( $this->get( 'type' ) === 'App' )
else if ( $type === 'app' )
{
// Remove audio if it's an App (falsely parsed from release name)
if ( $this->get( 'audio' ) !== \null )
Expand All @@ -1790,7 +1787,7 @@ private function cleanupAttributes()
$this->set( 'source', null );
}
}
else if ( $this->get( 'type' ) === 'eBook' )
else if ( $type === 'ebook' )
{
if ( $this->get( 'format' ) === 'Hybrid' )
{
Expand Down Expand Up @@ -1909,6 +1906,7 @@ private function set( string $name, $value )
// Check if array key alerady exists, so we don't create a new one
if ( \array_key_exists( $name, $this->data ) )
{
$value = \is_array( $value ) && empty( $value ) ? \null : $value;
$this->data[ $name ] = $value;
return \true;
}
Expand Down
17 changes: 11 additions & 6 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.2.1
* @version 1.2.2
*/

/**
Expand Down Expand Up @@ -177,7 +177,7 @@ function release_parser_test()
// TV #5 - No episode title given
[
new ReleaseParser( 'Dark.Net.S01E06.DOC.SUBFRENCH.720p.WEBRip.x264-TiMELiNE', 'tv' ),
'Title: Dark Net / Group: TiMELiNE / Season: 1 / Episode: 6 / Flags: DOC, Subbed / Source: WEB / Format: x264 / Resolution: 720p / Type: TV'
'Title: Dark Net / Group: TiMELiNE / Season: 1 / Episode: 6 / Flags: Docu, Subbed / Source: WEB / Format: x264 / Resolution: 720p / Type: TV'
],
// TV #6 - Old season + episode pattern: 2x14
[
Expand All @@ -192,7 +192,7 @@ function release_parser_test()
// TV #8 - Episode is 0 (needs dirfix but works)
[
new ReleaseParser( '72.Cutest.Animals.S01E0.German.DL.Doku.1080p.WEB.x264-BiGiNT', 'tv' ),
'Title: 72 Cutest Animals / Group: BiGiNT / Season: 1 / Episode: 0 / Flags: Doku / Source: WEB / Format: x264 / Resolution: 1080p / Language: German, Multilingual / Type: TV'
'Title: 72 Cutest Animals / Group: BiGiNT / Season: 1 / Episode: 0 / Flags: Docu / Source: WEB / Format: x264 / Resolution: 1080p / Language: German, Multilingual / Type: TV'
],
// TV #9 - P2P with multi Audio and no extra title
[
Expand Down Expand Up @@ -224,6 +224,11 @@ function release_parser_test()
new ReleaseParser( '4x4.Ule.ja.Umber.Autoga.Colombias.S01E09.EE.1080p.WEB.h264-EMX', 'PRE' ),
'Title: 4x4 Ule ja Umber Autoga Colombias / Group: EMX / Season: 1 / Episode: 9 / Source: WEB / Format: h264 / Resolution: 1080p / Language: Estonian / Type: TV'
],
// TV #15 - Docu with episode
[
new ReleaseParser( 'Speer.Et.Hitler.L.Architecte.Du.Diable.E03.FINAL.DOC.FRENCH.PDTV.XViD-BAWLS', 'tv-xvid' ),
'Title: Speer Et Hitler L Architecte Du Diable / Group: BAWLS / Episode: 3 / Flags: Docu, Final / Source: PDTV / Format: XViD / Language: French / Type: TV'
],

// TV Sports
// TV Sports #1
Expand Down Expand Up @@ -476,14 +481,14 @@ function release_parser_test()
function release_parser_test_single()
{
echo \PHP_EOL . 'Starting ReleaseParser Single test ...' . \PHP_EOL . \PHP_EOL;
$release_name = 'Broforce.Forever.MacOS-I_KnoW';
$release_section = 'pre';
$release_name = 'Doom.Plus.7.TRAiNER.NFOFIX-DARKSiDERS';
$release_section = 'DOX';
$release = new ReleaseParser( $release_name, $release_section );

// Check if expectation matches parsed.
echo '[Original] ' . $release_name . \PHP_EOL;
echo ' [Parsed] ' . $release . \PHP_EOL;
echo '[Expected] Title: Broforce Forever / Group: I_KnoW / Os: macOS / Type: App' . \PHP_EOL . \PHP_EOL;
echo '[Expected] Title: Doom Plus 7 / Group: DARKSiDERS / Flags: NFOFiX, TRAiNER / Type: Game' . \PHP_EOL . \PHP_EOL;

\print_r( $release );
}
Expand Down
Loading

0 comments on commit b930009

Please sign in to comment.