scrapping, downloading, and background process

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
tria Offline
Senior Member
Posts: 108
Joined: Jan 2012
Reputation: 0
Post: #1
Hello,

1. Is it possible to download (or scrap and download) a file in the background silently (keyword silently). If so, how to achieve such thing (not the download process, but the "background silently").

2. How can this download be on a separate thread (not necessarily a real thread, but the same idea), so that it doesn't interfere with the addon/user?

3. Can I run the thetvdb scrapper built-in xbmc on my own addon data or directory items to fetch posters/fanarts/thumbs/info...etc, and how to do this?

4. Finally, how can I make it work automatically on startup (silently in the background)

I am not asking for detailed code, just few lines snippet or even pseudo/human description with pointers. I also don't expect someone to answer them all, if you know one answer, then please share it with me.

I appreciate any help.
find quote
tria Offline
Senior Member
Posts: 108
Joined: Jan 2012
Reputation: 0
Post: #2
Well, for question #4 (and maybe #1 and #2), I found that there is a new feature which is to set your addon to be a "service" that can be set to start with xbmc or right after login. I will try it to see if it is suitable to what I need.

I am left for the time being with question #3, using the builtin tvdb scrapper with my own addon
find quote
pkscout Online
Posting Freak
Posts: 1,095
Joined: Jan 2011
Reputation: 23
Location: Honolulu, HI
Post: #3
tria Wrote:Hello,

1. Is it possible to download (or scrap and download) a file in the background silently (keyword silently). If so, how to achieve such thing (not the download process, but the "background silently").

2. How can this download be on a separate thread (not necessarily a real thread, but the same idea), so that it doesn't interfere with the addon/user?

Here's a chunk of code Artist Slideshow uses to download a file to a temp directory and then copy it to two other directories:
Code:
def download(src, dst, dst2):
    if (not xbmc.abortRequested):
        tmpname = xbmc.translatePath('special://profile/addon_data/%s/temp/%s' % ( __addonname__ , xbmc.getCacheThumbName(src) ))
        if xbmcvfs.exists(tmpname):
            xbmcvfs.delete(tmpname)
        urllib.urlretrieve(src, tmpname)
        if os.path.getsize(tmpname) > 999:
            log( 'copying file to transition directory' )
            xbmcvfs.copy(tmpname, dst2)
            log( 'moving file to cache directory' )
            xbmcvfs.rename(tmpname, dst)
        else:
            xbmcvfs.delete(tmpname)

and to spawn that in a separate thread (assuming you import the threading module), you could do:
Code:
self.thread = threading.Thread( target=self.download(src, dst, dst2) )
self.thread.setDaemon(True)
self.thread.start()

I am not a threading expert, so I *think* the thread will self destruct after the download is done.
find quote
jmarshall Offline
Team-XBMC Developer
Posts: 26,221
Joined: Oct 2003
Reputation: 178
Post: #4
Currently XBMC does not expose it's database facilities to add-ons. It's something we want to do in the future, and would then be handled internally.

For now, there's not a lot you can do I suspect (at least, not nicely).

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: badge.gif]
find quote
tria Offline
Senior Member
Posts: 108
Joined: Jan 2012
Reputation: 0
Post: #5
Thanks pkscuot for the snippet. I especially liked the threading sample.

jmarshall, adding this feature will move the efforts of developers into improving the scraping sources for both them and the xbmc project at the same time.

Thanks guys, all my question have been answered.
find quote