Пример #1
0
 def add_content_to_records(self, data_path=None):
     data_path = data_path or self.CONTENT_DIRECTORY
     content_files = sporklib.list_files(data_path, True, False)
     record_keys = self.get_records().keys()
     for file in content_files:
         fn = os.path.basename(file).split(".")
         name = fn[0]
         ext = fn[1]
         if name not in record_keys:
             self.RECORDS[name] = self.create_new_record(name, ext)
Пример #2
0
dir = sporklib.normalize_path(args.dir)
name = args.name
dry_run = args.dryrun
pattern = args.pattern

if dir == "":
    print("ERROR: Directory not specified")
    exit(1)
if name == "":
    print("ERROR: Name not specified")
    exit(2)

if name == "UPDATE":
    scoreboard = {}
    files_list = sporklib.list_files(dir, True, False)
    
    for file in files_list:
        fn = file.split(" - ")[0]
        if fn in scoreboard:
            scoreboard[fn] += 1
        else:
            scoreboard[fn] = 1
        
    biggest_value = 0
    biggest_key = ""
    for k in scoreboard.keys():
        if scoreboard[k] > biggest_value:
            biggest_value = scoreboard[k]
            biggest_key = k
            
Пример #3
0
    def rename_shows(dir, show_name, dry_run=False):

        if dry_run:
            print("DRY RUN -- FILES NOT RENAMED")

        video_formats = [".mpg", ".mp4", ".avi", ".mkv", ".mpeg"]

        dir = sporklib.normalize_path(dir)
        season = "XX"
        episode = "XX"
        re_season = "[Ss]\d{1,2}"
        re_episode = "[Ee]\d{1,2}"
        files = []
        vid_file_paths = []

        file_paths = sporklib.list_files(dir, True)

        for path in file_paths:

            vid_file_paths.append(path)
            i = path.rfind("/")
            f = path[i+1:]
            files.append(f)

        file_paths = vid_file_paths

        if len(file_paths) != len(files):
            raise IndexError("List of file paths did not have corresponding indices in list of file names.")

        i = 0
        for filename in files:
            
            ext_i = filename.rfind(".")
            extension = filename[ext_i:]

            if extension in video_formats:
        
                new_name = ""

                s_matcher = re.compile(re_season)
                e_matcher = re.compile(re_episode)

                looper = [["s", s_matcher], ["e", e_matcher]]

                for loop in looper:

                    matcher = loop[1]

                    mo = matcher.search(filename)

                    if mo != None: #regex failed
                        positions = mo.span()

                        match = filename[positions[0]:positions[1]]

                        match = re.sub("[^0 -9]", "", match)
                        match = int(match)

                        if match > 9:
                            match = str(match)
                        else:
                            match = "0" + str(match)

                        if loop[0] == "s":
                            season = match
                        elif loop[0] == "e":
                            episode = match
                        else:
                            raise IndexError("ERROR! DID NOT RECOGNIZE LOOP DIRECTIVE: " + loop[0])

                new_name = show_name + " - S" + season + "E" + episode + extension

                path = file_paths[i]
                new_path = dir + "/" + new_name

                if new_path != path:
                    print(filename + " --> " + new_name)

                    if not dry_run:
                        os.rename(path, new_path)

            i += 1