Exemple #1
0
    def test_is_sync_file(self):
        app.SYNC_FILES = '!sync,lftp-pget-status,part'

        test_cases = {
            None: False,
            42: False,
            '': False,
            'filename': False,
            '.syncthingfilename': True,
            '.syncthing.filename': True,
            '.syncthing-filename': True,
            '.!sync': True,
            'file.!sync': True,
            'file.!sync.ext': False,
            '.lftp-pget-status': True,
            'file.lftp-pget-status': True,
            'file.lftp-pget-status.ext': False,
            '.part': True,
            'file.part': True,
            'file.part.ext': False,
        }

        unicode_test_cases = {
            u'': False,
            u'filename': False,
            u'.syncthingfilename': True,
            u'.syncthing.filename': True,
            u'.syncthing-filename': True,
            u'.!sync': True,
            u'file.!sync': True,
            u'file.!sync.ext': False,
            u'.lftp-pget-status': True,
            u'file.lftp-pget-status': True,
            u'file.lftp-pget-status.ext': False,
            u'.part': True,
            u'file.part': True,
            u'file.part.ext': False,
        }

        for tests in test_cases, unicode_test_cases:
            for (filename, result) in iteritems(tests):
                self.assertEqual(is_sync_file(filename), result)
Exemple #2
0
    def process(self,
                resource_name=None,
                force=False,
                is_priority=None,
                delete_on=False,
                failed=False,
                proc_type='auto',
                ignore_subs=False):
        """
        Scan through the files in the root directory and process whatever media files are found.

        :param resource_name: The resource that will be processed directly
        :param force: True to postprocess already postprocessed files
        :param is_priority: Boolean for whether or not is a priority download
        :param delete_on: Boolean for whether or not it should delete files
        :param failed: Boolean for whether or not the download failed
        :param proc_type: Type of postprocessing auto or manual
        :param ignore_subs: True to ignore setting 'postpone if no subs'
        """
        if not self.directory:
            return self.output

        if resource_name:
            self.resource_name = resource_name

        if app.POSTPONE_IF_NO_SUBS:
            self._log(
                "Feature 'postpone post-processing if no subtitle available' is enabled."
            )

        for path in self.paths:

            if not self.should_process(path, failed):
                continue

            self.result = True

            for dir_path, filelist in self._get_files(path):

                sync_files = (filename for filename in filelist
                              if is_sync_file(filename))
                # Don't process files if they are still being synced
                postpone = app.POSTPONE_IF_SYNC_FILES and any(sync_files)

                if not postpone:

                    self._log('Processing folder: {0}'.format(dir_path),
                              logger.DEBUG)

                    self.prepare_files(dir_path, filelist, force)

                    self.process_files(dir_path,
                                       force=force,
                                       is_priority=is_priority,
                                       ignore_subs=ignore_subs)

                    # Always delete files if they are being moved or if it's explicitly wanted
                    if not self.process_method == 'move' or (
                            proc_type == 'manual' and not delete_on):
                        continue

                    self.delete_folder(os.path.join(dir_path, '@eaDir'))
                    if self.unwanted_files:
                        self.delete_files(dir_path, self.unwanted_files)

                    if all([
                            not app.NO_DELETE or proc_type == 'manual',
                            self.process_method == 'move',
                            os.path.normpath(dir_path) != os.path.normpath(
                                app.TV_DOWNLOAD_DIR)
                    ]):

                        if self.delete_folder(dir_path):
                            self._log('Deleted folder: {0}'.format(dir_path),
                                      logger.DEBUG)

                else:
                    self._log(
                        'Found temporary sync files in folder: {0}'.format(
                            dir_path))
                    self._log(
                        'Skipping post processing for folder: {0}'.format(
                            dir_path))
                    self.missedfiles.append(
                        '{0}: Sync files found'.format(dir_path))

        if self.succeeded:
            self._log('Successfully processed.')

            # Clean Kodi library
            if app.KODI_LIBRARY_CLEAN_PENDING and notifiers.kodi_notifier.clean_library(
            ):
                app.KODI_LIBRARY_CLEAN_PENDING = False

            if self.missedfiles:
                self._log('I did encounter some unprocessable items: ')
                for missedfile in self.missedfiles:
                    self._log('{0}'.format(missedfile))
        else:
            self._log(
                'Problem(s) during processing, failed for the following files/folders: ',
                logger.WARNING)
            for missedfile in self.missedfiles:
                self._log('{0}'.format(missedfile), logger.WARNING)

        if app.USE_TORRENTS and app.PROCESS_METHOD in (
                'hardlink', 'symlink') and app.TORRENT_SEED_LOCATION:
            to_remove_hashes = app.RECENTLY_POSTPROCESSED.items()
            for info_hash, release_names in to_remove_hashes:
                if self.move_torrent(info_hash, release_names):
                    app.RECENTLY_POSTPROCESSED.pop(info_hash)

        return self.output
