123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- # -*- coding: utf-8 -*-
- try:
- import wingdbstub
- except:
- pass
-
- import sys, os, urllib2, urllib, re, requests, datetime, time, json
- #CLI_MODE = True
- from kodiswift import xbmc, xbmcgui, xbmcplugin, CLI_MODE
- from kodiswift import Plugin, storage
- import pyxbmct.addonwindow as pyxbmct
- from downloadqueue import DownloadQueue
- import traceback, threading
- from resources.lib.content import file
-
-
- plugin = Plugin(addon_id="plugin.video.playstream")
- prefix = "plugin://plugin.video.playstream/"
- #plugin.load_addon_settings()
- timer = None
- timer_file = os.path.join(xbmc.translatePath("special://temp"), "timer_active") if not CLI_MODE else "timer_active"
- if os.path.exists(timer_file): os.remove(timer_file)
- sleep_time = 5 # TODO jāliek iekš parametriem
-
- #print "argv=",sys.argv
- handle = int(sys.argv[1])
- handle = 7777
- cmd = sys.argv[2]
- job_id = sys.argv[3] if len(sys.argv) > 3 else None
-
- queue_dir = os.path.join(xbmc.translatePath("special://temp"), "download_queue") if not CLI_MODE else "download_queue"
- download_queue = DownloadQueue(queue_dir)
-
- if not os.path.exists(queue_dir):
- os.mkdir(queue_dir)
-
-
- def main():
-
- if cmd == "list":
- ret = downloads_list()
- elif cmd == "view":
- ret = downloads_view_job(job_id)
- else:
- ret = downloads_cmd(cmd, job_id)
-
- def refresh_container():
- global timer
- if os.path.exists(timer_file):
- xbmc.executebuiltin('Container.Refresh')
- else:
- timer.stop()
-
- def downloads_list():
-
- #plugin.finish(items, view_mode=get_view_mode("WideList"), update_listing=True, cache_to_disc=False)
- #xbmcplugin.endOfDirectory(handle, succeeded=True, updateListing=True, cacheToDisc=False)
-
- items = ["Item {0}".format(i) for i in xrange(1, 11)]
- dialog = MultiChoiceDialog("Select items", [])
- dialog.doModal()
- xbmcgui.Dialog().notification("Finished", "Selected: {0}".format(str(dialog.selected)))
- del dialog #You need to delete your instance when it is no longer needed
-
-
- timer = threading.Timer(4.0, refresh_container)
- #timer.start()
- #open(timer_file, "w").write("started")
-
- def get_jobs():
- global timer
- jobs = download_queue.jobs()
- items = []
- i = 1
- for job in jobs:
- progress = float(job["currentbytes"])/float(job["totalbytes"])*100 if job["currentbytes"] and job["totalbytes"] else ""
- msg = "%.1f%% (%iMB/%iMB)"%(progress, job["currentbytes"] / 1024 / 1024, job["totalbytes"] / 1024 / 1024)
- title = "%s - %s: %s" % (job["status"], msg, job["output"])
- data2 = prefix + "downloads::view/%s" % job["job_id"]
- is_playable = False
- img = None
- desc = "%s\n%s\n%s\n%s\n%s" % (job["output"], msg, job["job_id"], job["file"], job["url"])
- #print title.encode("utf8"),data2,img
- context_menu = [
- ("Cancel download job", u'RunPlugin(plugin://plugin.video.playstream/downloads::cancel/%s'%(job["job_id"])),
- ("Pause download job", u'RunPlugin(plugin://plugin.video.playstream/downloads::pause/%s'%(job["job_id"])),
- ("Continue paused download job", u'RunPlugin(plugin://plugin.video.playstream/downloads::continue/%s'%(job["job_id"])),
- ("Cancel all jobs", u'RunPlugin(plugin://plugin.video.playstream/downloads::cancel_all'),
- ]
-
- item2 = xbmcgui.ListItem(title, "", "", "", data2)
- item2.setInfo("Video", {"title":title, "plot": desc,})
- item2.addContextMenuItems(context_menu)
- #item.setProperty("is_folder", "true")
- items.append(item2)
- #xbmcplugin.addDirectoryItem(handle=handle, url=data2, listitem=item2, isFolder=False)
- i += 1
- return items
-
-
- def downloads_view_job(job_id):
- pass
-
- def downloads_cmd(cmd, params):
- pass
-
- def get_view_mode(vm):
- modes = {
- "skin.estuary": {
- "None": None,
- "List": 50,
- "Poster": 51,
- "IconWall":52 ,
- "Shift": 53,
- "InfoWall": 54,
- "WideList": 55,
- "Wall": 500,
- "Banner": 501,
- "FanArt": 502
- },
- "skin.estuary.is": {
- "None": None,
- "List": 50,
- "Poster": 51,
- "IconWall":52 ,
- "Shift": 53,
- "InfoWall": 54,
- "WideList": 55,
- "Wall": 500,
- "Banner": 501,
- "FanArt": 502
- },
- }
- skin = xbmc.getSkinDir()
- if skin in modes and vm in modes[skin]:
- view_mode = modes[skin][vm]
- else:
- view_mode = 50
- return view_mode
-
- class MultiChoiceDialog(pyxbmct.AddonDialogWindow):
- def __init__(self, title="", items=None):
- super(MultiChoiceDialog, self).__init__(title)
- self.setGeometry(1200, 760, 10, 10)
- self.selected = []
- self.set_controls()
- self.connect_controls()
- self.update_list()
- self.set_navigation()
-
- def onAction(self, action):
- action_id = action.getId()
- if action_id in (101, 117):
- print "Context menu"
-
- def update_list(self):
- items = get_jobs()
- self.listing.reset()
- self.listing.addItems(items)
-
- def set_controls(self):
- self.listing = pyxbmct.List(_imageWidth=15)
- self.placeControl(self.listing, 0, 0, rowspan=10, columnspan=9)
- self.ok_button = pyxbmct.Button("OK")
- self.placeControl(self.ok_button, 1, 9)
- self.cancel_button = pyxbmct.Button("Cancel")
- self.placeControl(self.cancel_button, 2, 9)
-
- def connect_controls(self):
- self.connect(self.listing, self.item_selected)
- self.connect(self.ok_button, self.ok)
- self.connect(self.cancel_button, self.close)
- self.connect(117, self.context_menu)
-
- def set_navigation(self):
- self.listing.controlRight(self.ok_button)
- self.listing.controlLeft(self.ok_button)
- self.ok_button.setNavigation(self.listing, self.listing, self.cancel_button, self.cancel_button)
- self.cancel_button.setNavigation(self.listing, self.listing, self.ok_button, self.ok_button)
- if self.listing.size():
- self.setFocus(self.listing)
- else:
- self.setFocus(self.cancel_button)
-
- def context_menu(self):
- list_item = self.listing.getSelectedItem()
- print "aaaa"
-
-
- def item_selected(self):
- list_item = self.listing.getSelectedItem()
- pass
-
-
- def ok(self):
- self.selected = self.listing.getSelectedItem()
- super(MultiChoiceDialog, self).close()
-
- def close(self):
- self.selected = None
- super(MultiChoiceDialog, self).close()
-
- if __name__ == '__main__':
- main()
|