Directories in xbmx/python
#1
i have some strange problems with saving files to the disk so i have some questions:

1) can a python script save a file anywhere on the disk?
2) what should the path look like ( end slash or not etc etc, for example the script home directory and then in the mp3 map)?


im having some strange problems with it, i can save in partition roots but not in subfolders. i can sometimes save in my script homedir and subfolder etc etc
Reply
#2
Hi.

I'm not sure if I understood you right.
You dont know how to save a file via python?

Example Code:
Code:
f = open('Q:\\your\\path\\file.ext', 'w')
f.write("your text")
f.close()
Reply
#3
i do know how to save files, but i get problems with the path

i've written this, with a progress bar and stuff
Quote: url = resultaat[s]
naam = song[s]

# displays the progress of the download, needs the _pbhook
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
url = url.replace(" ","%20")
dest = downloadpath + naam + ".mp3"

print dest
# downloaden met download class
DownloaderClass(url,dest)
Reply
#4
so the problem is not with the code but how to format the download path
Reply
#5
use:
dest = os.path.join( downloadpath, naam + ".mp3")

do NOT include ending \ in the downloadpath

though i don't see where you define downloadpath or naam.
Reply
#6
naam is the song name
download path is set outside of this class as a global (sorry for that) but its Q:\scripts\OMplayer\mp3\

so i think that is the problem (end slash)
thanx Smile
Reply
#7
Q:\\scripts\\OMplayer\\mp3

you need to escape a backslash.

Also with using os.path.join(), my sentence should have read you do NOT need to include the ending backslashes.
Reply

Logout Mark Read Team Forum Stats Members Help
Directories in xbmx/python0