Page 1 of 1

Music Sorter

Posted: February 12th, 2010, 2:03 pm
by Briam
Hi

I made/assembled this scripts using bits and pieces found around this forum. All it does is go through a folder with downloaded music in the format completedmusic/artistname - albumname..../ and moves them to your music folder in the format Music/Artist/Artistname - Album..../ as this is how i like to store my music.

music_sorter.py

Code: Select all

#!/usr/bin/python

import os
import sys
import string
import ConfigParser
import shutil
import re
import urllib2
import socket

# store the script's working path
scriptHome = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0])))
# define the desired socket timeout in seconds (used in handling of url's)
timeout = 20
socket.setdefaulttimeout(timeout)

musicSource="/home/brian/downloads/music"
musicDir="/home/brian/Music"
downloadList = os.listdir(musicSource)
downloadList.sort()

for download in downloadList:
	newArtist = 1
	artistsList = os.listdir(musicDir)
	artistsList.sort()
	for artist in artistsList:
		if artist==download.split(" - ")[0]:
			newArtist=0
			os.mvdir(musicSource+"/"+download, musicDir+"/"+artist)
			break
	if newArtist == 1:
		os.mkdir(musicDir+"/"+download.split(" - ")[0])
		shutil.move(musicSource+"/"+download, musicDir+"/"+download.split(" - ")[0])

xbmcurl = urllib2.Request("http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(music)")
try: handle = urllib2.urlopen(xbmcurl)
except IOError, e:
	print "XBMC library update skipped"
else:      
    print "XBMC library update completed"
oh ye it also updates xbmc afterwards if it's on the same computer that is.

Problem is i that i can't get sabnzbd to run the script, but it works fine when calling it from terminal. i have chmod +x'ed it but still gives error
Exit(-1) Cannot run script /home/brian/scripts/music_sorter.py

anybody can help?

Re: Music Sorter

Posted: February 12th, 2010, 3:19 pm
by Briam
Thanks for the quick answer.

I tried what you suggested but the terminal gives me "command not found" when i try.
I also tried it on another script which is working and it also gave me "command no found".... hmm dunno what's wrong. Ubuntu karmic btw.

Re: Music Sorter

Posted: February 12th, 2010, 3:24 pm
by Briam
hmm when i go to scripts/ and write ./music_sorter.py i get "
-bash: ./music_sorter.py: /usr/bin/python^M: bad interpreter: No such file or directory
brian@XBMC:~/scripts$ python music_sorter.py
"

hmm so i guess thats the problem. but then the question is how to fix that :)

Re: Music Sorter

Posted: February 12th, 2010, 5:27 pm
by Briam
I just don't think it's wrong.

Cause this scripts works without a problem

Code: Select all

#!/usr/bin/python

import os
import sys
import string
import ConfigParser
import shutil
import re
import urllib2
import socket

# store the script's working path
scriptHome = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0])))
# define the desired socket timeout in seconds (used in handling of url's)
timeout = 20
socket.setdefaulttimeout(timeout)     
      
# send a http request to the xbmc server, this will trigger a library update on that xbmc box

xbmcurl = urllib2.Request("http://localhost:8080/xbmcCmds/xbmcHttp?command=ExecBuiltIn&parameter=XBMC.updatelibrary(video)")
try: handle = urllib2.urlopen(xbmcurl)
except IOError, e:
	print "XBMC library update skipped"
else:      
    print "XBMC library update completed"
they just seem so similar to me can't figure out whats causing the problem.

and i looked in usr/bin and there are the python bins.

Re: Music Sorter

Posted: February 12th, 2010, 5:34 pm
by Briam
got it working now by copying the code making a new file and pasting it. chmod +x and it worked right away... :/