Exemplo n.º 1
0
    def run(self, force=False):
        """
        TODO: Rename class to PostProcessor (classname contains a typo)
        Runs the postprocessor
        :param force: Forces postprocessing run (reserved for future use)
        :return: Returns when done without a return state/code
        """
        self.amActive = True

        if not ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR + " doesn't exist", logger.ERROR)
            self.amActive = False
            return

        if not ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR +
                " is relative (and probably not what you really want to process)",
                logger.ERROR)
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 2
0
    def run(self, force=False):
        """
        Runs the postprocessor

        :param force: Forces postprocessing run
        :return: Returns when done without a return state/code
        """
        self.amActive = True

        if not ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but directory doesn't exist: {0}".format(
                       sickbeard.TV_DOWNLOAD_DIR), logger.WARNING)
            self.amActive = False
            return

        if not (force or ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR)):
            logger.log(u"Automatic post-processing attempted but directory is relative "
                       u"(and probably not what you really want to process): %s" %
                       sickbeard.TV_DOWNLOAD_DIR, logger.WARNING)
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR, force=force)

        self.amActive = False
Exemplo n.º 3
0
    def run(self, force=False):
        """
        TODO: Rename class to PostProcessor (classname contains a typo)
        Runs the postprocessor
        :param force: Forces postprocessing run (reserved for future use)
        :return: Returns when done without a return state/code
        """
        self.amActive = True

        if not ek(os.path.isdir,sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " doesn't exist",
                       logger.ERROR)
            self.amActive = False
            return

        if not os.path.isabs(sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " is relative (and probably not what you really want to process)",
                logger.ERROR)
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 4
0
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR + " doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR +
                " is relative (and probably not what you really want to process)",
                logger.ERROR)
            return

        myDB = db.DBConnection()
        sqlResults = myDB.select(
            "SELECT * FROM tv_shows WHERE location = ? OR location LIKE ?", [
                os.path.abspath(sickbeard.TV_DOWNLOAD_DIR),
                ek.ek(os.path.join, os.path.abspath(sickbeard.TV_DOWNLOAD_DIR),
                      '%')
            ])

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 5
0
    def run(self, force=False):
        """
        Runs the postprocessor
        :param force: Forces postprocessing run (reserved for future use)
        :return: Returns when done without a return state/code
        """
        self.amActive = True

        if not ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logging.error("Automatic post-processing attempted but dir " +
                          sickbeard.TV_DOWNLOAD_DIR + " doesn't exist")
            self.amActive = False
            return

        if not os.path.isabs(sickbeard.TV_DOWNLOAD_DIR):
            logging.error(
                "Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR +
                " is relative (and probably not what you really want to process)"
            )
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 6
0
    def run(self, force=False):
        """
        Runs the postprocessor

        :param force: Forces postprocessing run
        :return: Returns when done without a return state/code
        """
        self.amActive = True

        if not ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but directory doesn't exist: {0}".format(
                       sickbeard.TV_DOWNLOAD_DIR), logger.WARNING)
            self.amActive = False
            return

        if not (force or ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR)):
            logger.log(u"Automatic post-processing attempted but directory is relative "
                       u"(and probably not what you really want to process): %s" %
                       sickbeard.TV_DOWNLOAD_DIR, logger.WARNING)
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR, force=force)

        self.amActive = False
Exemplo n.º 7
0
    def run(self):

        if not ek.ek(os.path.isdir, self.processorDir):
            logger.log(u"Automatic post-processing attempted but dir "+self.processorDir+" doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, self.processorDir):
            logger.log(u"Automatic post-processing attempted but dir "+self.processorDir+" is relative (and probably not what you really want to process)", logger.ERROR)
            return

        processTV.processDir(self.processorDir)
Exemplo n.º 8
0
    def run(self, force=False):
        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " doesn't exist",
                       logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " is relative (and probably not what you really want to process)",
                logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir "+sickbeard.TV_DOWNLOAD_DIR+" doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir "+sickbeard.TV_DOWNLOAD_DIR+" is relative (and probably not what you really want to process)", logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 10
0
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir " + sickbeard.TV_DOWNLOAD_DIR + " is relative (and probably not what you really want to process)", logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR, method='Automatic')
Exemplo n.º 11
0
    def _main():

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir %s doesn't exist" % sickbeard.TV_DOWNLOAD_DIR,
                       logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u'Automatic post-processing attempted but dir %s is relative '
                       '(and probably not what you really want to process)' % sickbeard.TV_DOWNLOAD_DIR, logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR, is_basedir=True)
Exemplo n.º 12
0
    def processEpisode(self, proc_dir=None, nzbName=None, jobName=None, quiet=None, process_method=None, force=None,
                       is_priority=None, delete_on='0', failed='0', type='auto', *args, **kwargs):
        nzb_name = nzbName

        def argToBool(argument):
            if isinstance(argument, basestring):
                _arg = argument.strip().lower()
            else:
                _arg = argument

            if _arg in ['1', 'on', 'true', True]:
                return True
            elif _arg in ['0', 'off', 'false', False]:
                return False

            return argument

        if not proc_dir:
            return self.redirect('/home/postprocess/')
        else:
            nzb_name = ss(nzb_name) if nzb_name else nzb_name

            result = processTV.processDir(
                ss(proc_dir), nzb_name, process_method=process_method, force=argToBool(force),
                is_priority=argToBool(is_priority), delete_on=argToBool(delete_on), failed=argToBool(failed), proc_type=type
            )

            if quiet is not None and int(quiet) == 1:
                return result

            result = result.replace('\n', '<br>\n')
            return self._genericMessage('Postprocessing results', result)
Exemplo n.º 13
0
    def run(self):

        if not ek.ek(os.path.isdir, self.processorDir):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                self.processorDir + " doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, self.processorDir):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                self.processorDir +
                " is relative (and probably not what you really want to process)",
                logger.ERROR)
            return

        processTV.processDir(self.processorDir)
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir "+sickbeard.TV_DOWNLOAD_DIR+" doesn't exist", logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir "+sickbeard.TV_DOWNLOAD_DIR+" is relative (and probably not what you really want to process)", logger.ERROR)
            return

        myDB = db.DBConnection()
        sqlResults = myDB.select("SELECT * FROM tv_shows WHERE location = ? OR location LIKE ?",
                                 [os.path.abspath(sickbeard.TV_DOWNLOAD_DIR),
                                  ek.ek(os.path.join, os.path.abspath(sickbeard.TV_DOWNLOAD_DIR), '%')])

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 15
0
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        self.amActive = True

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u"Automatic post-processing attempted but dir %s doesn't exist" % sickbeard.TV_DOWNLOAD_DIR,
                       logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(u'Automatic post-processing attempted but dir %s is relative '
                       '(and probably not what you really want to process)' % sickbeard.TV_DOWNLOAD_DIR, logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 16
0
    def subtitles_download_in_pp(self):
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = getEnabledServiceList()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER, 'password': sickbeard.ADDIC7ED_PASS},
                        'legendastv': {'username': sickbeard.LEGENDASTV_USER, 'password': sickbeard.LEGENDASTV_PASS},
                        'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER, 'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = subliminal.api.ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = set()
        for language in frozenset(wantedLanguages()):
            languages.add(fromietf(language))
        if not languages:
            return
        
        runPostProcess = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):
            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for videoFilename in sorted(files):
                    if videoFilename.rsplit(".", 1)[1] in media_extensions:
                        try:
                            video = subliminal.scan_video(os.path.join(root, videoFilename), subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)
                            
                            if not subtitles_list:
                                logger.log(u'No subtitles found for %s' % os.path.join(root, videoFilename), logger.DEBUG)
                                continue
        
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED, only_one=not sickbeard.SUBTITLES_MULTI)
                            
                            for subtitle in found_subtitles:
                                logger.log(u"Found subtitle for %s in %s provider with language %s" % (os.path.join(root, videoFilename), subtitle.provider_name, subtitle.language.opensubtitles), logger.DEBUG)
                                save_subtitles(video, found_subtitles, directory=root, single=not sickbeard.SUBTITLES_MULTI)
                                runPostProcess = True
                        except Exception as e:
                            logger.log(u"Error occurred when downloading subtitles for: %s. Error: %r" % (os.path.join(root, videoFilename), ex(e)))
            if runPostProcess:
                logger.log(u"Starting post-process with defaults settings now that we found subtitles")
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 17
0
 def processEpisode(self, dir=None, nzbName=None, jobName=None, quiet=None):
     
     if dir == None:
         redirect("/home/postprocess")
     else:
         result = processTV.processDir(dir, nzbName)
         if quiet != None and int(quiet) == 1:
             return result  
     
         result = result.replace("\n","<br />\n")
         return _genericMessage("Postprocessing results", result)
Exemplo n.º 18
0
    def run(self):
        if not sickbeard.PROCESS_AUTOMATICALLY:
            return

        self.amActive = True

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir %s doesn't exist"
                % sickbeard.TV_DOWNLOAD_DIR, logger.ERROR)
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u'Automatic post-processing attempted but dir %s is relative '
                '(and probably not what you really want to process)' %
                sickbeard.TV_DOWNLOAD_DIR, logger.ERROR)
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 19
0
    def run(self, force=False):

        self.amActive = True

        if not ek.ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR + " doesn't exist", logger.ERROR)
            self.amActive = False
            return

        if not ek.ek(os.path.isabs, sickbeard.TV_DOWNLOAD_DIR):
            logger.log(
                u"Automatic post-processing attempted but dir " +
                sickbeard.TV_DOWNLOAD_DIR +
                " is relative (and probably not what you really want to process)",
                logger.ERROR)
            self.amActive = False
            return

        processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)

        self.amActive = False
Exemplo n.º 20
0
 def _finish_download_process():
     """
     Finish downloading a pid
     (this is a closure, called in another thread)
     """
     
     last_reported_perc = 0.0
     
     while p.poll() is None:
         line = p.stdout.readline()
         if line:
             line = line.rstrip()
             match = re.match(IPLAYER_DL_PROGRESS_PATTERN, line, re.IGNORECASE)
             if match:
                 dlSize = match.group('size')
                 dlTime = match.group('time')
                 dlPerc = float(match.group('perc'))
                 if dlPerc - last_reported_perc >= 10.0:
                     # only report progress every 10% or so.
                     logger.log(u"RUNNING iPLAYER: "+line, logger.DEBUG)
                     last_reported_perc = dlPerc
             else:
                 # not a progress line, echo it to debug
                 logger.log(u"RUNNING iPLAYER: "+line, logger.DEBUG)
                     
                 
     
     logger.log(u"RUNNING iPLAYER: process has ended, returncode was " + 
                repr(p.returncode) , logger.DEBUG)
     
     # We will need to rename some of the files in the folder to ensure 
     # that sb is comfortable with them.
     videoFiles = listMediaFiles(tmp_dir)
     for videoFile in videoFiles:
         filePrefix, fileExt = os.path.splitext(videoFile)
         if fileExt and fileExt[0] == '.': 
             fileExt = fileExt[1:]
         
         # split again to get the quality
         filePrePrefix, fileQuality = os.path.splitext(filePrefix)   
         if fileQuality and fileQuality[0] == '.': 
             fileQuality = fileQuality[1:]   
         qual_str = cls.iplayer_quality_to_sb_quality_string(fileQuality)
         
         # reassemble the filename again, with new quality
         newFilePrefix = filePrePrefix + '.' + qual_str
         newFileName = newFilePrefix + '.' + fileExt
         
         if newFileName != videoFile:    # just in case!
             logger.log('Renaming {0} to {1}'.format(videoFile, newFileName), logger.DEBUG)
             os.rename(videoFile, newFileName)
             
             # Also need to rename any associated files (nfo and srt)
             for otherFile in glob.glob(newFilePrefix + '.*'):
                 if otherFile == newFileName:
                     continue
                 otherFilePrefix, otherFileExt = os.path.splitext(otherFile)
                 newOtherFile = newFilePrefix + otherFileExt
                 logger.log('Renaming {0} to {1}'.format(otherFile, newOtherFile), logger.DEBUG)
                 os.rename(otherFile, newOtherFile)
             
     
     # Ok, we're done with *our* post-processing, so let SB do its own.
     processResult = processDir(tmp_dir)
     #logger.log(u"processDir returned " + processResult , logger.DEBUG) - this is long, and quite useless!
     
     files_remaining = os.listdir(tmp_dir)
     can_delete = True
     for filename in files_remaining:
         fullFilePath = os.path.join(tmp_dir, filename)
         isVideo = isMediaFile(fullFilePath)
         if isVideo:
             can_delete = False # keep the folder - something prob went wrong
             logger.log('Found a media file after processing, something probably went wrong: ' + fullFilePath, logger.MESSAGE)
         else:
             logger.log('Extra file left over (will be deleted if no media found): ' + fullFilePath, logger.DEBUG)
     
     # tidy up - delete our temp dir
 
     if can_delete and os.path.isdir(tmp_dir):
         logger.log('Removing temp dir: ' + tmp_dir, logger.DEBUG)
         shutil.rmtree(tmp_dir)
Exemplo n.º 21
0
    def subtitles_download_in_pp():  # pylint: disable=R0914
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                         'password': sickbeard.ADDIC7ED_PASS},
                            'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                           'password': sickbeard.LEGENDASTV_PASS},
                            'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                              'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = subliminal.api.ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            for root, _, files in ek(os.walk, sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for video_filename in sorted(files):
                    if video_filename.rsplit(".", 1)[1] in media_extensions:
                        try:
                            video = subliminal.scan_video(os.path.join(root, video_filename),
                                                          subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for %s'
                                           % ek(os.path.join, root, video_filename), logger.DEBUG)
                                continue

                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u"Found subtitle for %s in %s provider with language %s"
                                           % (os.path.join(root, video_filename), subtitle.provider_name,
                                              subtitle.language.opensubtitles), logger.DEBUG)
                                subliminal.save_subtitles(video, found_subtitles, directory=root,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if root is not None:
                                    subtitle_path = ek(os.path.join, root, ek(os.path.split, subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u"Error occurred when downloading subtitles for: %s. Error: %r"
                                       % (os.path.join(root, video_filename), ex(error)))
            if run_post_process:
                logger.log(u"Starting post-process with default settings now that we found subtitles")
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 22
0
    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
        logger.log(u'Checking for needed subtitles in Post-Process folder',
                   logger.INFO)

        providers = enabled_service_list()
        pool = SubtitleProviderPool()

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        # Dict of language exceptions to use with subliminal
        language_exceptions = {'pt-br': 'pob'}

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(
                sickbeard.TV_DOWNLOAD_DIR):

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR,
                                          topdown=False):
                rar_files = [
                    rar_file for rar_file in files if isRarFile(rar_file)
                ]
                if rar_files and sickbeard.UNPACK:
                    video_files = [
                        video_file for video_file in files
                        if isMediaFile(video_file)
                    ]
                    if u'_UNPACK' not in root and (
                            not video_files
                            or root == sickbeard.TV_DOWNLOAD_DIR):
                        logger.log(
                            u'Found rar files in post-process folder: {0}'.
                            format(rar_files), logger.DEBUG)
                        result = processTV.ProcessResult()
                        processTV.unRAR(root, rar_files, False, result)
                elif rar_files and not sickbeard.UNPACK:
                    logger.log(
                        u'Unpack is disabled. Skipping: {0}'.format(rar_files),
                        logger.WARNING)

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR,
                                          topdown=False):
                for filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_filename = remove_non_release_groups(filename)
                        if new_filename != filename:
                            os.rename(filename, new_filename)
                            filename = new_filename
                    except Exception as error:
                        logger.log(
                            u"Couldn't remove non release groups from video file. Error: {0}"
                            .format(ex(error)), logger.DEBUG)

                    # Delete unwanted subtitles before downloading new ones
                    if sickbeard.SUBTITLES_MULTI and sickbeard.SUBTITLES_KEEP_ONLY_WANTED and filename.rpartition(
                            '.')[2] in subtitle_extensions:
                        subtitle_language = filename.rsplit('.', 2)[1].lower()
                        if len(
                                subtitle_language
                        ) == 2 and subtitle_language in language_converters[
                                'opensubtitles'].codes:
                            subtitle_language = Language.fromcode(
                                subtitle_language, 'alpha2').opensubtitles
                        elif subtitle_language in language_exceptions:
                            subtitle_language = language_exceptions.get(
                                subtitle_language, subtitle_language)
                        elif subtitle_language not in language_converters[
                                'opensubtitles'].codes:
                            subtitle_language = 'unknown'
                        if subtitle_language not in sickbeard.SUBTITLES_LANGUAGES:
                            try:
                                os.remove(os.path.join(root, filename))
                                logger.log(
                                    u"Deleted '{0}' because we don't want subtitle language '{1}'. We only want '{2}' language(s)"
                                    .format(
                                        filename, subtitle_language, ','.join(
                                            sickbeard.SUBTITLES_LANGUAGES)),
                                    logger.DEBUG)
                            except Exception as error:
                                logger.log(
                                    u"Couldn't delete subtitle: {0}. Error: {1}"
                                    .format(filename, ex(error)), logger.DEBUG)

                    if isMediaFile(filename) and processTV.subtitles_enabled(
                            filename):
                        try:
                            video = get_video(os.path.join(root, filename),
                                              subtitles=False,
                                              embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(
                                video, languages)

                            for provider in providers:
                                if provider in pool.discarded_providers:
                                    logger.log(
                                        u'Could not search in {0} provider. Discarding for now'
                                        .format(provider), logger.DEBUG)

                            if not subtitles_list:
                                logger.log(
                                    u'No subtitles found for {0}'.format(
                                        os.path.join(root, filename)),
                                    logger.DEBUG)
                                continue

                            logger.log(
                                u'Found subtitle(s) canditate(s) for {0}'.
                                format(filename), logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 198
                            found_subtitles = pool.download_best_subtitles(
                                subtitles_list,
                                video,
                                languages=languages,
                                hearing_impaired=hearing_impaired,
                                min_score=user_score,
                                only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                score = subliminal.score.compute_score(
                                    subtitle,
                                    video,
                                    hearing_impaired=sickbeard.
                                    SUBTITLES_HEARING_IMPAIRED)
                                logger.log(
                                    u'[{0}] Subtitle score for {1} is: {2} (min={3})'
                                    .format(subtitle.provider_name,
                                            subtitle.id, score, user_score),
                                    logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(
                                    u'Found subtitle for {0} in {1} provider with language {2}'
                                    .format(os.path.join(root, filename),
                                            subtitle.provider_name,
                                            subtitle.language.opensubtitles),
                                    logger.INFO)
                                subliminal.save_subtitles(
                                    video,
                                    found_subtitles,
                                    directory=root,
                                    single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(
                                    video.name, None
                                    if subtitles_multi else subtitle.language)
                                if root is not None:
                                    subtitle_path = os.path.join(
                                        root,
                                        os.path.split(subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(
                                    subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(
                                u'Error occurred when downloading subtitles for: {0}. Error: {1}'
                                .format(os.path.join(root, filename),
                                        ex(error)))
            if run_post_process:
                logger.log(
                    u'Starting post-process with default settings now that we found subtitles'
                )
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 23
0
        def _finish_download_process():
            """
            Finish downloading a pid
            (this is a closure, called in another thread)
            """

            last_reported_perc = 0.0

            while p.poll() is None:
                line = p.stdout.readline()
                if line:
                    line = line.rstrip()
                    match = re.match(IPLAYER_DL_PROGRESS_PATTERN, line,
                                     re.IGNORECASE)
                    if match:
                        dlSize = match.group('size')
                        dlTime = match.group('time')
                        dlPerc = float(match.group('perc'))
                        if dlPerc - last_reported_perc >= 10.0:
                            # only report progress every 10% or so.
                            logger.log(u"RUNNING iPLAYER: " + line,
                                       logger.DEBUG)
                            last_reported_perc = dlPerc
                    else:
                        # not a progress line, echo it to debug
                        logger.log(u"RUNNING iPLAYER: " + line, logger.DEBUG)

            logger.log(
                u"RUNNING iPLAYER: process has ended, returncode was " +
                repr(p.returncode), logger.DEBUG)

            # We will need to rename some of the files in the folder to ensure
            # that sb is comfortable with them.
            videoFiles = listMediaFiles(tmp_dir)
            for videoFile in videoFiles:
                filePrefix, fileExt = os.path.splitext(videoFile)
                if fileExt and fileExt[0] == '.':
                    fileExt = fileExt[1:]

                # split again to get the quality
                filePrePrefix, fileQuality = os.path.splitext(filePrefix)
                if fileQuality and fileQuality[0] == '.':
                    fileQuality = fileQuality[1:]
                qual_str = cls.iplayer_quality_to_sb_quality_string(
                    fileQuality)

                # reassemble the filename again, with new quality
                newFilePrefix = filePrePrefix + '.' + qual_str
                newFileName = newFilePrefix + '.' + fileExt

                if newFileName != videoFile:  # just in case!
                    logger.log('Renaming %s to %s' % (videoFile, newFileName),
                               logger.DEBUG)
                    os.rename(videoFile, newFileName)

                    # Also need to rename any associated files (nfo and srt)
                    for otherFile in glob.glob(newFilePrefix + '.*'):
                        if otherFile == newFileName:
                            continue
                        otherFilePrefix, otherFileExt = os.path.splitext(
                            otherFile)
                        newOtherFile = newFilePrefix + otherFileExt
                        logger.log(
                            'Renaming %s to %s' % (otherFile, newOtherFile),
                            logger.DEBUG)
                        os.rename(otherFile, newOtherFile)

            # Ok, we're done with *our* post-processing, so let SB do its own.
            processResult = processDir(tmp_dir)
            #logger.log(u"processDir returned " + processResult , logger.DEBUG) - this is long, and quite useless!

            files_remaining = os.listdir(tmp_dir)
            can_delete = True
            for filename in files_remaining:
                fullFilePath = os.path.join(tmp_dir, filename)
                isVideo = isMediaFile(fullFilePath)
                if isVideo:
                    can_delete = False  # keep the folder - something prob went wrong
                    logger.log(
                        'Found a media file after processing, something probably went wrong: '
                        + fullFilePath, logger.MESSAGE)
                else:
                    logger.log(
                        'Extra file left over (will be deleted if no media found): '
                        + fullFilePath, logger.DEBUG)

            # tidy up - delete our temp dir

            if can_delete and os.path.isdir(tmp_dir):
                logger.log('Removing temp dir: ' + tmp_dir, logger.DEBUG)
                shutil.rmtree(tmp_dir)
Exemplo n.º 24
0
    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                         'password': sickbeard.ADDIC7ED_PASS},
                            'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                           'password': sickbeard.LEGENDASTV_PASS},
                            'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                              'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = subliminal.api.ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and ek(os.path.isdir, sickbeard.TV_DOWNLOAD_DIR):
            for root, _, files in ek(os.walk, sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for video_filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_video_filename = remove_non_release_groups(video_filename)
                        if new_video_filename != video_filename:
                            os.rename(video_filename, new_video_filename)
                            video_filename = new_video_filename
                    except Exception as error:
                        logger.log(u'Could not remove non release groups from video file. Error: %r'
                                   % ex(error), logger.DEBUG)
                    if isMediaFile(video_filename):
                        try:
                            video = subliminal.scan_video(os.path.join(root, video_filename),
                                                          subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for %s'
                                           % ek(os.path.join, root, video_filename), logger.DEBUG)
                                continue

                            logger.log(u'Found subtitle(s) canditate(s) for %s' % video_filename, logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 132 if sickbeard.SUBTITLES_PERFECT_MATCH else 111
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           min_score=user_score,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                matches = subtitle.get_matches(video, hearing_impaired=False)
                                score = subliminal.subtitle.compute_score(matches, video)
                                logger.log(u"[%s] Subtitle score for %s is: %s (min=%s)"
                                           % (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u"Found subtitle for %s in %s provider with language %s"
                                           % (os.path.join(root, video_filename), subtitle.provider_name,
                                              subtitle.language.opensubtitles), logger.DEBUG)
                                subliminal.save_subtitles(video, found_subtitles, directory=root,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if root is not None:
                                    subtitle_path = ek(os.path.join, root, ek(os.path.split, subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u"Error occurred when downloading subtitles for: %s. Error: %r"
                                       % (os.path.join(root, video_filename), ex(error)))
            if run_post_process:
                logger.log(u"Starting post-process with default settings now that we found subtitles")
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 25
0
    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        provider_configs = {'addic7ed': {'username': sickbeard.ADDIC7ED_USER,
                                         'password': sickbeard.ADDIC7ED_PASS},
                            'legendastv': {'username': sickbeard.LEGENDASTV_USER,
                                           'password': sickbeard.LEGENDASTV_PASS},
                            'opensubtitles': {'username': sickbeard.OPENSUBTITLES_USER,
                                              'password': sickbeard.OPENSUBTITLES_PASS}}

        pool = ProviderPool(providers=providers, provider_configs=provider_configs)

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                rar_files = [x for x in files if isRarFile(x)]
                if rar_files and sickbeard.UNPACK:
                    video_files = [x for x in files if isMediaFile(x)]
                    if u'_UNPACK' not in root and (not video_files or root == sickbeard.TV_DOWNLOAD_DIR):
                        logger.log(u'Found rar files in post-process folder: {}'.format(rar_files), logger.DEBUG)
                        result = processTV.ProcessResult()
                        processTV.unRAR(root, rar_files, False, result)
                elif rar_files and not sickbeard.UNPACK:
                    logger.log(u'Unpack is disabled. Skipping: {}'.format(rar_files), logger.WARNING)

            for root, _, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for video_filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_video_filename = remove_non_release_groups(video_filename)
                        if new_video_filename != video_filename:
                            os.rename(video_filename, new_video_filename)
                            video_filename = new_video_filename
                    except Exception as error:
                        logger.log(u'Couldn\'t remove non release groups from video file. Error: {}'.format
                                   (ex(error)), logger.DEBUG)
                    if isMediaFile(video_filename):
                        try:
                            video = subliminal.scan_video(os.path.join(root, video_filename),
                                                          subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            for provider in providers:
                                if provider in pool.discarded_providers:
                                    logger.log(u'Could not search in {} provider. Discarding for now'.format(provider), logger.DEBUG)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for {}'.format
                                           (os.path.join(root, video_filename)), logger.DEBUG)
                                continue

                            logger.log(u'Found subtitle(s) canditate(s) for {}'.format(video_filename), logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 204
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           min_score=user_score,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                score = subliminal.score.compute_score(subtitle, video, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED)
                                logger.log(u'[{}] Subtitle score for {} is: {} (min={})'.format
                                           (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u'Found subtitle for {} in {} provider with language {}'.format
                                           (os.path.join(root, video_filename), subtitle.provider_name,
                                            subtitle.language.opensubtitles), logger.DEBUG)
                                subliminal.save_subtitles(video, found_subtitles, directory=root,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if root is not None:
                                    subtitle_path = os.path.join(root, os.path.split(subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u'Error occurred when downloading subtitles for: {}. Error: {}'.format
                                       (os.path.join(root, video_filename), ex(error)))
            if run_post_process:
                logger.log(u'Starting post-process with default settings now that we found subtitles')
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)
Exemplo n.º 26
0
    def subtitles_download_in_pp():  # pylint: disable=too-many-locals, too-many-branches, too-many-statements
        logger.log(u'Checking for needed subtitles in Post-Process folder', logger.INFO)

        providers = enabled_service_list()
        pool = SubtitleProviderPool()

        # Search for all wanted languages
        languages = {from_code(language) for language in wanted_languages()}
        if not languages:
            return

        # Dict of language exceptions to use with subliminal
        language_exceptions = {'pt-br': 'pob'}

        run_post_process = False
        # Check if PP folder is set
        if sickbeard.TV_DOWNLOAD_DIR and os.path.isdir(sickbeard.TV_DOWNLOAD_DIR):

            for dirpath, dirnames_, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                rar_files = [rar_file for rar_file in files if isRarFile(rar_file)]
                if rar_files and sickbeard.UNPACK:
                    video_files = [video_file for video_file in files if isMediaFile(video_file)]
                    if u'_UNPACK' not in dirpath and (not video_files or dirpath == sickbeard.TV_DOWNLOAD_DIR):
                        logger.log(u'Found rar files in post-process folder: {0}'.format(rar_files), logger.DEBUG)
                        result = processTV.ProcessResult()
                        processTV.unRAR(dirpath, rar_files, False, result)
                elif rar_files and not sickbeard.UNPACK:
                    logger.log(u'Unpack is disabled. Skipping: {0}'.format(rar_files), logger.WARNING)

            for dirpath, dirnames_, files in os.walk(sickbeard.TV_DOWNLOAD_DIR, topdown=False):
                for filename in sorted(files):
                    try:
                        # Remove non release groups from video file. Needed to match subtitles
                        new_filename = remove_non_release_groups(filename)
                        if new_filename != filename:
                            os.rename(filename, new_filename)
                            filename = new_filename
                    except Exception as error:
                        logger.log(u"Couldn't remove non release groups from video file. Error: {0}".format
                                   (ex(error)), logger.DEBUG)

                    # Delete unwanted subtitles before downloading new ones
                    if sickbeard.SUBTITLES_MULTI and sickbeard.SUBTITLES_KEEP_ONLY_WANTED and filename.rpartition('.')[2] in subtitle_extensions:
                        subtitle_language = filename.rsplit('.', 2)[1].lower()
                        if len(subtitle_language) == 2 and subtitle_language in language_converters['opensubtitles'].codes:
                            subtitle_language = Language.fromcode(subtitle_language, 'alpha2').opensubtitles
                        elif subtitle_language in language_exceptions:
                            subtitle_language = language_exceptions.get(subtitle_language, subtitle_language)
                        elif subtitle_language not in language_converters['opensubtitles'].codes:
                            subtitle_language = 'unknown'
                        if subtitle_language not in sickbeard.SUBTITLES_LANGUAGES:
                            try:
                                os.remove(os.path.join(dirpath, filename))
                                logger.log(u"Deleted '{0}' because we don't want subtitle language '{1}'. We only want '{2}' language(s)".format
                                           (filename, subtitle_language, ','.join(sickbeard.SUBTITLES_LANGUAGES)), logger.DEBUG)
                            except Exception as error:
                                logger.log(u"Couldn't delete subtitle: {0}. Error: {1}".format(filename, ex(error)), logger.DEBUG)

                    if isMediaFile(filename) and processTV.subtitles_enabled(filename):
                        try:
                            video = get_video(os.path.join(dirpath, filename), subtitles=False, embedded_subtitles=False)
                            subtitles_list = pool.list_subtitles(video, languages)

                            for provider in providers:
                                if provider in pool.discarded_providers:
                                    logger.log(u'Could not search in {0} provider. Discarding for now'.format(provider), logger.DEBUG)

                            if not subtitles_list:
                                logger.log(u'No subtitles found for {0}'.format
                                           (os.path.join(dirpath, filename)), logger.DEBUG)
                                continue

                            logger.log(u'Found subtitle(s) canditate(s) for {0}'.format(filename), logger.INFO)
                            hearing_impaired = sickbeard.SUBTITLES_HEARING_IMPAIRED
                            user_score = 213 if sickbeard.SUBTITLES_PERFECT_MATCH else 198
                            found_subtitles = pool.download_best_subtitles(subtitles_list, video, languages=languages,
                                                                           hearing_impaired=hearing_impaired,
                                                                           min_score=user_score,
                                                                           only_one=not sickbeard.SUBTITLES_MULTI)

                            for subtitle in subtitles_list:
                                score = subliminal.score.compute_score(subtitle, video, hearing_impaired=sickbeard.SUBTITLES_HEARING_IMPAIRED)
                                logger.log(u'[{0}] Subtitle score for {1} is: {2} (min={3})'.format
                                           (subtitle.provider_name, subtitle.id, score, user_score), logger.DEBUG)

                            downloaded_languages = set()
                            for subtitle in found_subtitles:
                                logger.log(u'Found subtitle for {0} in {1} provider with language {2}'.format
                                           (os.path.join(dirpath, filename), subtitle.provider_name,
                                            subtitle.language.opensubtitles), logger.INFO)
                                subliminal.save_subtitles(video, found_subtitles, directory=dirpath,
                                                          single=not sickbeard.SUBTITLES_MULTI)

                                subtitles_multi = not sickbeard.SUBTITLES_MULTI
                                subtitle_path = subliminal.subtitle.get_subtitle_path(video.name,
                                                                                      None if subtitles_multi else
                                                                                      subtitle.language)
                                if dirpath is not None:
                                    subtitle_path = os.path.join(dirpath, os.path.split(subtitle_path)[1])
                                sickbeard.helpers.chmodAsParent(subtitle_path)
                                sickbeard.helpers.fixSetGroupID(subtitle_path)

                                downloaded_languages.add(subtitle.language.opensubtitles)

                            # Don't run post processor unless at least one file has all of the needed subtitles
                            if not needs_subtitles(downloaded_languages):
                                run_post_process = True
                        except Exception as error:
                            logger.log(u'Error occurred when downloading subtitles for: {0}. Error: {1}'.format
                                       (os.path.join(dirpath, filename), ex(error)))
            if run_post_process:
                logger.log(u'Starting post-process with default settings now that we found subtitles')
                processTV.processDir(sickbeard.TV_DOWNLOAD_DIR)