wstewart
2009-04-29, 19:38
Does anyone know of a linux script that will move a bunch of movies from one directory to individual directories named after the movie file?
I have search and found nothing; only a few references in threads discussing the merit of putting movies all in one directory versus individual directories.
for i in *; do \
test -d $i && continue; \
DIR=`echo $i | sed -e 's/\....//g'`; \
mkdir $DIR && mv $i $DIR/$i \
; done
midgetspy
2009-04-29, 19:51
I made this (python) to do mine: (save to whatever.py and run python whatever.py /your/movie/dir/)
import os
import sys
badWords = ['bluray', 'hdtv', 'hddvd', '1080p', '720p', 'dvd5', 'dvd9', 'x264']
def fixFolder (folder):
for file in os.listdir(folder):
if file.endswith('.tbn'):
print ' Renaming tbn file', file
os.rename(os.path.join(folder, file), os.path.join(folder, 'movie.tbn'))
if file.endswith('.nfo'):
print ' Renaming nfo file', file
os.rename(os.path.join(folder, file), os.path.join(folder, 'movie.nfo'))
if file.endswith('-fanart.jpg'):
print ' Renaming fanart file', file
os.rename(os.path.join(folder, file), os.path.join(folder, 'fanart.jpg'))
if file.endswith('-big.png'):
print ' Deleting secondary thumb', file
os.remove(os.path.join(folder, file))
def sanitizeFileName (filename):
print 'file is', filename
goodName = filename[0:filename.rfind('.')]
goodName = goodName.replace('.', ' ')
goodName = goodName.replace(' ', '. ')
for badWord in badWords:
rPos = goodName.lower().rfind(badWord)
if rPos != -1:
goodName = goodName[0:rPos-1]
return goodName
def doFolder (whichDir):
for movie in filter(lambda x: x.endswith('.mkv') or x.endswith('.avi') or x.endswith('.iso'), os.listdir(whichDir)):
print 'Found file:', movie
goodName = sanitizeFileName(movie)
print ' Using sanitized name', goodName
print ' Creating folder...',
os.mkdir(os.path.join(whichDir, goodName))
print ' success.'
print ' Moving files...'
for movieFile in filter(lambda x: x.startswith(movie[0:movie.rfind('.')]) and not os.path.isdir(os.path.join(whichDir, x)), os.listdir(whichDir)):
print ' Moving', movieFile, '...',
os.rename(os.path.join(whichDir, movieFile), os.path.join(whichDir, goodName, movieFile))
print ' success.'
print ' Fixing names...'
fixFolder(os.path.join(whichDir, goodName))
doFolder(sys.argv[1])
EDIT: Don't use this on folders that contain multipart movies, it will almost certainly do the wrong thing and may well erase stuff you wanted. And I take no responsibility if it deletes all your movies or something... all I can say is it worked for me, heh.
Mike48236
2009-04-29, 22:40
I ended up using this app and instructions:
http://www.monkeyjob.com/FoldMonk/FAQ/Create-Folder-Move-File.htm
It's trialware, but you only need to use it for all of 5 minutes to get the job done. Worked perfectly for me.
Edit: Sorry, breezed right pass the linux script part. But it's a good tip for Windows users.
wstewart
2009-04-30, 00:58
Thanks everyone.!!!
Now I know I have made the right decision to jump from mythtv to xbmc, everyone is so responsive and helpful. Thanks again.
Mike48236: that will work also, all my linux stuff is accessible from windows and that is how I manipulate most of it anyway.
schwallman
2009-04-30, 22:53
for i in *; do \
test -d $i && continue; \
DIR=`echo $i | sed -e 's/\....//g'`; \
mkdir $DIR && mv $i $DIR/$i \
; done
damn, ive been trying for days to make my own