Last active
January 29, 2019 14:49
-
-
Save dukelion/a64d8f70c097d68f5aa416719eed3820 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python | |
import os,sys,re | |
from sets import Set | |
from pipes import quote | |
FILE_TYPES=[ | |
'.mkv', | |
'.avi', | |
'.mp4', | |
'.flv' | |
] | |
srcpath = "/Volumes/Thunderbolt/Media/TV" | |
dstpath = "/Volumes/Media/TV" | |
dstshows = Set(os.listdir(dstpath)) | |
srcshows = Set(os.listdir(srcpath)) | |
keyregex = re.compile(r'^(.*\WS\d+E\d+)\W') | |
shows = dstshows.intersection(srcshows) | |
for show in shows: | |
dstdir=os.path.join(dstpath,show) | |
if not os.path.isdir(dstdir): | |
continue | |
dstfiles=Set() | |
for file in os.listdir(dstdir): | |
m = keyregex.match(file) | |
if m is None: | |
name,ext = os.path.splitext(file) | |
dstfiles.add(name) | |
else: | |
key = m.group(0) | |
dstfiles.add(key) | |
newfiles = Set() | |
srcdir=os.path.join(srcpath,show) | |
if os.path.isdir(srcdir): | |
for path, dirs, files in os.walk(srcdir): | |
for file in files: | |
name, ext = os.path.splitext(file) | |
if ext not in FILE_TYPES: | |
continue | |
m = keyregex.match(file) | |
if m is None: | |
if name not in dstfiles: | |
newfiles.add(os.path.join(path,file)) | |
else: | |
key = m.group(0) | |
if key not in dstfiles: | |
newfiles.add(os.path.join(path,file)) | |
for file in newfiles: | |
print(quote(file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment