You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

booty.py 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python3
  2. import os
  3. import sys
  4. import subprocess
  5. import shutil
  6. video_exts = [
  7. '.mkv',
  8. '.mp4',
  9. '.avi'
  10. ]
  11. meta_exts = [
  12. '.nfo',
  13. '.srt' # We can get these on our own.
  14. ]
  15. def filebot_rename(src, dest, name, action):
  16. filter = 'n == \"' + name + '\"'
  17. subprocess.run([
  18. 'filebot',
  19. '-rename', src,
  20. '-non-strict',
  21. '--filter', filter,
  22. '--action', action,
  23. '--output', dest])
  24. def unrar(src, dest='extract'):
  25. subprocess.run(['unrar', 'x', dest + '/'])
  26. return dest
  27. def process_rename(ofile, destdir):
  28. shutil.copy(ofile, destdir)
  29. dest = sys.argv[1]
  30. if not os.path.isdir(dest):
  31. os.makedirs(dest, mode=0o755)
  32. print('created destination directory ' + dest)
  33. medianame = sys.argv[2]
  34. to_rename = []
  35. for f in os.listdir(os.getcwd()):
  36. if os.path.isdir(f):
  37. continue
  38. name, ext = os.path.splitext(f)
  39. if ext in video_exts:
  40. to_rename.append({ 'srcname': f, 'action': 'hardlink' })
  41. elif ext == 'rar':
  42. contents = unrar(f)
  43. for ff in os.listdir(contents):
  44. if ext in video_exts:
  45. to_rename.append({ 'srcname': ff, 'action': 'copy' })
  46. else:
  47. pass
  48. elif ext in meta_exts:
  49. # just an NFO file, ignore it
  50. pass
  51. else:
  52. print('warning: ignoring file because of extension: ' + f)
  53. for e in to_rename:
  54. filebot_rename(e['srcname'], dest, medianame, e['action'])