Some questions about Built-in function with "addContextMenuItems"
#1
I'm developing the plugin that can download the class material files from my school server

Once I got all the list of items show up on the screen I've implement the "addContextMenuItems" methods

to let the plugin call the SimpleDownloader script from the "Download" context menu

What I need to ask is how can i parse the parameters likes filename,url and download location, from the plugin to the SimpleDownloader
Reply
#2
Here is example code:
Code:
import SimpleDownloader
sd = SimpleDownloader.SimpleDownloader()
filename = 'test.flv'
params = {
    'url': 'http://server/test.flv',
    'download_path': 'C:\\temp\\',  # windows
    #'download_path': '/tmp/',  # linux/osx
}
sd.download(filename, params)

of course you should use dynamic download_path, filename and url Wink
My GitHub. My Add-ons:
Image
Reply
#3
I may be wrong but I don't think he's asking how to set the parms for the downloader, but how to get the parms from the list item that he is pulling up the context menu on

If that's the case you need to set them up when creating the context menu items

Here's what I do in one of my addons, setting the watched flag for movies/tvshows.. this is done for every list item

Code:
contextMenuItems.append((watched_mark, 'XBMC.RunPlugin(%s?mode=watch_mark&video_type=%s&title=%s&imdb_id=%s&season=%s&episode=%s)' % (sys.argv[0], video_type, vidtitle, imdb, season_num, episode_num)))


I call my addon again and passing in parms, the parms come after the ?
Reply
#4
(2012-11-23, 20:31)Eldorado Wrote: I may be wrong but I don't think he's asking how to set the parms for the downloader, but how to get the parms from the list item that he is pulling up the context menu on

If that's the case you need to set them up when creating the context menu items

Here's what I do in one of my addons, setting the watched flag for movies/tvshows.. this is done for every list item

Code:
contextMenuItems.append((watched_mark, 'XBMC.RunPlugin(%s?mode=watch_mark&video_type=%s&title=%s&imdb_id=%s&season=%s&episode=%s)' % (sys.argv[0], video_type, vidtitle, imdb, season_num, episode_num)))


I call my addon again and passing in parms, the parms come after the ?

This is what i means (sorry sphere to make u misunderstood Big Grin )

Anyway, i'm still not clear about some of the patterns above.

I know that "watched_mark" is the label that will be show on context menu but i'm getting confused about everything behind

could you please explain to me where everything flows


Ps.from my guess the (sys.argv[0],video_type,vidtitle,imdb,season_num,episode_num) are the add-ons parameter which going to be parse to the (%s?mode=watch_mark&video_type=%s&title=%s&imdb_id=%s&season=%s&episode=%s) is it correct Huh
Reply
#5
Have you read the documentation? http://mirrors.xbmc.org/docs/python-docs...l#ListItem EDIT: Ah, sorry, you have and your last assumption is correct.

Pneumatic | SABnzbd | XBMC that just works - openelec
Reply
#6
I think i'm going to the wrong way....

the things that I really want to do is to create a "Download" buttons to the context menu

and let the user download the files to the specific location with the specific links and names.


I had looking through "The Trailers" source code and getting a lot confusing about how it works

Hope the image below will make you all understand what i'm really want to do.

Image
Reply
#7
Let's work backwards. What is the list item url you need to call to invoke your download function for any given piece of content? It should be something like:

plugin://plugin.video.myvideoplugin/?mode=download&url=example.com
Reply
#8
(2012-11-24, 18:01)Bstrdsmkr Wrote: Let's work backwards. What is the list item url you need to call to invoke your download function for any given piece of content? It should be something like:

plugin://plugin.video.myvideoplugin/?mode=download&url=example.com

I'm not clearly understand what you want to means.Huh

But the item url that i want to download is somethings like "https://learning.myfaculty.mycampus.ac/uploads/subject/153/Lab6-sol.pdf"
Reply
#9
I'm assuming that you've already gotten to the point that you can list the items and view the files when you select the list items. At some point, you would have created a plugin:// url which causes your plugin to go to a different section. Most commonly, this is done by passing a "mode=" parameter.

Can you link to the code you have so far?
Reply
#10
Thanks for your help Bstrdmkr

did you means that I can use "RunPlugin" to run the add-on itself again and passing the "mode=" parameter to the destination

so I need to set the parameter inside the bracket as "xbmc.RunPlugin(?mode=download)" and create one method that implement SimpleDownloader

then create the condition outside the methods like

if mode=download
download_method(name,link)


Is those methods above correct ? Smile
Reply
#11
That's it exactly. Look back at Eldorado's code example. He's just dynamically assembling the setting to be passed to RunPlugin. Then inside your called function, you'll want something like sphere posted above
Reply
#12
Thanks for your guide Bstrdsmkr !

I will now try it and hope it will work Smile
Reply
#13
I'm facing another problem Big Grin

For now, I can pass the parameter and make it download the files that i want (Thanks to Bstrdmkr!)

However, there were a bug that my plugin can only download the file once at a time.

I need to restart XBMC to make it can download again, so I go check the log files and see this

Code:
21:43:02 T:5820   ERROR: C:\Users\me\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib\DialogDownloadProgress.py:136: DeprecationWarning: object.__init__() takes no parameters
                                              xbmcgui.WindowXMLDialog.__init__(self, *args, **kwargs)
21:43:02 T:3504   ERROR: CLocalizeStrings::ClearBlock: Trying to clear non existent block C:\Users\ITTIPRATEEP\AppData\Roaming\XBMC\addons\script.module.simple.downloader
21:43:03 T:5820   ERROR: Exception in thread Thread-1:
                                            Traceback (most recent call last):
                                              File "C:\Program Files (x86)\XBMC\system\python\Lib\threading.py", line 532, in __bootstrap_inner
                                                self.run()
                                              File "C:\Program Files (x86)\XBMC\system\python\Lib\threading.py", line 484, in run
                                                self.__target(*self.__args, **self.__kwargs)
                                              File "C:\Users\me\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib\SimpleDownloader.py", line 125, in _startDownload
                                                self._processQueue()
                                              File "C:\Users\me\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib\SimpleDownloader.py", line 162, in _processQueue
                                                self._setPaths(filename, item)
                                              File "C:\Users\me\AppData\Roaming\XBMC\addons\script.module.simple.downloader\lib\SimpleDownloader.py", line 134, in _setPaths
                                                params["path_incomplete"] = os.path.join(self.temporary_path.decode("utf-8"), self.common.makeUTF8(filename))
                                            TypeError: 'str' object does not support item assignment


I think I'm implement the SimpleDownloader by following the patterns which shown on XBMC's wiki like this

Code:
def download_material(filename,url):
        local_path = __settings__.getSetting('download_location')
        params = {'url' : url, 'download_path' : local_path}
        sd.download(filename,params)

Anyone can give me another idea to solve this bug ?
Reply
#14
Never used simple downloader myself. Try Sphere's code sample above. If that doesn't work, hit up their thread
Reply

Logout Mark Read Team Forum Stats Members Help
Some questions about Built-in function with "addContextMenuItems"0