From 07930310a740f7e130ec7fd9c928243d171cf5e8 Mon Sep 17 00:00:00 2001 From: Ben Roberts Date: Mon, 21 Nov 2016 23:49:51 +0000 Subject: [PATCH] Use subliminal to fetch subtitles for TV --- .../DownloadDispatcher/Source/Plugin/TV.class.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php b/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php index eca2705..4ac50f6 100644 --- a/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php +++ b/source/lib/DownloadDispatcher/Source/Plugin/TV.class.php @@ -62,6 +62,8 @@ class DownloadDispatcher_Source_Plugin_TV extends DownloadDispatcher_Source_Plug $this->copyOutput($type, $dir, $file, $full_output_dir); $this->renameOutput($full_output_dir); + + $this->fetchSubtitles($full_output_dir); // This file has been dealt with, so no need to look at it in subsequent operations $this->markProcessed($dir . '/' . $file); @@ -147,7 +149,7 @@ class DownloadDispatcher_Source_Plugin_TV extends DownloadDispatcher_Source_Plug $normalised_name = $matches[1]; } - $normalised_name = preg_replace('/[^a-zA-Z0-9]/', ' ', $normalised_name); + $normalised_name = preg_replace('/[^a-zA-Z0-9]/', '', $normalised_name); $normalised_name = preg_replace('/ +/', ' ', $normalised_name); $normalised_name = strtolower($normalised_name); $normalised_name = preg_replace('/season \d+( complete)?/', '', $normalised_name); @@ -186,7 +188,7 @@ class DownloadDispatcher_Source_Plugin_TV extends DownloadDispatcher_Source_Plug if (preg_match('/(?:(?:[\s\.](?:19|20)\d{2})?[\s\.])?(?:\d+(\d{2})(?!\d|[\s\.](?:\d+x\d+|s\d[._-]?+ep?\d+))|\[?\s*\d+x(\d+)\s*\]?|s(?:eason ?)?\d+e(?:pisode ?)?(\d+))/i', $name, $matches)) { return $set_episode($matches); - } elseif (preg_match('/^(\d+))/i', $name, $matches)) { + } elseif (preg_match('/^(\d+)/i', $name, $matches)) { return $set_episode($matches); } else { return 0; @@ -321,6 +323,15 @@ EOSH; DownloadDispatcher_LogEntry::debug($this->log, "Executing tvrenamer command in '{$dir}': {$command}"); DownloadDispatcher_ForegroundTask::execute($command, $dir); } + + protected function fetchSubtitles($dir) { + $safe_dir = escapeshellarg($dir); + $command = <<log, "Executing subliminal command in '{$dir}': {$command}"); + DownloadDispatcher_ForegroundTask::execute($command, $dir); + } protected function forgetDownload($series, $season, $episode) { $base_url = $this->config->get('sources.TV.flexget-url');