tzvikaz: I had the same problem and I fix it by running this script every few hours...
Code:
import os
import sys
import re
import shutil
import xbmc
def _mkdir(newdir):
"""works the way a good mkdir should :)
- already exists, silently complete
- regular file in the way, raise an exception
- parent directory(ies) does not exist, make them as well
"""
if os.path.isdir(newdir):
pass
elif os.path.isfile(newdir):
raise OSError("a file with the same name as the desired " \
"dir, '%s', already exists." % newdir)
else:
head, tail = os.path.split(newdir)
if head and not os.path.isdir(head):
_mkdir(head)
#print "_mkdir %s" % repr(newdir)
if tail:
os.mkdir(newdir)
src_dir = 'e:\\tvshow dump'
new_dir = 'e:\\tv'
for root, dirs, files in os.walk(src_dir):
for name in files:
print name
p=re.compile('(.+?)\.S([0-9]+)E([0-9]+).+?\.avi')
match=p.findall(name)
for filename, season, episode in match:
try:
filename = filename.replace(".", " ")
filename = filename.replace("_", " ")
newdir = os.path.join(new_dir,filename)
_mkdir(newdir)
shutil.move(os.path.join(src_dir,name), os.path.join(newdir,name.replace("_", ".")))
except:
print "Error moving " + name
p=re.compile('(.+?)\.([0-9]+)x([0-9]+).+?\.avi')
match=p.findall(name)
for filename, season, episode in match:
try:
filename = filename.replace(".", " ")
filename = filename.replace("_", " ")
newdir = os.path.join(new_dir,filename)
_mkdir(newdir)
shutil.move(os.path.join(src_dir,name), os.path.join(newdir,name.replace("_", ".")))
except:
print "Error moving " + name
p=re.compile('(.+?)\.([0-9]+)\.([0-9]+)\.([0-9]+).+?\.avi')
match=p.findall(name)
for filename, year, month, day in match:
try:
filename = filename.replace(".", " ")
filename = filename.replace("_", " ")
newdir = os.path.join(new_dir,filename)
_mkdir(newdir)
shutil.move(os.path.join(src_dir,name), os.path.join(newdir,name.replace("_", ".")))
except:
print "Error moving " + name
xbmc.executebuiltin('XBMC.updatelibrary(video)')