View Full Version : Online mp3 player script
ok i already made a request for a script like this
but nobody responded so i tried some stuff myself
link to my topic: http://xbmc.org/forum/showthread.php?t=23023
i cant write python but i can write php. But they have a lot in comon.
this is my proof of concept that it works (in windows)
there is no error detection and it just displays the link to the file.
the comments are in dutch but the code is easy to read
import urllib,urllib2 , re
import time
from string import split, replace, find, capitalize, join
# om strings te capitalisen
def capitalize_words(s):
s = split(s)
for i in range(len(s)):
s[i] = capitalize(s[i])
return join(s)
# imput van dingen
Artist = raw_input("Artist = ")
Song = raw_input("Song = ")
# Voor de url
ArtistTemp = Artist.lower()
ArtistTemp = replace( ArtistTemp, " ", "_")
print ArtistTemp
URL = "http://radioblogclub.com/search/0/" + ArtistTemp
del ArtistTemp
WebSock = urllib.urlopen(URL) # Opens a 'Socket' to URL
HTML = WebSock.read() # Reads Contents of URL and saves to Variable
WebSock.close() # Closes connection to url
# Doorlees HTML
spam = capitalize_words(Song)
Result = re.compile("blogThis[(]['](.*)" + spam +".rbs").findall(HTML)
# Verwerking
test = Result[0] + spam + ".rbs"
# Output
print test
But I dont know anything about gui's :sniffle:
some help?
since i cant edit my post (cant find an edit button)
the .rbs files are lame encoded mp3 files so i think xbmc is able to play them
ok i created a xbmc python script :)
but now it hangs when i push the select button (it then tries to find the url to the file), the shutdown menu (right tumbstick down) is still responsive but the script isnt. And the debug log is erased after a reset.
Any help?
import xbmc, xbmcgui
import urllib,urllib2 , re
from string import split, replace, find, capitalize, join
#get actioncodes from keymap.xml
ACTION_PREVIOUS_MENU = 10
ACTION_SELECT_ITEM = 7
class MyClass(xbmcgui.Window):
def __init__(self):
self.strActionInfo = xbmcgui.ControlLabel(100, 120, 200, 200, '', 'font13', '0xFFFF00FF')
self.addControl(self.strActionInfo)
self.strActionInfo.setLabel('Push BACK to quit')
self.strActionInfo2 = xbmcgui.ControlLabel(100, 140, 200, 200, '', 'font13', '0xFFFF00FF')
self.addControl(self.strActionInfo2)
self.strActionInfo2.setLabel('And SELECT to play!')
self.strNaam = xbmcgui.ControlLabel(100, 300, 200, 200, '', 'font13', '0xFFFFFFFF')
self.addControl(self.strNaam)
self.strInfo = xbmcgui.ControlLabel(100, 280, 200, 200, '', 'font13', '0xFFFFFFFF')
self.addControl(self.strInfo)
self.strInfo.setLabel("Song playing: ")
keyboard = xbmc.Keyboard('Artiest')
keyboard.doModal()
if (keyboard.isConfirmed()):
info = keyboard.getText()
self.strNaam.setLabel(keyboard.getText())
else:
self.strNaam.setLabel('Geen Artiest')
keyboard2 = xbmc.Keyboard('Song')
keyboard2.doModal()
if (keyboard.isConfirmed()):
info2 = keyboard2.getText()
info3 = info + " - " + info2
self.strNaam.setLabel(info3)
else:
self.strNaam.setLabel('Geen Song')
def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.close()
if action == ACTION_SELECT_ITEM:
# om strings te capitalisen
def capitalize_words(s):
s = split(s)
for i in range(len(s)):
s[i] = capitalize(s[i])
return join(s)
# imput van dingen
Artist = info
Song = info2
# Voor de url
ArtistTemp = Artist.lower()
ArtistTemp = replace( ArtistTemp, " ", "_")
print ArtistTemp
URL = "http://radioblogclub.com/search/0/" + ArtistTemp
del ArtistTemp
WebSock = urllib.urlopen(URL) # Opens a 'Socket' to URL
HTML = WebSock.read() # Reads Contents of URL and saves to Variable
WebSock.close() # Closes connection to url
# Doorlees HTML
spam = capitalize_words(Song)
Result = re.compile("blogThis[(]['](.*)" + spam +".rbs").findall(HTML)
# Verwerking
fileurl = Result[0] + spam + ".rbs"
# Output in log
print fileurl
# exit
self.close()
mydisplay = MyClass()
mydisplay .doModal()
del mydisplay
Nuka1195
2006-11-09, 16:15
# imput van dingen
Artist = info
Song = info2
those are not global or global to your class.
# imput van dingen
Artist = info
Song = info2
those are not global or global to your class.
ah thanx :)
the place of def capitalize_words isn't a problem? (can i place it anywhere?)
and secondly (i've been trying a bit more) if you want to show a dialog process can you place it in the same indent (when the select button is clicked)? Or does it have to be in the same class?
code: (from alex's tutorial)
def DownloaderClass(url,dest):
dp = xbmcgui.DialogProgress()
dp.create("My Script","Downloading File",url)
urllib.urlretrieve(url,dest,lambda nb, bs, fs, url=url: _pbhook(nb,bs,fs,url,dp))
def _pbhook(numblocks, blocksize, filesize, url=None,dp=None):
try:
percent = min((numblocks*blocksize*100)/filesize, 100)
print percent
dp.update(percent)
except:
percent = 100
dp.update(percent)
dp.close()
if dp.iscanceled():
print "DOWNLOAD CANCELLED" # need to get this part working
dp.close()
and last but not least, is there a way to see at what line the script freezes?
ive solved the questions above
its working now, thanx :)
ok the script is almost ready
it has a nice interface, progress bar and error checks
im getting the hang of it :-)
but the only thing that doesnt work is the most importent part:
the player
im trying xbmc.Player().play(dest) to play the file but it doesnt open it in some way and the script returns to the main interface (as i had planned after it played the file.
whats wrong :S
the def Player():
def Player(s):
print "in de player"
url = resultaat[s]
naam = song[s]
# thanx to alex's tutorial, de downloader. Its a bit ;) modified.
def DownloaderClass(url,dest):
dp = xbmcgui.DialogProgress()
error = xbmcgui.Dialog()
dp.create("Online MP3 Player","Downloading file to play")
try:
urllib.urlretrieve(url,dest,lambda nb, bs, fs, url=url: _pbhook(nb,bs,fs,url,dp))
dp.close()
return 1
except:
spam.error.ok("Online MP3 Player","Error in urlretrieve, url wrong?")
return 0
def _pbhook(numblocks, blocksize, filesize, url=None,dp=None,ratio=1.0):
try:
percent = min((numblocks*blocksize*100)/filesize, 100)
dp.update(int(percent*ratio))
except:
percent = 100
dp.update(int(percent*ratio))
if dp.iscanceled():
raise IOError
# bewerk url en naam
url = url.replace(" ","%20")
naam = naam[:-4]
# Dest maken
dest = HOME_DIR + naam + ".mp3"
print dest
# downloaden met download class, doesnt work (yet)
DownloaderClass(url,dest)
#urllib.urlretrieve(url,dest)
# speel nummer
xbmc.Player().play(dest)
# verwijder file
#os.unlink(dest)
ok i posted it to the xbmc script page
its not yet available but it will be soon :-)
I tried v0.1. Great work. I love this script, even my girl.
Sollie.
Groetjes en succes met versie 0.2.
thanx sollie.
im already busy on 0.2, expect it in a few days
veel plezier met het script :-)
akaigotchi
2006-11-13, 01:28
Hi jepper,
first of all, BIG UP for the great work! As I tried the script thoroughly today I found a tiny bug, that causes the whole script and the box to hang:
If you open the script and then press "search" and do not enter a search string but instead hit "done" the search box closes as expected but there is no more option to induce another search as the label for searching is completely gone. You cannot shutdown the script in that state either, only a hard reset helps you out of that situation.
Another bug is, that there are some files which absolutely do not stream. Example: My girl searched for "Celine Dion" (bad excuse for me searching Celine, huh? :grin: ) and most of the songs did not work. Maybe there is a pattern to that, if you could look into it...
I am currently using XBMC 2.0 latest CVS build (not 2.0.1 !).
So keep up the good work, I am hopefully expecting 0.2 :)
akaigotchi
ok thank you for reporting the first bug, i've got it fixed i think. :)
the celine dion thing i cannot help, unless the script crashed reporting a bug in the website. I've got a workaround for that one.
I dont host the files so you are downloading from someones site and some are very slow.
But i've added an option to set the number of searchresults it returns (max 50) so there is a bigger chance it wil return working songs.
Expect it in a few days :)
mmh i've got some problems
when i try to download a file to a destination on the xbox
some destinations work fine but others dont
fine:
F:\
Q:\scripts\OMplayer\mp3\
doesnt work:
F:\Muziek\mp3\
any1 knows why? :S
This script is very interesting, thanks :)
This script is very interesting, thanks :)
it will be more interesting with the download function but nobody wants to help me :blush: :laugh:
think im going to release it with a hardcoded download directory plus a how to add this directory to your library