|
@@ -1,13 +1,27 @@
|
|
|
#!/usr/bin/env python
|
|
#!/usr/bin/env python
|
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
-import os, sys, re
|
|
|
|
|
|
|
+import os, sys, re, glob
|
|
|
|
|
|
|
|
-files = [f for f in os.listdir('.') if os.path.isfile(f) and f.startswith(sys.argv[1])]
|
|
|
|
|
-for f in files:
|
|
|
|
|
- print f
|
|
|
|
|
- match = re.match(r'([a-zA-Z.]*).([S|s][0-9]*[E|e][0-9]*).([a-zA-Z0-9äöüÄÖÜß\-\.\,\w]*)', f)
|
|
|
|
|
- newName = match.group(1) + "-" + match.group(2) + "-" + match.group(3)
|
|
|
|
|
- print newName
|
|
|
|
|
- os.rename(f, newName)
|
|
|
|
|
- print "\n"
|
|
|
|
|
|
|
+if len(sys.argv) == 1 or len(sys.argv) > 3:
|
|
|
|
|
+ print "Usage: seriesFormatter Series.Name or seriesFormatter Series.Name mkv"
|
|
|
|
|
+ sys.exit(0)
|
|
|
|
|
+elif len(sys.argv) == 2:
|
|
|
|
|
+ files = [f for f in os.listdir('.') if os.path.isfile(f) and f.startswith(sys.argv[1])]
|
|
|
|
|
+ for f in files:
|
|
|
|
|
+ print f
|
|
|
|
|
+ match = re.match(r'([a-zA-Z.]*).([S|s][0-9]*[E|e][0-9]*).([a-zA-Z0-9äöüÄÖÜß\-\.\,\w]*)', f)
|
|
|
|
|
+ newName = match.group(1) + "-" + match.group(2) + "-" + match.group(3)
|
|
|
|
|
+ print newName
|
|
|
|
|
+ os.rename(f, newName)
|
|
|
|
|
+ print "\n"
|
|
|
|
|
+elif len(sys.argv) == 3:
|
|
|
|
|
+ files = [f for f in os.listdir('.') if os.path.isdir(f) and f.startswith(sys.argv[1])] # directory formatting
|
|
|
|
|
+ for f in files:
|
|
|
|
|
+ print f
|
|
|
|
|
+ os.chdir(f)
|
|
|
|
|
+ if len(glob.glob("*." + sys.argv[2])) > 1:
|
|
|
|
|
+ print "nigga, moar than 1 file with ." + sys.argv[2]
|
|
|
|
|
+ print glob.glob("*." + sys.argv[2])[0]
|
|
|
|
|
+ os.rename(glob.glob("*." + sys.argv[2])[0], "../" + os.getcwd().split('/')[len(os.getcwd().split('/')) - 1] + "." + sys.argv[2])
|
|
|
|
|
+ os.chdir('..')
|