Exemple #3
0
    def process(self,
                resource_name=None,
                force=False,
                is_priority=None,
                delete_on=False,
                proc_type='auto',
                ignore_subs=False):
        """
        Scan through the files in the root directory and process whatever media files are found.

        :param resource_name: The resource that will be processed directly
        :param force: True to postprocess already postprocessed files
        :param is_priority: Boolean for whether or not is a priority download
        :param delete_on: Boolean for whether or not it should delete files
        :param proc_type: Type of postprocessing auto or manual
        :param ignore_subs: True to ignore setting 'postpone if no subs'
        """
        if resource_name:
            self.resource_name = resource_name
            self.log_and_output('Processing resource: {resource}',
                                level=logging.DEBUG,
                                **{'resource': self.resource_name})

        if not self.directory:
            return self.output

        if app.POSTPONE_IF_NO_SUBS:
            self.log_and_output(
                "Feature 'postpone post-processing if no subtitle available' is enabled."
            )

        processed_items = False
        for path in self.paths:

            if not self.should_process(path):
                continue

            self.result = True

            for dir_path, filelist in self._get_files(path):
                sync_files = (filename for filename in filelist
                              if is_sync_file(filename))

                # Don't process files if they are still being synced
                postpone = app.POSTPONE_IF_SYNC_FILES and any(sync_files)
                if not postpone:
                    self.log_and_output('Processing folder: {dir_path}',
                                        level=logging.DEBUG,
                                        **{'dir_path': dir_path})

                    self.prepare_files(dir_path, filelist, force)
                    self.process_files(dir_path,
                                       force=force,
                                       is_priority=is_priority,
                                       ignore_subs=ignore_subs)
                    self._clean_up(dir_path, proc_type, delete=delete_on)
                    # Keep track if processed anything.
                    processed_items = True
                else:
                    self.postpone_processing = True
                    self.postpone_any = True
                    self.log_and_output(
                        'Found temporary sync files in folder: {dir_path}',
                        **{'dir_path': dir_path})
                    self.log_and_output(
                        'Skipping post-processing for folder: {dir_path}',
                        **{'dir_path': dir_path})

                    self.missed_files.append(
                        '{0}: Sync files found'.format(dir_path))

        if not processed_items:
            self.result = False

        if self.succeeded:
            self.log_and_output('Post-processing completed.')

            # Clean Kodi library
            if app.KODI_LIBRARY_CLEAN_PENDING and notifiers.kodi_notifier.clean_library(
            ):
                app.KODI_LIBRARY_CLEAN_PENDING = False

            if self.missed_files:
                self.log_and_output(
                    'I did encounter some unprocessable items: ')

                for missed_file in self.missed_files:
                    self.log_and_output('Missed file: {missed_file}',
                                        level=logging.WARNING,
                                        **{'missed_file': missed_file})
        else:
            self.log_and_output(
                'Problem(s) during processing, failed for the following files/folders: ',
                level=logging.WARNING)
            for missed_file in self.missed_files:
                self.log_and_output('Missed file: {missed_file}',
                                    level=logging.WARNING,
                                    **{'missed_file': missed_file})

        if all([
                app.USE_TORRENTS, app.TORRENT_SEED_LOCATION,
                self.process_method
                in ('hardlink', 'symlink', 'reflink', 'copy')
        ]):
            for info_hash, release_names in list(
                    iteritems(app.RECENTLY_POSTPROCESSED)):
                if self.move_torrent(info_hash, release_names):
                    app.RECENTLY_POSTPROCESSED.pop(info_hash, None)

        return self.output
Exemple #4
0
    def process(self, resource_name=None, force=False, is_priority=None, delete_on=False, failed=False,
                proc_type='auto', ignore_subs=False):
        """
        Scan through the files in the root directory and process whatever media files are found.

        :param resource_name: The resource that will be processed directly
        :param force: True to postprocess already postprocessed files
        :param is_priority: Boolean for whether or not is a priority download
        :param delete_on: Boolean for whether or not it should delete files
        :param failed: Boolean for whether or not the download failed
        :param proc_type: Type of postprocessing auto or manual
        :param ignore_subs: True to ignore setting 'postpone if no subs'
        """
        if not self.directory:
            return self.output

        if resource_name:
            self.resource_name = resource_name

        if app.POSTPONE_IF_NO_SUBS:
            self.log("Feature 'postpone post-processing if no subtitle available' is enabled.")

        for path in self.paths:

            if not self.should_process(path, failed):
                continue

            self.result = True

            for dir_path, filelist in self._get_files(path):

                sync_files = (filename
                              for filename in filelist
                              if is_sync_file(filename))

                # Don't process files if they are still being synced
                postpone = app.POSTPONE_IF_SYNC_FILES and any(sync_files)
                if not postpone:

                    self.log('Processing folder: {0}'.format(dir_path), logger.DEBUG)

                    self.prepare_files(dir_path, filelist, force)
                    self.process_files(dir_path, force=force, is_priority=is_priority,
                                       ignore_subs=ignore_subs)
                    self._clean_up(dir_path, proc_type, delete=delete_on)

                else:
                    self.log('Found temporary sync files in folder: {0}'.format(dir_path))
                    self.log('Skipping post-processing for folder: {0}'.format(dir_path))
                    self.missedfiles.append('{0}: Sync files found'.format(dir_path))

        if self.succeeded:
            self.log('Successfully processed.')

            # Clean Kodi library
            if app.KODI_LIBRARY_CLEAN_PENDING and notifiers.kodi_notifier.clean_library():
                app.KODI_LIBRARY_CLEAN_PENDING = False

            if self.missedfiles:
                self.log('I did encounter some unprocessable items: ')
                for missedfile in self.missedfiles:
                    self.log('{0}'.format(missedfile))
        else:
            self.log('Problem(s) during processing, failed for the following files/folders: ', logger.WARNING)
            for missedfile in self.missedfiles:
                self.log('{0}'.format(missedfile), logger.WARNING)

        if all([app.USE_TORRENTS, app.TORRENT_SEED_LOCATION,
                self.process_method in ('hardlink', 'symlink', 'reflink')]):
            for info_hash, release_names in list(iteritems(app.RECENTLY_POSTPROCESSED)):
                if self.move_torrent(info_hash, release_names):
                    app.RECENTLY_POSTPROCESSED.pop(info_hash, None)

        return self.output
Exemple #5
0
def test_is_sync_file(p, app_config):
    app_config('SYNC_FILES', ['!sync', 'lftp-pget-status', 'part'])

    for (filename, result) in iteritems(p):
        assert sut.is_sync_file(filename) == result