Advertisement
Guest User

error in xbmc script

a guest
Jun 26th, 2014
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 20.55 KB | None | 0 0
  1. ### ############################################################################################################
  2. ### #  
  3. ### # Project:          #       Infowars.com Plugin
  4. ### #  
  5. ### ############################################################################################################
  6. ### ############################################################################################################
  7. ### Plugin Settings ###
  8.  
  9. def ps(x):
  10.     return {
  11.         '__plugin__':                   "Infowars"
  12.         ,'__authors__':                 "Prafit"
  13.         ,'__credits__':                 ""
  14.         ,'_addon_id':                   "plugin.video.infowars"
  15.         ,'_plugin_id':                  "plugin.video.infowars"
  16.         ,'_domain_url':                 "infowars.com"
  17.         ,'_database_name':          "infowars"
  18.         ,'_addon_path_art':         "art"
  19.         ,'special.home.addons': 'special:'+os.sep+os.sep+'home'+os.sep+'addons'+os.sep
  20.         ,'special.home':                'special:'+os.sep+os.sep+'home'
  21.         ,'content_movies':          "movies"
  22.         ,'content_tvshows':         "tvshows"
  23.         ,'content_episodes':        "episodes"
  24.         ,'content_links':           "list"
  25.         ,'common_word':                 "Anime"
  26.         ,'common_word2':                "Watch"
  27.         ,'default_art_ext':         '.png'
  28.         ,'default_cFL_color':   'green'
  29.         ,'cFL_color':                   'lime'
  30.         ,'cFL_color2':                  'yellow'
  31.         ,'cFL_color3':                  'red'
  32.         ,'cFL_color4':                  'grey'
  33.         ,'cFL_color5':                  'white'
  34.         ,'cFL_color6':                  'blanchedalmond'
  35.         ,'default_section':         'movies'
  36.         ,'section.wallpaper':       'wallpapers'
  37.         ,'section.movie':           'movies'
  38.         ,'section.trailers':        'trailers'
  39.         ,'section.trailers.popular':            'trailerspopular'
  40.         ,'section.trailers.releasedate':    'trailersreleasedate'
  41.         ,'section.users':               'users'
  42.         ,'section.tv':                  'tv'
  43.     }[x]
  44.  
  45.  
  46.  
  47. ### ##### /\ ##### Plugin Settings ###
  48. ### ############################################################################################################
  49. ### ############################################################################################################
  50. ### ############################################################################################################
  51. ##### Imports #####
  52. ##Notes-> Some Default imports so that you can use the functions that are available to them.
  53. import xbmc,xbmcplugin,xbmcgui,xbmcaddon,xbmcvfs
  54. import urllib,urllib2,re,os,sys,htmllib,string,StringIO,logging,random,array,time,datetime
  55. import plugintools
  56. import copy
  57. import HTMLParser, htmlentitydefs
  58. ##Notes-> Common script.module.___ that is used by many to resolve urls of many video hosters.
  59. ## ##Notes-> Sometimes you can will use this method.
  60. ## ##Notes-> Sometimes you'll have to parse out the direct/playabe url of a video yourself.
  61. import urlresolver
  62. ##Notes-> I often use this in the cache-method for addon favorites.
  63. try:        import StorageServer
  64. except: import storageserverdummy as StorageServer
  65. ##Notes-> t0mm0's common module for addon and net functions.
  66. ## ##Notes-> I sometimes toss a copy of these modules into my addon folders just incase they dont have them installed... even if that's not a great practice.  I use them a LOT, so in this case it's a habbit.
  67. try:        from t0mm0.common.addon                 import Addon
  68. except: from t0mm0_common_addon                 import Addon
  69. try:        from t0mm0.common.net                   import Net
  70. except: from t0mm0_common_net                   import Net
  71.  
  72. ##Notes-> modules to import if you play to use SQL DB stuff in your addon.
  73. try:        from sqlite3                                        import dbapi2 as sqlite; print "Loading sqlite3 as DB engine"
  74. except: from pysqlite2                                  import dbapi2 as sqlite; print "Loading pysqlite2 as DB engine"
  75.  
  76.  
  77. ##Notes-> how to import another .py file from your addon's folder.  Example: to import "config.py" you'd use: "from config import *"
  78. #from teh_tools         import *
  79. #from config            import *
  80.  
  81. ##### /\ ##### Imports #####
  82.  
  83. ### ############################################################################################################
  84. ### ############################################################################################################
  85. ### ############################################################################################################
  86. __plugin__=ps('__plugin__');
  87. __authors__=ps('__authors__');
  88. __credits__=ps('__credits__');
  89. _addon_id=ps('_addon_id');
  90. _domain_url=ps('_domain_url');
  91. _database_name=ps('_database_name');
  92. _plugin_id=ps('_addon_id')
  93. _database_file=os.path.join(xbmc.translatePath("special://database"),ps('_database_name')+'.db');
  94. ###
  95. _addon=Addon(ps('_addon_id'), sys.argv); addon=_addon; _plugin=xbmcaddon.Addon(id=ps('_addon_id')); cache=StorageServer.StorageServer(ps('_addon_id'))
  96. ###
  97. ### ############################################################################################################
  98. ### ############################################################################################################
  99. ### ############################################################################################################
  100. ##Notes-> I placed these here so that they would be before the stuff that they use during setup.
  101. def addst(r,s=''): return _addon.get_setting(r)   ## Get Settings
  102. def addpr(r,s=''): return _addon.queries.get(r,s) ## Get Params
  103. def tfalse(r,d=False): ## Get True / False
  104.     if   (r.lower()=='true' ): return True
  105.     elif (r.lower()=='false'): return False
  106.     else: return d
  107. ##### Paths #####
  108. ### # ps('')
  109. _addonPath  =xbmc.translatePath(_plugin.getAddonInfo('path'))
  110. _artPath        =xbmc.translatePath(os.path.join(_addonPath,ps('_addon_path_art')))
  111. _datapath   =xbmc.translatePath(_addon.get_profile()); _artIcon     =_addon.get_icon(); _artFanart  =_addon.get_fanart()
  112. ##### /\ ##### Paths #####
  113. ##### Important Functions with some dependencies #####
  114. def art(f,fe=ps('default_art_ext')): return xbmc.translatePath(os.path.join(_artPath,f+fe)) ### for Making path+filename+ext data for Art Images. ###
  115. ##### /\ ##### Important Functions with some dependencies #####
  116. ##### Settings #####
  117. _setting={};
  118. ##Notes-> options from the settings.xml file.
  119. _setting['enableMeta']  =   _enableMeta         =tfalse(addst("enableMeta"))
  120. _setting['debug-enable']=   _debugging          =tfalse(addst("debug-enable")); _setting['debug-show']  =   _shoDebugging       =tfalse(addst("debug-show"))
  121. _setting['label-empty-favorites']=tfalse(addst('label-empty-favorites'))
  122. ##Notes-> some custom settings.
  123. #_setting['meta.movie.domain']=ps('meta.movie.domain'); _setting['meta.movie.search']=ps('meta.movie.search')
  124. #_setting['meta.tv.domain']   =ps('meta.tv.domain');    _setting['meta.tv.search']   =ps('meta.tv.search')
  125. #_setting['meta.tv.page']=ps('meta.tv.page'); _setting['meta.tv.fanart.url']=ps('meta.tv.fanart.url');
  126. #_setting['meta.tv.fanart.url2']=ps('meta.tv.fanart.url2');
  127. ##### /\ ##### Settings #####
  128. ##### Variables #####
  129. _default_section_=ps('default_section'); net=Net(); DB=_database_file; BASE_URL=_domain_url;
  130. ### ############################################################################################################
  131. ##Notes-> Some important time saving functions to shorten your work later.
  132. #def eod(): _addon.end_of_directory() ## used at the end of a folder listing to print the list to the screen.
  133. def eod(): xbmcplugin.endOfDirectory(int(sys.argv[1]))
  134. def myNote(header='',msg='',delay=5000,image=''): _addon.show_small_popup(title=header,msg=msg,delay=delay,image=image)
  135. def cFL( t,c=ps('default_cFL_color')): return '[COLOR '+c+']'+t+'[/COLOR]' ### For Coloring Text ###
  136. def cFL_(t,c=ps('default_cFL_color')): return '[COLOR '+c+']'+t[0:1]+'[/COLOR]'+t[1:] ### For Coloring Text (First Letter-Only) ###
  137. def notification(header="", message="", sleep=5000 ): xbmc.executebuiltin( "XBMC.Notification(%s,%s,%i)" % ( header, message, sleep ) )
  138. def WhereAmI(t): ### for Writing Location Data to log file ###
  139.     if (_debugging==True): print 'Where am I:  '+t
  140. def deb(s,t): ### for Writing Debug Data to log file ###
  141.     if (_debugging==True): print s+':  '+t
  142. def debob(t): ### for Writing Debug Object to log file ###
  143.     if (_debugging==True): print t
  144. def nolines(t):
  145.     it=t.splitlines(); t=''
  146.     for L in it: t=t+L
  147.     t=((t.replace("\r","")).replace("\n",""))
  148.     return t
  149. def isPath(path): return os.path.exists(path)
  150. def isFile(filename): return os.path.isfile(filename)
  151. def askSelection(option_list=[],txtHeader=''):
  152.     if (option_list==[]):
  153.         if (debugging==True): print 'askSelection() >> option_list is empty'
  154.         return None
  155.     dialogSelect = xbmcgui.Dialog();
  156.     index=dialogSelect.select(txtHeader, option_list)
  157.     return index
  158. def iFL(t): return '[I]'+t+'[/I]' ### For Italic Text ###
  159. def bFL(t): return '[B]'+t+'[/B]' ### For Bold Text ###
  160. def _FL(t,c,e=''): ### For Custom Text Tags ###
  161.     if (e==''): d=''
  162.     else: d=' '+e
  163.     return '['+c.upper()+d+']'+t+'[/'+c.upper()+']'
  164.  
  165. #Metahandler
  166. try:        from script.module.metahandler  import metahandlers
  167. except: from metahandler                                import metahandlers
  168. grab=metahandlers.MetaData(preparezip=False)
  169. def GRABMETA(name,types):
  170.     type=types
  171.     EnableMeta=tfalse(addst("enableMeta"))
  172.     if (EnableMeta==True):
  173.         if ('movie' in type):
  174.             ### grab.get_meta(media_type, name, imdb_id='', tmdb_id='', year='', overlay=6)
  175.             meta=grab.get_meta('movie',name,'',None,None,overlay=6)
  176.             infoLabels={'rating': meta['rating'],'duration': meta['duration'],'genre': meta['genre'],'mpaa':"rated %s"%meta['mpaa'],'plot': meta['plot'],'title': meta['title'],'writer': meta['writer'],'cover_url': meta['cover_url'],'director': meta['director'],'cast': meta['cast'],'backdrop': meta['backdrop_url'],'backdrop_url': meta['backdrop_url'],'tmdb_id': meta['tmdb_id'],'year': meta['year'],'votes': meta['votes'],'tagline': meta['tagline'],'premiered': meta['premiered'],'trailer_url': meta['trailer_url'],'studio': meta['studio'],'imdb_id': meta['imdb_id'],'thumb_url': meta['thumb_url']}
  177.             #infoLabels={'rating': meta['rating'],'duration': meta['duration'],'genre': meta['genre'],'mpaa':"rated %s"%meta['mpaa'],'plot': meta['plot'],'title': meta['title'],'writer': meta['writer'],'cover_url': meta['cover_url'],'director': meta['director'],'cast': meta['cast'],'backdrop_url': meta['backdrop_url'],'backdrop_url': meta['backdrop_url'],'tmdb_id': meta['tmdb_id'],'year': meta['year']}
  178.         elif ('tvshow' in type):
  179.             meta=grab.get_meta('tvshow',name,'','',None,overlay=6)
  180.             #print meta
  181.             infoLabels={'rating': meta['rating'],'genre': meta['genre'],'mpaa':"rated %s"%meta['mpaa'],'plot': meta['plot'],'title': meta['title'],'cover_url': meta['cover_url'],'cast': meta['cast'],'studio': meta['studio'],'banner_url': meta['banner_url'],'backdrop_url': meta['backdrop_url'],'status': meta['status'],'premiered': meta['premiered'],'imdb_id': meta['imdb_id'],'tvdb_id': meta['tvdb_id'],'year': meta['year'],'imgs_prepacked': meta['imgs_prepacked'],'overlay': meta['overlay'],'duration': meta['duration']}
  182.             #infoLabels={'rating': meta['rating'],'genre': meta['genre'],'mpaa':"rated %s"%meta['mpaa'],'plot': meta['plot'],'title': meta['title'],'cover_url': meta['cover_url'],'cast': meta['cast'],'studio': meta['studio'],'banner_url': meta['banner_url'],'backdrop_url': meta['backdrop_url'],'status': meta['status']}
  183.         else: infoLabels={}
  184.     else: infoLabels={}
  185.     return infoLabels
  186. ### ############################################################################################################
  187. ### ############################################################################################################
  188. ##### Queries #####
  189. _param={}
  190. ##Notes-> add more here for whatever params you want to use then you can just put the tagname within _param[''] to fetch it later.  or you can use addpr('tagname','defaultvalue').
  191. _param['mode']=addpr('mode',''); _param['url']=addpr('url',''); _param['pagesource'],_param['pageurl'],_param['pageno'],_param['pagecount']=addpr('pagesource',''),addpr('pageurl',''),addpr('pageno',0),addpr('pagecount',1)
  192. _param['img']=addpr('img',''); _param['fanart']=addpr('fanart',''); _param['thumbnail'],_param['thumbnail'],_param['thumbnail']=addpr('thumbnail',''),addpr('thumbnailshow',''),addpr('thumbnailepisode','')
  193. _param['section']=addpr('section','movies'); _param['title']=addpr('title',''); _param['year']=addpr('year',''); _param['genre']=addpr('genre','')
  194. _param['by']=addpr('by',''); _param['letter']=addpr('letter',''); _param['showtitle']=addpr('showtitle',''); _param['showyear']=addpr('showyear',''); _param['listitem']=addpr('listitem',''); _param['infoLabels']=addpr('infoLabels',''); _param['season']=addpr('season',''); _param['episode']=addpr('episode','')
  195. _param['pars']=addpr('pars',''); _param['labs']=addpr('labs',''); _param['name']=addpr('name',''); _param['thetvdbid']=addpr('thetvdbid','')
  196. _param['plot']=addpr('plot',''); _param['tomode']=addpr('tomode',''); _param['country']=addpr('country','')
  197. _param['thetvdb_series_id']=addpr('thetvdb_series_id',''); _param['dbid']=addpr('dbid',''); _param['user']=addpr('user','')
  198. _param['subfav']=addpr('subfav',''); _param['episodetitle']=addpr('episodetitle',''); _param['special']=addpr('special',''); _param['studio']=addpr('studio','')
  199. ##Notes-> another way to do it which my custom function just shortens down.
  200. #_param['']=_addon.queries.get('','')
  201.  
  202. ### ############################################################################################################
  203. ### ############################################################################################################
  204. ### ############################################################################################################
  205. ##### Player Functions #####
  206. def PlayURL(url):
  207.     play=xbmc.Player(xbmc.PLAYER_CORE_AUTO) ### xbmc.PLAYER_CORE_AUTO | xbmc.PLAYER_CORE_DVDPLAYER | xbmc.PLAYER_CORE_MPLAYER | xbmc.PLAYER_CORE_PAPLAYER
  208.     try: _addon.resolve_url(url)
  209.     except: t=''
  210.     try: play.play(url)
  211.     except: t=''
  212.    
  213. def play(params):
  214.     plugintools.play_resolved_url( params.get("url") ) 
  215.    
  216. ### ############################################################################################################
  217. ### ############################################################################################################
  218. ### ############################################################################################################
  219. def Menu_MainMenu(): #The Main Menu
  220.     WhereAmI('@ the Main Menu')
  221.     _addon.add_directory({'mode': 'PlayURL','url':'http://cdn.rbm.tv:1935/rightbrainmedia-originpull-2/_definst_/mp4:247daily2/playlist.m3u8'},{'title':  cFL_('Infowars.com Live Video(Loops After Airing)',ps('cFL_color'))},is_folder=False,img=_artIcon,fanart=_artFanart)
  222.     _addon.add_directory({'mode': 'DocSubMenu','title':'Acclaimed Documentaries'},{'title':  cFL_('Acclaimed Documentaries',ps('cFL_color3'))},is_folder=True,img=_artIcon,fanart=_artFanart)
  223.     _addon.add_directory({'mode': 'NightlyNewsSubMenu','title':'Infowars Nightly News'},{'title':  cFL_('Infowars Nightly News',ps('cFL_color3'))},is_folder=True,img=_artIcon,fanart=_artFanart)
  224.     eod()
  225.  
  226.  
  227. def Documentary_Sub_Menu(title=''): #The Main Menu
  228.     WhereAmI('@ Documentaries')
  229.     #mode left blank for main menu.
  230.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=eAaQNACwaLw'},{'title':'The Obama Deception'},is_folder=False,img=_artIcon,fanart=_artFanart)
  231.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=t-yscpNIxjI'},{'title':'The 9/11 Chronicles Part One: Truth Rising'},is_folder=False,img=_artIcon,fanart=_artFanart)
  232.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=x-CrNlilZho'},{'title':'End Game'},is_folder=False,img=_artIcon,fanart=_artFanart)
  233.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=vrXgLhkv21Y'},{'title':'TerrorStorm'},is_folder=False,img=_artIcon,fanart=_artFanart)
  234.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=BqxUFVsmPcQ'},{'title':'Martial Law: 9/11 Rise of the Police State'},is_folder=False,img=_artIcon,fanart=_artFanart)
  235.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=OVMyH8eOHKs'},{'title':'911: The Road to Tyranny'},is_folder=False,img=_artIcon,fanart=_artFanart)
  236.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=nxllWCPw6sU'},{'title':'Matrix of Evil'},is_folder=False,img=_artIcon,fanart=_artFanart)
  237.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=vsKVyhuBf3c'},{'title':'America Destroyed by Design'},is_folder=False,img=_artIcon,fanart=_artFanart)
  238.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=1Fr5QC6u2EQ'},{'title':'American Dictators'},is_folder=False,img=_artIcon,fanart=_artFanart)
  239.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=FVtEvplXMLs'},{'title':'Dark Secrets: Inside Bohemian Grove'},is_folder=False,img=_artIcon,fanart=_artFanart)
  240.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=VhlRIH9iPD4'},{'title':'The Order of Death'},is_folder=False,img=_artIcon,fanart=_artFanart)
  241.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=GKty_3IlXOc'},{'title':'Police State 2000 Martial Law Posse Comitatus'},is_folder=False,img=_artIcon,fanart=_artFanart)
  242.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=4Cf_tZzABgE'},{'title':'Police State 2: The Takeover'},is_folder=False,img=_artIcon,fanart=_artFanart)
  243.     _addon.add_directory({'mode': 'PlayURL','url':'plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid=K4RWRm-bgv8'},{'title':'Police State 3: Total Enslavement'},is_folder=False,img=_artIcon,fanart=_artFanart)
  244.     eod() #Ends the directory listing and prints it to the screen.  if you dont use eod() or something like it, the menu items won't be put to the screen.
  245.  
  246. def Nightly_News_Sub_Menu(title=''): #The Main Menu
  247.     WhereAmI('@ Nightly News')
  248.     url = 'http://gdata.youtube.com/feeds/api/users/ConspiracyScope/uploads?start-index=1&max-results=10'
  249.     response = urllib2.urlopen(url)
  250.     if response and response.getcode() == 200:
  251.         content = response.read()
  252.         videos= plugintools.find_multiple_matches(content,"<entry>(.*?)</entry>")
  253.         for entry in videos:
  254.             title = plugintools.find_single_match(entry,"<titl[^>]+>([^<]+)</title>")
  255.             plot = plugintools.find_single_match(entry,"<media\:descriptio[^>]+>([^<]+)</media\:description>")
  256.             thumbnail = plugintools.find_single_match(entry,"<media\:thumbnail url='([^']+)'")
  257.             video_id = plugintools.find_single_match(entry,"http\://www.youtube.com/watch\?v\=([^\&]+)\&").replace("&amp;","&")
  258.             url = "plugin://plugin.video.youtube/?path=/root/video&action=play_video&videoid="+video_id
  259.             if title.find('Nightly News') > -1:
  260.                 print title
  261.                 print plot
  262.                 print thumbnail
  263.                 print url
  264.                 #
  265.                 #  How do I add directory listing at this point?
  266.                 #
  267.                
  268.     else:
  269.         util.showError(ADDON_ID, 'Could not open URL %s to create menu' % (url))
  270.  
  271.     eod()
  272.  
  273. def check_mode(mode=''):
  274.  
  275.     deb('Mode',mode)
  276.     if (mode=='') or (mode=='main') or (mode=='MainMenu'):  Menu_MainMenu() ## Default Menu
  277.     elif (mode=='PlayURL'):                             PlayURL(_param['url']) ## Play Video
  278.     elif (mode=='DocSubMenu'):                      Documentary_Sub_Menu(_param['title']) ## Play Video
  279.     elif (mode=='NightlyNewsSubMenu'):                      Nightly_News_Sub_Menu(_param['title']) ## Play Video
  280.     elif (mode=='Settings'):                            _addon.addon.openSettings() # Another method: _plugin.openSettings() ## Settings for this addon.
  281.     elif (mode=='ResolverSettings'):            urlresolver.display_settings()  ## Settings for UrlResolver script.module.
  282.     #
  283.     #
  284.     #elif (mode=='YourMode'):                       YourFunction(_param['url'])
  285.     #
  286.     #
  287.     #
  288.     else: myNote(header='Mode:  "'+mode+'"',msg='[ mode ] not found.'); Menu_MainMenu() ## So that if a mode isn't found, it'll goto the Main Menu and give you a message about it.
  289.  
  290.  
  291. deb('param >> title',_param['title'])
  292. deb('param >> url',_param['url']) ### Simply Logging the current query-passed / param -- URL
  293. check_mode(_param['mode']) ### Runs the function that checks the mode and decides what the plugin should do. This should be at or near the end of the file.
  294. ### ############################################################################################################
  295. ### ############################################################################################################
  296. ### ############################################################################################################
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement