Esempio n. 1
0
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files',
                                      'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [
            os.path.join(self.FILEDIR, f) for f in file_names
        ] + [os.path.join(self.test_tree, f) for f in file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            open(test_file, 'a').close()
Esempio n. 2
0
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files', 'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [os.path.join(self.FILEDIR, f) for f in file_names] + [os.path.join(self.test_tree, f) for f in
                                                                                file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            io.open(test_file, 'a').close()
Esempio n. 3
0
    def test_process(self):
        show = TVShow(3, 1)
        show.name = self.SHOWNAME
        show.location = self.SHOWDIR
        sickrage.app.showlist = [show]

        self.post_processor = PostProcessor(self.FILEPATH, process_method='move')
        self.post_processor._log = _log
        self.assertTrue(self.post_processor.process)
Esempio n. 4
0
    def test_process(self):
        show = TVShow(1, 3)
        show.name = self.SHOWNAME
        show.location = self.SHOWDIR
        show.save_to_db()
        sickrage.app.showlist = [show]

        sickrage.app.name_cache.put('show name', 3)
        self.post_processor = PostProcessor(self.FILEPATH, process_method='move')
        self.post_processor._log = _log
        self.assertTrue(self.post_processor.process)
Esempio n. 5
0
    def test_process(self):
        show = TVShow(3, 1)
        show.name = self.SHOWNAME
        show.location = self.SHOWDIR
        sickrage.app.showlist = [show]
        ep = TVEpisode(show, self.SEASON, self.EPISODE)
        ep.name = "some ep name"
        ep.save()

        self.post_processor = PostProcessor(self.FILEPATH, process_method='move')
        self.post_processor._log = _log
        self.assertTrue(self.post_processor.process)
Esempio n. 6
0
    def test_process(self):
        show = TVShow(1, 3)
        show.name = self.SHOWNAME
        show.location = self.SHOWDIR
        show.saveToDB()
        sickrage.app.showlist = [show]
        ep = TVEpisode(show, self.SEASON, self.EPISODE)
        ep.name = "some ep name"
        ep.saveToDB()

        sickrage.app.name_cache.put('show name', 3)
        self.pp = PostProcessor(self.FILEPATH, process_method='move')
        self.assertTrue(self.pp.process)
Esempio n. 7
0
    def test_process(self):
        show = TVShow(1, 3)
        show.name = SHOWNAME
        show.location = SHOWDIR
        show.saveToDB()
        show.loadFromDB(skipNFO=True)
        sickrage.srCore.SHOWLIST = [show]
        ep = TVEpisode(show, SEASON, EPISODE)
        ep.name = "some ep name"
        ep.saveToDB()

        sickrage.srCore.NAMECACHE.addNameToCache('show name', 3)
        self.pp = PostProcessor(FILEPATH, process_method='move')
        self.assertTrue(self.pp.process)
Esempio n. 8
0
class ListAssociatedFiles(tests.SiCKRAGETestCase):
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files',
                                      'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [
            os.path.join(self.FILEDIR, f) for f in file_names
        ] + [os.path.join(self.test_tree, f) for f in file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            open(test_file, 'a').close()

    def test_subfolders(self):
        # Test edge cases first:
        self.assertEqual([],
                         self.post_processor.list_associated_files(
                             '', subfolders=True))
        self.assertEqual([],
                         self.post_processor.list_associated_files(
                             '\\Show Name\\.nomedia', subfolders=True))

        associated_files = self.post_processor.list_associated_files(
            self.file_list[0], subfolders=True)

        associated_files = sorted(
            file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list[1:]
                          if 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

        # Test no associated files:
        associated_files = self.post_processor.list_associated_files(
            'Fools Quest.avi', subfolders=True)

    def test_no_subfolders(self):
        associated_files = self.post_processor.list_associated_files(
            self.file_list[0], subfolders=False)

        associated_files = sorted(
            file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list[1:]
                          if 'associated_files' not in file_name
                          and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

    def test_subtitles_only(self):
        associated_files = self.post_processor.list_associated_files(
            self.file_list[0], subtitles_only=True, subfolders=True)

        associated_files = sorted(
            file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list
                          if file_name.endswith('.srt')
                          and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

    def test_subtitles_only_no_subfolders(self):
        associated_files = self.post_processor.list_associated_files(
            self.file_list[0], subtitles_only=True, subfolders=False)
        associated_files = sorted(
            file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(
            file_name for file_name in self.file_list
            if file_name.endswith('.srt') and 'associated_files' not in
            file_name and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)
Esempio n. 9
0
 def setUp(self, **kwargs):
     super(PPInitTests, self).setUp()
     self.pp = PostProcessor(self.FILEPATH)
Esempio n. 10
0
class ListAssociatedFiles(tests.SiCKRAGETestCase):
    def setUp(self):
        super(ListAssociatedFiles, self).setUp()
        self.test_tree = os.path.join(self.FILEDIR, 'associated_files', 'random', 'recursive', 'subdir')

        file_names = [
            'Show Name [SickRage].avi',
            'Show Name [SickRage].srt',
            'Show Name [SickRage].nfo',
            'Show Name [SickRage].en.srt',
            'Non-Associated Show [SickRage].srt',
            'Non-Associated Show [SickRage].en.srt',
            'Show [SickRage] Non-Associated.en.srt',
            'Show [SickRage] Non-Associated.srt',
        ]
        self.file_list = [os.path.join(self.FILEDIR, f) for f in file_names] + [os.path.join(self.test_tree, f) for f in
                                                                                file_names]
        self.post_processor = PostProcessor('Show Name')
        self.post_processor._log = _log
        self.maxDiff = None
        sickrage.app.config.move_associated_files = True
        sickrage.app.config.allowed_extensions = ''

        make_dirs(self.test_tree)
        for test_file in self.file_list:
            io.open(test_file, 'a').close()

    def test_subfolders(self):
        # Test edge cases first:
        self.assertEqual([], self.post_processor.list_associated_files('', subfolders=True))
        self.assertEqual([], self.post_processor.list_associated_files('\\Show Name\\.nomedia', subfolders=True))

        associated_files = self.post_processor.list_associated_files(self.file_list[0], subfolders=True)

        associated_files = sorted(file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list[1:] if 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

        # Test no associated files:
        associated_files = self.post_processor.list_associated_files('Fools Quest.avi', subfolders=True)

    def test_no_subfolders(self):
        associated_files = self.post_processor.list_associated_files(self.file_list[0], subfolders=False)

        associated_files = sorted(file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list[1:] if
                          'associated_files' not in file_name and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

    def test_subtitles_only(self):
        associated_files = self.post_processor.list_associated_files(self.file_list[0], subtitles_only=True,
                                                                     subfolders=True)

        associated_files = sorted(file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list if
                          file_name.endswith('.srt') and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)

    def test_subtitles_only_no_subfolders(self):
        associated_files = self.post_processor.list_associated_files(self.file_list[0], subtitles_only=True,
                                                                     subfolders=False)
        associated_files = sorted(file_name.lstrip('./') for file_name in associated_files)
        out_list = sorted(file_name for file_name in self.file_list if file_name.endswith(
            '.srt') and 'associated_files' not in file_name and 'Non-Associated' not in file_name)

        self.assertEqual(out_list, associated_files)
Esempio n. 11
0
    def rename(self):
        """
        Renames an episode file and all related files to the location and filename as specified
        in the naming settings.
        """

        if not os.path.isfile(self.location):
            sickrage.app.log.warning(
                "Can't perform rename on " + self.location + " when it doesn't exist, skipping")
            return

        proper_path = self.proper_path()
        absolute_proper_path = os.path.join(self.show.location, proper_path)
        absolute_current_path_no_ext, file_ext = os.path.splitext(self.location)
        absolute_current_path_no_ext_length = len(absolute_current_path_no_ext)

        related_subs = []

        current_path = absolute_current_path_no_ext

        if absolute_current_path_no_ext.startswith(self.show.location):
            current_path = absolute_current_path_no_ext[len(self.show.location):]

        sickrage.app.log.debug("Renaming/moving episode from the base path " + self.location + " to " + absolute_proper_path)

        # if it's already named correctly then don't do anything
        if proper_path == current_path:
            sickrage.app.log.debug(str(self.indexer_id) + ": File " + self.location + " is already named correctly, skipping")
            return

        from sickrage.core.processors.post_processor import PostProcessor

        related_files = PostProcessor(self.location).list_associated_files(self.location, subfolders=True, rename=True)

        # This is wrong. Cause of pp not moving subs.
        if self.show.subtitles and sickrage.app.config.subtitles_dir:
            subs_path = os.path.join(sickrage.app.config.subtitles_dir, os.path.basename(self.location))
            related_subs = PostProcessor(self.location).list_associated_files(subs_path, subtitles_only=True, subfolders=True, rename=True)

        sickrage.app.log.debug("Files associated to " + self.location + ": " + str(related_files))

        # move the ep file
        result = self.rename_ep_file(self.location, absolute_proper_path, absolute_current_path_no_ext_length)

        # move related files
        for cur_related_file in related_files:
            # We need to fix something here because related files can be in subfolders and the original code doesn't
            # handle this (at all)
            cur_related_dir = os.path.dirname(os.path.abspath(cur_related_file))
            subfolder = cur_related_dir.replace(os.path.dirname(os.path.abspath(self.location)), '')
            # We now have a subfolder. We need to add that to the absolute_proper_path.
            # First get the absolute proper-path dir
            proper_related_dir = os.path.dirname(os.path.abspath(absolute_proper_path + file_ext))
            proper_related_path = absolute_proper_path.replace(proper_related_dir, proper_related_dir + subfolder)

            cur_result = self.rename_ep_file(cur_related_file, proper_related_path,
                                             absolute_current_path_no_ext_length + len(subfolder))
            if not cur_result:
                sickrage.app.log.warning(str(self.indexer_id) + ": Unable to rename file " + cur_related_file)

        for cur_related_sub in related_subs:
            absolute_proper_subs_path = os.path.join(sickrage.app.config.subtitles_dir, self.formatted_filename())
            cur_result = self.rename_ep_file(cur_related_sub, absolute_proper_subs_path,
                                             absolute_current_path_no_ext_length)
            if not cur_result:
                sickrage.app.log.warning(str(self.indexer_id) + ": Unable to rename file " + cur_related_sub)

        # save the ep
        if result:
            self.location = absolute_proper_path + file_ext
            for relEp in self.related_episodes:
                relEp.location = absolute_proper_path + file_ext

        # in case something changed with the metadata just do a quick check
        for curEp in [self] + self.related_episodes:
            curEp.checkForMetaFiles()