Kodi Community Forum

Full Version: scrapping, downloading, and background process
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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.
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
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.
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).
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.