XBMC Community Forum  

Go Back   XBMC Community Forum > Off-Topic > (OLD) Off-Topic Discussion > Linux Apps and OS General - discussion not directly related to XBMC

Linux Apps and OS General - discussion not directly related to XBMC General Linux related chit-chat and discussions, (no support/help questions!)
For support/help on non-XBMC related Linux stuff visit their OS support sites

 
 
Thread Tools Search this Thread Display Modes
Old 2009-04-29, 19:38   #1
wstewart
Senior Member
 
Join Date: Jan 2009
Location: Canada
Posts: 122
wstewart is on a distinguished road
Default Script to move movies to individual directories?

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.
wstewart is offline  
Old 2009-04-29, 19:48   #2
spiff
Grumpy Bastard Developer
 
spiff's Avatar
 
Join Date: Nov 2003
Posts: 7,714
spiff is on a distinguished road
Default

Code:
for i in *; do \
  test -d $i && continue; \
  DIR=`echo $i | sed -e 's/\....//g'`; \
  mkdir $DIR && mv $i $DIR/$i \
; done
__________________
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.
spiff is offline  
Old 2009-04-29, 19:51   #3
midgetspy
Fan
 
Join Date: Jan 2008
Location: Edmonton, Canada
Posts: 444
midgetspy is on a distinguished road
Default

I made this (python) to do mine: (save to whatever.py and run python whatever.py /your/movie/dir/)

Code:
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.

Last edited by midgetspy; 2009-04-29 at 20:49.
midgetspy is offline  
Old 2009-04-29, 22:40   #4
Mike48236
Junior Member
 
Join Date: Jan 2009
Posts: 4
Mike48236 is on a distinguished road
Default

I ended up using this app and instructions:

http://www.monkeyjob.com/FoldMonk/FA...-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.

Last edited by Mike48236; 2009-04-29 at 22:43.
Mike48236 is offline  
Old 2009-04-30, 00:58   #5
wstewart
Senior Member
 
Join Date: Jan 2009
Location: Canada
Posts: 122
wstewart is on a distinguished road
Default

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.
wstewart is offline  
Old 2009-04-30, 22:53   #6
schwallman
Member
 
Join Date: Nov 2008
Posts: 46
schwallman is on a distinguished road
Default

Quote:
Originally Posted by spiff View Post
Code:
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
schwallman is offline  
 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 13:16.


Protected by Akismet, We recommend WordPress blogs
Copyright © 2008, XBMC Project