|
|
@@ -1,3 +1,66 @@ |
|
|
|
#!/usr/bin/env python3 |
|
|
|
|
|
|
|
print('Hello, World!') |
|
|
|
import os |
|
|
|
import sys |
|
|
|
|
|
|
|
import subprocess |
|
|
|
import shutil |
|
|
|
|
|
|
|
video_exts = [ |
|
|
|
'.mkv', |
|
|
|
'.mp4', |
|
|
|
'.avi' |
|
|
|
] |
|
|
|
|
|
|
|
meta_exts = [ |
|
|
|
'.nfo', |
|
|
|
'.srt' # We can get these on our own. |
|
|
|
] |
|
|
|
|
|
|
|
def filebot_rename(src, dest, name, action): |
|
|
|
filter = 'n == \"' + name + '\"' |
|
|
|
subprocess.run([ |
|
|
|
'filebot', |
|
|
|
'-rename', src, |
|
|
|
'-non-strict', |
|
|
|
'--filter', filter, |
|
|
|
'--action', action, |
|
|
|
'--output', dest]) |
|
|
|
|
|
|
|
def unrar(src, dest='extract'): |
|
|
|
subprocess.run(['unrar', 'x', dest + '/']) |
|
|
|
return dest |
|
|
|
|
|
|
|
def process_rename(ofile, destdir): |
|
|
|
shutil.copy(ofile, destdir) |
|
|
|
|
|
|
|
dest = sys.argv[1] |
|
|
|
if not os.path.isdir(dest): |
|
|
|
os.makedirs(dest, mode=0o755) |
|
|
|
print('created destination directory ' + dest) |
|
|
|
|
|
|
|
medianame = sys.argv[2] |
|
|
|
to_rename = [] |
|
|
|
|
|
|
|
for f in os.listdir(os.getcwd()): |
|
|
|
if os.path.isdir(f): |
|
|
|
continue |
|
|
|
|
|
|
|
name, ext = os.path.splitext(f) |
|
|
|
if ext in video_exts: |
|
|
|
to_rename.append({ 'srcname': f, 'action': 'hardlink' }) |
|
|
|
elif ext == 'rar': |
|
|
|
contents = unrar(f) |
|
|
|
for ff in os.listdir(contents): |
|
|
|
if ext in video_exts: |
|
|
|
to_rename.append({ 'srcname': ff, 'action': 'copy' }) |
|
|
|
else: |
|
|
|
pass |
|
|
|
elif ext in meta_exts: |
|
|
|
# just an NFO file, ignore it |
|
|
|
pass |
|
|
|
else: |
|
|
|
print('warning: ignoring file because of extension: ' + f) |
|
|
|
|
|
|
|
for e in to_rename: |
|
|
|
filebot_rename(e['srcname'], dest, medianame, e['action']) |