Http download
#1
hi,

i'm currently writing a script that downloads a specific file each time xbmc is started (listing.xml of course!!Wink.

however, the ftp code i have written only works peridically, and i would prefer to use http anyway as i have a web server constently up and running on my lan.

can someone point me in the right direction for http file downloading with python please?

ps. also, how do i return the current time into a string?
Reply
#2
i don't know anything about this, but... can't you look at how all the other retrieval scripts do it Huh
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.


Image
Reply
#3
like the web radio? of course, good idea.
Reply
#4
the code to read a page from html is:

siteurl = urllib.urlopen(url)
page = siteurl.read()

bye
Reply
#5
if you dont need to parse

urllib.urlretrieve(url, filename)
Reply
#6
check the good ol aqtbrowser.py script.

it has a neat http download function fetchhtmlpage. it returns the html contents in a string and supports a timeout, so your script won't hang in case the webserver doesn't respond.

bernd
Reply
#7
here's a better function to download a file:

Quote:import urllib2, socket
user_agent = 'mozilla/4.0 (compatible; msie 6.0; windows nt 5.1)'

# number of times the script will try to download a url before giving up
download_attempts = 5

# max. seconds to wait for a response when downloading files
http_timeout = 10.0

def download_file(url):
print('reading file at ' + url)
dialogprogress.create("downloading", url)

def try_download(url):
result = none
try:
socket.setdefaulttimeout(http_timeout)
request = urllib2.request(url)
global user_agent
request.add_header('user-agent', user_agent)
opener = urllib2.build_opener()
result = opener.open(request).read()
except urllib2.urlerror, e:
print('caught exception in download_file for url: ' + url)
print('exception reason: ' + str(e.reason))
except exception, e:
print('caught exception in download_file for url: ' + url)
return result

for i in range(1, download_attempts+1):
print('download attempt #' + str(i))
result = try_download(url)
if result != none: break

print('done reading file at ' + url)
dialogprogress.close()

if result == none:
print('error! reading file at ' + url)
xbmcgui.dialog().ok('error!','failed to download file at\n' + url)

return result

# example, how to use:
url = 'http://www.apple.com/trailers/' + link
data = download_file(url)
if data == none:
print('can\'t find file at url: ' + url)
# use data here...
Reply
#8
sorry for jumping a very old post but i search the forum and i found it

i am using the function "download_file" that post here and now i need to save the data variable and save it in the skin folder

how can i do that ?

thank you
Reply

Logout Mark Read Team Forum Stats Members Help
Http download0