Exemple #1
0
    def ask_if_single_letter_is_epno(self, split_fn, letter):
        # nice defaults
        default_false = False
        if not (letter == 'a' or letter == 'b'):
            default_false = True

        answer = self.booloptionator(
            'In: {}\nIs {} an episode or part number?'.format(
                bold(dotjoin(*split_fn)), bold(letter)),
            yesno=True,
            default_false=default_false)
        self.treat_single_letters_as_epnos = answer

        logging.info('%s is %s an episode number', letter, '' if answer else 'not')
        return answer
Exemple #2
0
    def build_rename_map(self, content_details, possible_series_foldernames):
        #pylint: disable=too-many-branches,too-many-locals,too-many-statements
        content_abspath = content_details['content_abspath']
        orig_paths = content_details['orig_paths']

        # At this point, self.dest_dirpath contains the full folder path
        self.debugprint('Final dest_dirpath=' + self.dest_dirpath)
        ##################################
        ## Now to rename the filenames
        ##################################
        # create output paths based on the filenames

        # TODO: Create a map of src -> [poss_dest, poss_dest]
        # TODO: verify that for a set of poss_dests, there are no duplicates
        mutual = {}
        multiple = {}
        for path in orig_paths:
            src_filename = basename(path)
            filename_from_filename = self.filenamer.convert_filename(src_filename, False)
            relpath_from_filename = pjoin(basename(self.dest_dirpath), filename_from_filename)
            path_from_filename = pjoin(self.dest_dirpath, filename_from_filename)
            self.debugprint('path_from_filename = %s' % self.dest_dirpath)

            path_from_foldername = ''
            if isdir(content_abspath):
                filename_from_foldername = self.filename_from_foldername(
                    possible_series_foldernames, basename(path_from_filename))
                relpath_from_foldername = pjoin(
                    basename(self.dest_dirpath), filename_from_foldername)
                path_from_foldername = pjoin(self.dest_dirpath, filename_from_foldername)

            if not path_from_foldername or (path_from_filename == path_from_foldername):
                mutual[path] = path_from_filename
            else:
                multiple[path] = {
                    'path_from_filename': path_from_filename,
                    'path_from_foldername': path_from_foldername,
                    'relpath_from_filename': relpath_from_filename,
                    'relpath_from_foldername': relpath_from_foldername
                }

        mutual_output_paths = [v for k, v in mutual.items()]
        mutual_output_paths.sort()

        ##### USER DECIDES BETWEEN RESULTS
        print
        print 'Path: %s' % (self.dest_dirpath)
        print
        if not multiple:
            # the two methods produced the same results. Print them, ask y/n
            for p in mutual_output_paths:
                print p
            print
            question = "Use these filenames or enter new term to remove"
            options = ["filenames", CANCEL]

        # the two methods produced differing results.
        # Print only the differences,  ask 1/2/n
        else:
            print 'Mutual:'
            for p in mutual_output_paths:
                print p
            print ' === '
            print 'Different:'
            multiple_keys = multiple.keys()
            multiple_keys.sort()
            for k in multiple_keys:
                print bold('%s\t|\t%s') % (multiple[k]['relpath_from_filename'],
                                           multiple[k]['relpath_from_foldername'])

            question = ' '.join([
                'Filename-based and Foldername-based produced differences: ',
                'Select which is better, or enter new term to remove'
            ])
            options = ["filenames", "foldernames", CANCEL]

        rename_map = {}

        # Possibilities: RECALCULATE, an option, '', foo (from +foo)
        answer = self.pose_question(question, options)

        if answer == "filenames":
            rename_map = deepcopy(mutual)
            rename_map.update({p: fns['path_from_filename'] for p, fns in multiple.items()})

        elif answer == "foldernames":
            rename_map = deepcopy(mutual)
            rename_map.update({p: fns['path_from_foldername'] for p, fns in multiple.items()})
        elif answer == RECALCULATE:
            return RECALCULATE
        elif answer and len(orig_paths) == 1:
            ## TODO: Re-attach file ext (and maybe checksum) if not supplied
            print 'You ignored our suggestion; supplying: %r' % (answer,)
            result = pjoin(self.dest_folder, self.dest_dirpath, answer)
            print 'Result: %r' % (result,)
            rename_map = {orig_paths[0]: result}

        elif answer and len(orig_paths) > 1:
            # more than one file
            print "We don't currently support manual mmvs :("
            return
        else:
            print 'cancelled ...'
            return

        return rename_map