def initCookie(self): self.__log('start initCookie') addon = xbmcaddon.Addon(self.PLUGINID) cookiepath = xbmc.translatePath(addon.getAddonInfo('profile')) cookiepath = cookiepath + self.COOKIEFILE cookiepath = xbmc.translatePath(cookiepath) #set global self.__cookiepath__ = cookiepath self.__log('Cookiepath: ' + cookiepath) cj = cookielib.LWPCookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) #if exist load file and cookie information if (os.path.isfile(cookiepath)): cj.load(cookiepath, False, False) self.__log('Cookies loaded from file: ' + cookiepath) for index, cookie in enumerate(cj): self.__log('cookies come here: ') else: self.__log('No cookie file found at: ' + cookiepath) #set global object self.__cj__ = cj self.__log('Finished initCookie') '''
def __init__(self, name, plugin_id, filepath=None, debug=False): '''Initialize a plugin object for an XBMC addon.''' self._name = name self._filepath = filepath self._plugin_id = plugin_id # Keeps track of url routes self._routes = [] self._view_functions = {} args = self.parse_commandline(sys.argv) self._plugin = xbmcaddon.Addon(id=self._plugin_id) if self._mode in debug_modes: self._plugin._setup(os.path.dirname(self._filepath)) self._argv0, self._argv1, self._argv2 = args self.handle = int(self._argv1) self.qs_args = parse_qs(self._argv2.lstrip('?')) self.scheme, self.netloc, self.path = urlparse(self._argv0) self._cache_path = xbmc.translatePath( 'special://profile/addon_data/%s/.cache' % self._plugin_id)
def __get_source(source_id): cache_path = os.path.join( xbmc.translatePath(plugin._plugin.getAddonInfo('profile')), 'cache', ) if not os.path.isdir(cache_path): os.makedirs(cache_path) if source_id == 'apple': __log('__get_source using: %s' % source_id) source = apple_trailers.AppleTrailers(cache_path) return source else: raise Exception('UNKNOWN SOURCE: %s' % source_id)
def __init__(self, name, plugin_id, filepath=None, debug=False): '''Initialize a plugin object for an XBMC addon.''' self._name = name self._filepath = filepath self._plugin_id = plugin_id # Keeps track of url routes self._routes = [] self._view_functions = {} args = self.parse_commandline(sys.argv) self._plugin = xbmcaddon.Addon(id=self._plugin_id) if self._mode in debug_modes: self._plugin._setup(os.path.dirname(self._filepath)) self._argv0, self._argv1, self._argv2 = args self.handle = int(self._argv1) self.qs_args = parse_qs(self._argv2.lstrip('?')) self.scheme, self.netloc, self.path = urlparse(self._argv0) self._cache_path = xbmc.translatePath('special://profile/addon_data/%s/.cache' % self._plugin_id)
import os, sys, urllib, xbmcplugin, xbmcaddon from xbmcswift import download_page, xbmc, xbmcgui from addon.common.addon import Addon try: import json except ImportError: import simplejson as json addon_id='plugin.video.showmax' icon = xbmc.translatePath(os.path.join('special://home/addons/' + addon_id, 'icon.png')) fanart = xbmc.translatePath(os.path.join('special://home/addons/' + addon_id, 'fanart.jpg')) selfAddon = xbmcaddon.Addon(id=addon_id) addon = Addon(addon_id, sys.argv) API_BASE = 'https://api.showmax.com/v36.0/website/catalogue/' seriesurl = 'search?lang=eng&num=50&type=tv_series' moviesurl = 'search?lang=eng&num=50&type=movie' #https://api.showmax.com/v24.0/website/catalogue/search?lang=eng&num=30&start=60 def cat(): addDir('Search','',1,icon,fanart,'') addDir('Series',seriesurl,2,icon,fanart,'') addDir('Movies',moviesurl,6,icon,fanart,'') addDir('Language','',3,icon,fanart,'') addDir('Categories','',4,icon,fanart,'') addDir('Sections','',5,icon,fanart,'') def Search(): keyb = xbmc.Keyboard('', 'Search') keyb.doModal()
def temp_fn(self, path): return os.path.join(xbmc.translatePath('special://temp'), path)
from pyxbmct.addonwindow import * import sys import json import os.path from urllib2 import Request import urllib import urllib2 import datetime import time __addon__ = xbmcaddon.Addon() __addon_name__ = __addon__.getAddonInfo('name') __id__ = __addon__.getAddonInfo('id') __lang__ = __addon__.getLocalizedString __version__ = __addon__.getAddonInfo('version') __profile_path__ = xbmc.translatePath( __addon__.getAddonInfo('profile')).decode("utf-8") __token_filepath__ = __profile_path__ + '/token.txt' # BEGIN # Plugin class Plugin_mod(Plugin): def add_items(self, iterable, is_update=False, sort_method_ids=[]): items = [] urls = [] for i, li_info in enumerate(iterable): items.append(self._make_listitem(**li_info)) if self._mode in ['crawl', 'interactive']: print '[%d] %s%s%s (%s)' % (i + 1, '', li_info.get('label'), '', li_info.get('url'))
# BEGIN # if plugin.get_setting('server_url'): SITE_PATH = plugin.get_setting('server_url') else: SITE_PATH = 'http://mytv.bg/api/mobile_v2/' # Onli load master menu ONLI_MASTER_MENU = SITE_PATH + 'menu/index' SITE_LOGIN_PAGE = SITE_PATH + 'user/signin' # END # __addon__ = xbmcaddon.Addon() __version__ = __addon__.getAddonInfo('version') __profile_path__ = xbmc.translatePath( __addon__.getAddonInfo('profile') ).decode("utf-8") __token_filepath__ = __profile_path__ + '/' + TOKEN_FILE @plugin.route('/') def main_menu(): request = urllib2.Request(ONLI_MASTER_MENU, headers={"User-Agent" : "XBMC/Kodi MyTV Addon " + str(__version__)}) response = urllib2.urlopen(request) dataNew = json.loads(response.read()) menulist = dataNew['menu'] items = [] for (key, val) in enumerate(menulist): items.append({"label": u"{0}".format(val['title']),
def download_play_trailer(local_path, remote_url, trailer_id): # if remote_url is None, trailer is already downloaded - play it if not remote_url: return plugin.set_resolved_url(local_path) # we need to sleep before creating progress dialog xbmc.sleep(500) # create progress dialog pDialog = xbmcgui.DialogProgress() pDialog.create(__addon_name__) pDialog.update(0) # if there is a useragent set in the url, split it for urllib downloading if '?|User-Agent=' in remote_url: remote_url, useragent = remote_url.split('?|User-Agent=') __log('detected useragent:"%s"' % useragent) class _urlopener(urllib.URLopener): version = useragent urllib._urlopener = _urlopener() # split filename from local_path for dialog line download_path, filename = os.path.split(local_path) tmppath = os.path.join( xbmc.translatePath(plugin._plugin.getAddonInfo('profile')), filename, ).decode('utf-8') # TODO: change text to downloading and add the amt download speed/time? def _report_hook(count, blocksize, totalsize): percent = int(float(count * blocksize * 100) / totalsize) msg1 = _('downloading_trailer') msg2 = filename if pDialog.iscanceled(): # raise KeyboardInterrupt to stop download in progress raise KeyboardInterrupt pDialog.update(percent, msg1, msg2) __log('start downloading: %s to path: %s' % (filename, download_path)) try: if not urllib.urlretrieve(remote_url, tmppath, _report_hook): __log('downloading failed') xbmcvfs.delete(tmppath) pDialog.close() return # catch KeyboardInterrupt which was rised to stop the dl silently except KeyboardInterrupt: __log('downloading canceled') xbmcvfs.delete(tmppath) pDialog.close() return xbmc.sleep(100) __log('downloading successfully completed, start moving') xbmcvfs.copy(tmppath, local_path) xbmcvfs.delete(tmppath) __log('moving completed') pDialog.close() plugin.set_setting(trailer_id, local_path) __log('start playback') return plugin.set_resolved_url(local_path)
def __get_cache(): profile_path = plugin._plugin.getAddonInfo('profile').decode('utf-8') cache_path = xbmc.translatePath(profile_path) return resources.lib.cache.Cache(cache_path)