reorganising projects
--HG-- branch : sandbox
This commit is contained in:
62
misc/batch_rename.py
Normal file
62
misc/batch_rename.py
Normal file
@@ -0,0 +1,62 @@
|
||||
""" flatex broker server """
|
||||
|
||||
import getopt
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
import logging
|
||||
mylog = logging.getLogger('batch_rename')
|
||||
|
||||
class Usage(Exception):
|
||||
def __init__(self, message):
|
||||
Exception.__init__(message)
|
||||
|
||||
|
||||
class Error(Exception):
|
||||
def __init__(self, message):
|
||||
Exception.__init__(message)
|
||||
|
||||
# Star.Trek.The.Next.Generation.1x01-02.Encounter.At.Farpoint.DVDRip-AMC.[tvu.org.ru].avi
|
||||
# Star Trek TNG - 1x01-2 - Encounter At Farpoint - DVDRip-AMC.divx.avi
|
||||
|
||||
def main(argv = None):
|
||||
if argv == None:
|
||||
argv = sys.argv
|
||||
mylog.info("starting [%s]" % (argv[0],))
|
||||
try:
|
||||
try:
|
||||
opts, args = getopt.getopt(argv[1:], "h", ["help"])
|
||||
print "opts: ", opts, "args:", args
|
||||
except getopt.error, msg:
|
||||
raise Usage(msg)
|
||||
# more code, unchanged
|
||||
p = re.compile("Star\.Trek\.The\.Next\.Generation.(.*?)\.(.*)\.(DVDRip-.*)\.\[tvu.org.ru\]\.avi")
|
||||
tng = "e:\\share\\movies\\star trek tng"
|
||||
os.chdir(tng)
|
||||
for (dirpath, dirnames, filenames) in os.walk(tng):
|
||||
for f in filenames:
|
||||
mot = re.match(p, f)
|
||||
if mot is not None:
|
||||
# print mot.group()
|
||||
print mot.groups()
|
||||
ver = mot.group(1)
|
||||
title0 = mot.group(2)
|
||||
title1 = title0.replace('.', ' ')
|
||||
nf = "Star Trek TNG - %s - %s - %s.divx.avi" % (ver, title1, mot.group(3))
|
||||
# os.rename(f, nf)
|
||||
print 'ren "%s" "%s"' % (f, nf)
|
||||
|
||||
except Error, err:
|
||||
mylog.error(err.message)
|
||||
return 1
|
||||
except Usage, err:
|
||||
mylog.error(err.message)
|
||||
mylog.error("for help use --help")
|
||||
return 2
|
||||
|
||||
if __name__ == '__main__':
|
||||
logging.basicConfig(level=logging.DEBUG,
|
||||
format='%(asctime)s.%(msecs)03d %(levelname)-8s %(message)s',
|
||||
datefmt='%H:%M:%S')
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user