Skip to content

Commit

Permalink
Improve TV season and episode matching
Browse files Browse the repository at this point in the history
  • Loading branch information
DariusIII committed Sep 30, 2023
1 parent ca22ac5 commit 41ac1ca
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions Blacklight/processing/tv/TV.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,67 +450,67 @@ private function parseSeasonEp(string $relname): array
$episodeArr = [];

// S01E01-E02 and S01E01-02
if (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?e(\d{1,3})(?:[e-])(\d{1,3})[^a-z0-9]/i', $relname, $hits)) {
if (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?e(\d{1,3})(?:[e-])(\d{1,3})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = [(int) $hits[3], (int) $hits[4]];
}
//S01E0102 and S01E01E02 - lame no delimit numbering, regex would collide if there was ever 1000 ep season.
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{2})[^a-z0-9]?e(\d{2})e?(\d{2})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{2})[^a-z0-9]?e(\d{2})e?(\d{2})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = (int) $hits[3];
}
// S01E01 and S01.E01
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?e(\d{1,3})[abr]?[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?e(\d{1,3})[abr]?[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = (int) $hits[3];
}
// S01
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = 'all';
}
// S01D1 and S1D1
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?d\d{1}[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9]s(\d{1,2})[^a-z0-9]?d\d{1}[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = 'all';
}
// 1x01 and 101
elseif (preg_match('/^(.*?)[^a-z0-9](\d{1,2})x(\d{1,3})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](\d{1,2})x(\d{1,3})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = (int) $hits[2];
$episodeArr['episode'] = (int) $hits[3];
}
// 2009.01.01 and 2009-01-01
elseif (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(19|20)(\d{2})[.\/-](\d{2})[.\/-](\d{2}))[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(19|20)(\d{2})[.\/-](\d{2})[.\/-](\d{2}))[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = $hits[4].$hits[5];
$episodeArr['episode'] = $hits[5].'/'.$hits[6];
$episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $hits['airdate']))); //yyyy-mm-dd
}
// 01.01.2009
elseif (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(\d{2})[^a-z0-9](\d{2})[^a-z0-9](19|20)(\d{2}))[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](?P<airdate>(\d{2})[^a-z0-9](\d{2})[^a-z0-9](19|20)(\d{2}))[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = $hits[5].$hits[6];
$episodeArr['episode'] = $hits[3].'/'.$hits[4];
$episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $hits['airdate']))); //yyyy-mm-dd
}
// 01.01.09
elseif (preg_match('/^(.*?)[^a-z0-9](\d{2})[^a-z0-9](\d{2})[^a-z0-9](\d{2})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](\d{2})[^a-z0-9](\d{2})[^a-z0-9](\d{2})[^a-z0-9]?/i', $relname, $hits)) {
// Add extra logic to capture the proper YYYY year
$episodeArr['season'] = $hits[4] = ($hits[4] <= 99 && $hits[4] > 15) ? '19'.$hits[4] : '20'.$hits[4];
$episodeArr['episode'] = $hits[2].'/'.$hits[3];
$tmpAirdate = $episodeArr['season'].'/'.$episodeArr['episode'];
$episodeArr['airdate'] = date('Y-m-d', strtotime(preg_replace('/[^0-9]/i', '/', $tmpAirdate))); //yyyy-mm-dd
}
// 2009.E01
elseif (preg_match('/^(.*?)[^a-z0-9]20(\d{2})[^a-z0-9](\d{1,3})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9]20(\d{2})[^a-z0-9](\d{1,3})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = '20'.$hits[2];
$episodeArr['episode'] = (int) $hits[3];
}
// 2009.Part1
elseif (preg_match('/^(.*?)[^a-z0-9](19|20)(\d{2})[^a-z0-9]Part(\d{1,2})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](19|20)(\d{2})[^a-z0-9]Part(\d{1,2})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = $hits[2].$hits[3];
$episodeArr['episode'] = (int) $hits[4];
}
// Part1/Pt1
elseif (preg_match('/^(.*?)[^a-z0-9](?:Part|Pt)[^a-z0-9](\d{1,2})[^a-z0-9]/i', $relname, $hits)) {
elseif (preg_match('/^(.*?)[^a-z0-9](?:Part|Pt)[^a-z0-9](\d{1,2})[^a-z0-9]?/i', $relname, $hits)) {
$episodeArr['season'] = 1;
$episodeArr['episode'] = (int) $hits[2];
}
Expand Down

0 comments on commit 41ac1ca

Please sign in to comment.