Created
July 15, 2024 07:33
-
-
Save mtimkovich/651c4e0f77d6eba63410e53c8ae39745 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
1. Parse csv | |
2. Convert 1st column to season and episode string | |
3. Parse season from 2nd column | |
4. Use first column to find video file | |
5. Dry run rename | |
6. Rename, creating folders when necessary | |
''' | |
import csv | |
from glob import glob | |
import os | |
import re | |
import shutil | |
def stuff(): | |
with open('Looney Tunes Golden Collection to PLEX.csv') as f: | |
reader = csv.reader(f, delimiter=';') | |
for row in reader: | |
yield row[0], row[1] | |
def parse_column_one(origin): | |
id = origin.split(' ')[2] | |
split = list(map(int, id.split('-'))) | |
season = (split[0] - 1) * 4 + split[1] | |
ep_id = f'{season}{split[2]:02}' | |
return season, ep_id | |
def parse_year(dest): | |
return re.search('S(\d+)', dest).group(1) | |
if __name__ == '__main__': | |
for origin, dest in stuff(): | |
season, episode_id = parse_column_one(origin) | |
match = glob(f'Q:\\Looney Tunes Gold Collection\\*{season}\\{episode_id}*.mkv')[0] | |
year = parse_year(dest) | |
filename = f'{dest}.mkv' | |
filename = filename.replace('?', '') | |
output = f'Q:\\Looney Tunes\\{year}\\{filename}' | |
print(match) | |
print('->') | |
print(output) | |
print() | |
os.makedirs(os.path.dirname(output), exist_ok=True) | |
shutil.copy(match, output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment