def walk(self, path, recursive=False, types=None): filenames = [] dirnames = [] files_to_return = [] dirs_to_return = [] if type(path).__name__ == 'unicode': path = path.encode('utf-8') if path.startswith('multipath://'): common.log("Scanner.walk", 'multipath "%s"' % path) dirs = path[12:-1].split('/') for item in dirs: dirnames1, filenames1 = self._walk(urllib.unquote_plus(item), recursive, types) for dirname in dirnames1: dirnames.append(dirname) for filename in filenames1: filenames.append(filename) else: common.log("Scanner.walk", 'path "%s"' % path) dirnames, filenames = self._walk(path, recursive, types) # Make sure everything is a unicode for filename in filenames: files_to_return.append(common.smart_unicode(filename)) for dirname in dirnames: dirs_to_return.append(common.smart_unicode(dirname)) return dirs_to_return, files_to_return
def fetchall(self): rows = [] #return [row for row in self.cursor.fetchall()] for row in self.cursor.fetchall(): cols = [] for col in row: # make sure we return unicode strings!!! if isinstance(col, basestring): col = common.smart_unicode(col) if isinstance(col, datetime.date): if col == '0000-00-00': col = '' col = common.smart_unicode(str(col)) #print col #else: # print type(col) # print col cols.append(col) rows.append(cols) return rows
def onAction(self, action): # Cancel if (action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM): self.close() # Okay if (self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM): self.close() # Select or deselect item in list if (action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST): item = self.getControl(TAGS_LIST).getSelectedItem() #pos = self.getControl( TAGS_LIST ).getSelectedPosition() kb = xbmc.Keyboard( item.getLabel2(), common.getstring(30623) % (common.smart_utf8(item.getLabel())), False) kb.doModal() if (kb.isConfirmed()): item.setLabel2(kb.getText()) self.MPDB.set_tagtype_translation( common.smart_unicode(item.getLabel()), common.smart_unicode(item.getLabel2())) self.getControl(TAGS_LIST).setVisible(False) self.getControl(TAGS_LIST).setVisible(True)
def walk(self, path, recursive=False, types=None): filenames = [] dirnames = [] files_to_return = [] dirs_to_return = [] if type(path).__name__ == "unicode": path = path.encode("utf-8") if path.startswith("multipath://"): common.log("Scanner.walk", 'multipath "%s"' % path) dirs = path[12:-1].split("/") for item in dirs: dirnames1, filenames1 = self._walk(urllib.unquote_plus(item), recursive, types) for dirname in dirnames1: dirnames.append(dirname) for filename in filenames1: filenames.append(filename) else: common.log("Scanner.walk", 'path "%s"' % path) dirnames, filenames = self._walk(path, recursive, types) # Make sure everything is a unicode for filename in filenames: files_to_return.append(common.smart_unicode(filename)) for dirname in dirnames: dirs_to_return.append(common.smart_unicode(dirname)) return dirs_to_return, files_to_return
def is_content_checked(self, tagType, tagContent): key = common.smart_unicode(tagType) + '||' + common.smart_unicode(tagContent) if key in self.active_tags : checked = self.active_tags[ key ] else: self.active_tags[ key ] = 0 checked = 0 return checked
def is_content_checked(self, tagType, tagContent): key = common.smart_unicode(tagType) + '||' + common.smart_unicode( tagContent) if key in self.active_tags: checked = self.active_tags[key] else: self.active_tags[key] = 0 checked = 0 return checked
def encode_header(self, value): """ Encode an HTTP header value. Try first natively in ISO-8859-1, then UTF-8 encoded quoted string. """ try: return smart_unicode(value).encode('iso-8859-1') except UnicodeEncodeError: header = Header(smart_unicode(value), 'utf-8') return header.encode()
def masterlist(): master_start = 0 master_count = 200 master_db = [] master_dict = {} master_check = [] master_menu = simplejson.loads( connection.getURL(SHOWS, header={'X-Requested-With': 'XMLHttpRequest'})) for master_item in master_menu.itervalues(): for master_item in master_item: master_check.append(master_item['title']) while master_start < master_count: master_data = cove.programs.filter(fields='mediafiles', order_by='title', limit_start=master_start) master_menu = master_data['results'] master_count = master_data['count'] master_stop = master_data['stop'] del master_data for master_item2 in master_menu: website = master_item2['website'] if website is None: website = '' if master_item2['title'] in master_check and ( 'PBS Kids' != master_item2['nola_root']) and ('blog' not in website): master_name = common.smart_utf8(master_item2['title']) season_url = re.compile('/cove/v1/programs/(.*?)/').findall( master_item2['resource_uri'])[0] tvdb_name = common.get_show_data( master_name, SITE, 'seasons', common.smart_unicode(master_name) + '#' + season_url)[-1] if season_url: if tvdb_name not in master_dict.keys(): try: master_dict[tvdb_name] = common.smart_unicode( master_name) + '#' + season_url except Exception, e: print "e1", e return e else: try: master_dict[tvdb_name] = master_dict[ tvdb_name] + '|' + common.smart_unicode( master_name) + '#' + season_url except Exception, e: print "error", e return e else: print "No season"
def convert_subtitles(closedcaption): str_output = '' count = 0 for closedcaption_url, i in closedcaption: count = int(i) + 1 if closedcaption_url is not None: try: cc_content = common.smart_unicode( connection.getURL(closedcaption_url, connectiontype=0).replace(' 9137', '')) reader = detect_format(cc_content) if reader: str_output = common.smart_utf8(SRTWriter().write( reader().read(cc_content))) file = open( os.path.join(ustvpaths.DATAPATH, 'subtitle-%s.srt' % str(count)), 'w') file.write(str_output) str_output = '' file.close() else: print "Unknown sub type" except Exception, e: print "Exception with Subs: ", e
def masterlist(): master_start = 0 master_count = 200 master_db = [] master_dict = {} master_check = [] master_menu = simplejson.loads(connection.getURL(SHOWS, header = {'X-Requested-With' : 'XMLHttpRequest'})) for master_item in master_menu.itervalues(): for master_item in master_item: master_check.append(master_item['title']) while master_start < master_count: master_data = cove.programs.filter(fields = 'mediafiles', order_by = 'title', limit_start = master_start) master_menu = master_data['results'] master_count = master_data['count'] master_stop = master_data['stop'] del master_data for master_item2 in master_menu: website = master_item2['website'] if website is None: website = '' if master_item2['title'] in master_check and ('PBS Kids' != master_item2['nola_root']) and ('blog' not in website): master_name = common.smart_utf8(master_item2['title']) tvdb_name = common.get_show_data(master_name, SITE, 'seasons')[-1] season_url = re.compile('/cove/v1/programs/(.*?)/').findall(master_item2['resource_uri'])[0] if tvdb_name not in master_dict.keys(): master_dict[tvdb_name] = common.smart_unicode(master_name) + '#' +season_url else: master_dict[tvdb_name] = master_dict[tvdb_name] + ',' + master_name + '#' + season_url master_start = master_stop for master_name in master_dict: season_url = master_dict[master_name] master_db.append((master_name, SITE, 'seasons', season_url)) return master_db
def request(self, statement, bindvariables=[]): binds = [] return_value = [] try: try: if bindvariables > 0: for value in bindvariables: if type(value).__name__ == 'str': binds.append(common.smart_unicode(value)) #common.log("", "bindVar = %s"%common.smart_unicode(value)) else: binds.append(value) #common.log("", "bindVar = %s"%value) self.execute(statement, binds) try: return_value = self.fetchall() except: pass else: self.execute(statement, binds) try: return_value = self.fetchall() except: pass self.connection.commit() except Exception, msg: try: common.log("Database abstraction layer", "The request failed :", xbmc.LOGERROR) common.log("Database abstraction layer", "%s - %s" % (Exception, str(msg)), xbmc.LOGERROR) except: pass try: common.log("Database abstraction layer", "SQL > %s" % statement, xbmc.LOGERROR) except: pass try: i = 1 for var in binds: common.log( "SQL request numvar = %d content = %s" % (i, var), xbmc.LOGERROR) i = i + 1 except: pass except Exception, msg: try: common.log("Database abstraction layer", "The request failed :", xbmc.LOGERROR) common.log("Database abstraction layer", "%s - %s" % (Exception, msg), xbmc.LOGERROR) except: pass
def getlocalfile(self, filename): filename = common.smart_unicode(filename) # Windows NEEDS unicode but OpenElec utf-8 try: exists = os.path.exists(filename) except: exists = os.path.exists(common.smart_utf8(filename)) if exists: return filename, False else: tempdir = xbmc.translatePath('special://temp').decode('utf-8') basefilename = self.getname(filename) destination = os.path.join(tempdir, basefilename) xbmcvfs.copy(filename, destination) return common.smart_unicode(destination), True
def getlocalfile(self, filename): filename = common.smart_unicode(filename) # Windows NEEDS unicode but OpenElec utf-8 try: exists = os.path.exists(filename) except: exists = os.path.exists(common.smart_utf8(filename)) if exists: return filename, False else: tempdir = xbmc.translatePath("special://temp").decode("utf-8") basefilename = self.getname(filename) destination = os.path.join(tempdir, basefilename) xbmcvfs.copy(filename, destination) return common.smart_unicode(destination), True
def masterlist(): master_db = [] master_data = connection.getURL(SHOWS) master_menu = re.compile('<li class="views-row .*?">.*?<div>\s*<div><a href="(.*?)">.*?<div class="field .*?">\n\s*(.*?)</div>.*?</li>' , re.DOTALL).findall(master_data) for season_url, master_name in master_menu: master_name = common.smart_unicode(master_name).strip() master_name = HTMLParser.HTMLParser().unescape(master_name) master_db.append((master_name, SITE, 'seasons', season_url)) return master_db
def masterlist(): master_db = [] master_data = connection.getURL(SHOWS) json = simplejson.loads(master_data)['menu_html'] master_menu = re.compile('<li class="views-row .*?">.*?<div>\s*<div><a href="(.*?)">.*?<div class="field .*?">\n\s*(.*?)</div>.*?</li>' , re.DOTALL).findall(json) for season_url, master_name in master_menu: master_name = common.smart_unicode(master_name).strip() master_name = HTMLParser.HTMLParser().unescape(master_name) master_db.append((master_name, SITE, 'seasons', season_url)) return master_db
def masterlist(): master_start = 0 master_count = 200 master_db = [] master_dict = {} master_check = [] #master_menu = simplejson.loads(connection.getURL(SHOWS, header = {'X-Requested-With' : 'XMLHttpRequest'})) #for master_item in master_menu.itervalues(): # for master_item in master_item: # master_check.append(master_item['title']) while master_start < master_count: master_data = cove.programs.filter(fields = 'mediafiles', order_by = 'title', limit_start = master_start, limit_end = 500) master_menu = master_data['results'] master_count = master_data['count'] master_stop = master_data['stop'] print master_stop, master_count #del master_data for master_item2 in master_menu: website = master_item2['website'] if website is None: website = '' if ('PBS Kids' != master_item2['nola_root']) and ('blog' not in website): master_name = common.smart_utf8(master_item2['title']) print master_name season_url = re.compile('/cove/v1/programs/(.*?)/').findall(master_item2['resource_uri'])[0] tvdb_name = common.get_show_data(master_name, SITE, 'seasons', common.smart_unicode(master_name) + '#' +season_url)[-1] if season_url: if tvdb_name not in master_dict.keys(): try: master_dict[tvdb_name] = common.smart_unicode(master_name) + '#' +season_url except Exception, e: print "e1", e return e else: try: master_dict[tvdb_name] = master_dict[tvdb_name] + '|' + common.smart_unicode(master_name) + '#' + season_url except Exception, e: print "error",e return e else: print "No season"
def masterlist(SITE, SHOWS): master_db = [] master_data = connection.getURL(SHOWS) master_tree = simplejson.loads(master_data) for master_item in master_tree: if master_item["hasNoVideo"] == "false": # print master_item try: master_name = common.smart_unicode(master_item["detailTitle"]) master_db.append((master_name, SITE, "seasons", urllib.quote_plus(master_item["showID"]))) except Exception, e: print "Exception", e, master_item
def masterlist(SITE, SHOWS): master_db = [] master_data = connection.getURL(SHOWS) master_tree = simplejson.loads(master_data) for master_item in master_tree: if (master_item['hasNoVideo'] == 'false'): #print master_item try: master_name = common.smart_unicode(master_item['detailTitle']) master_db.append((master_name, SITE, 'seasons', urllib.quote_plus(master_item['showID']))) except Exception, e: print "Exception", e, master_item
def request(self, statement, bindvariables = []): binds = [] return_value= [] try: try: if bindvariables > 0: for value in bindvariables: if type(value).__name__ == 'str': binds.append(common.smart_unicode(value)) #common.log("", "bindVar = %s"%common.smart_unicode(value)) else: binds.append(value) #common.log("", "bindVar = %s"%value) self.execute( statement, binds ) try: return_value = self.fetchall() except: pass else: self.execute( statement, binds ) try: return_value = self.fetchall() except: pass self.connection.commit() except Exception,msg: try: common.log("Database abstraction layer", "The request failed :", xbmc.LOGERROR ) common.log("Database abstraction layer", "%s - %s"%(Exception,str(msg)), xbmc.LOGERROR ) except: pass try: common.log("Database abstraction layer", "SQL > %s"%statement, xbmc.LOGERROR) except: pass try: i = 1 for var in binds: common.log ("SQL request numvar = %d content = %s"%(i,var), xbmc.LOGERROR) i=i+1 except: pass except Exception,msg: try: common.log("Database abstraction layer", "The request failed :", xbmc.LOGERROR ) common.log("Database abstraction layer", "%s - %s"%(Exception,msg), xbmc.LOGERROR ) except: pass
def convert_subtitles(closedcaption): str_output = '' count = 0 for closedcaption_url, i in closedcaption: count = int(i) + 1 if closedcaption_url is not None: try: cc_content = common.smart_unicode(connection.getURL(closedcaption_url, connectiontype = 0).replace(' 9137', '')) reader = detect_format(cc_content) if reader: str_output = common.smart_utf8(SRTWriter().write(reader().read(cc_content))) file = open(os.path.join(ustvpaths.DATAPATH, 'subtitle-%s.srt' % str(count)), 'w') file.write(str_output) str_output='' file.close() else: print "Unknown sub type" except Exception, e: print "Exception with Subs: ", e
def fetchall(self): rows = [] #return [row for row in self.cursor.fetchall()] for row in self.cursor.fetchall(): cols = [] for col in row: if isinstance(col, basestring): col = common.smart_unicode(col) #print col #else: # print type(col) # print col cols.append(col) rows.append(cols) return rows
def onAction( self, action ): # Cancel if ( action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM ): self.close() # Okay if ( self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM ): self.close() # Select or deselect item in list if ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST ): item = self.getControl( TAGS_LIST ).getSelectedItem() #pos = self.getControl( TAGS_LIST ).getSelectedPosition() kb = xbmc.Keyboard(item.getLabel2(), common.getstring(30623)%( common.smart_utf8(item.getLabel())), False) kb.doModal() if (kb.isConfirmed()): item.setLabel2(kb.getText()) self.MPDB.set_tagtype_translation(common.smart_unicode(item.getLabel()), common.smart_unicode(item.getLabel2())) self.getControl( TAGS_LIST ).setVisible(False) self.getControl( TAGS_LIST ).setVisible(True)
def __get_xmp_metadata(self, dirname, picfile): #xmptag = 'x:xmpmeta' xmptag = 'rdf:RDF' self.get_xmp_dirname = dirname self.get_xmp_picfile = picfile try: f = open(join(dirname,picfile), 'rb') except: path = join(dirname.encode('utf-8'),picfile.encode('utf-8')) path = common.smart_unicode(path).encode('utf-8') f = open(path, 'rb') content = f.read() f.close() start = content.find("<" + xmptag) end = content.rfind("</" + xmptag) + 4 + len(xmptag) inner = content[start:end] self.get_xmp_inner = inner
def __get_xmp_metadata(self, dirname, picfile): #xmptag = 'x:xmpmeta' xmptag = 'rdf:RDF' self.get_xmp_dirname = dirname self.get_xmp_picfile = picfile try: f = open(join(dirname,picfile), 'rb') except: path = join(dirname.encode('utf-8'),picfile.encode('utf-8')) path = common.smart_unicode(path).encode('utf-8') f = open(path, 'rb') content = f.read() f.close() #print "__get_xmp_metadata" start = content.find("<" + xmptag) end = content.rfind("</" + xmptag) + 4 + len(xmptag) inner = content[start:end] self.get_xmp_inner = inner
def ExportShow(self, show): series_title, mode, sitemode, url, tvdb_id, imdb_id, tvdbbanner, tvdbposter, tvdbfanart, first_aired, date, year, actors, genres, studio, plot, runtime, rating, airs_dayofweek, airs_time, status, has_full_episodes, favor, hide, show_name = show allepisodes = [] has_episodes = False has_movies = False if '--' not in series_title: seasons = common.get_seasons(mode, sitemode, url) for season in seasons: section_title, site, subsitemode, suburl, locked, unlocked = season if 'Clips' not in section_title and ('Episode' in section_title or 'Season' in section_title): episodes = common.get_episodes(mode, subsitemode, suburl) allepisodes.extend(episodes) if allepisodes != []: for episode in allepisodes: try: type = episode[-1] except: print "Type not found.............." try: info = episode[3] except: print "Info not found......................." try: number = info['episode'] except: number = -1 if type == 'Full Episode' and number > -1: has_episodes = True else: episodes = common.get_episodes(mode, sitemode, url) allepisodes = episodes has_movies = True if has_movies: directory = MOVIE_PATH for episode in allepisodes: self.ExportVideo(episode, directory, studio=studio) icon = episode[2] self.Notification(addon.getLocalizedString(39036), addon.getLocalizedString(39037) % episode[1], image=icon) elif has_episodes: directory = os.path.join(TV_SHOWS_PATH, self.cleanfilename(show_name)) self.CreateDirectory(directory) if addon.getSetting('shownfo') == 'true': tvshowDetails = '<tvshow>' tvshowDetails += '<title>' + show_name + '</title>' tvshowDetails += '<showtitle>' + show_name + '</showtitle>' tvshowDetails += '<rating>' + str(rating) + '</rating>' tvshowDetails += '<year>' + str(year) + '</year>' try: plot = common.replace_signs(plot) tvshowDetails += '<plot>' + plot + '</plot>' except: pass try: tvshowDetails += '<runtime>' + runtime + '</runtime>' except: pass try: tvshowDetails += '<thumb>' + tvdbposter + '</thumb>' except: try: tvshowDetails += '<thumb>' + tvdbbanner + '</thumb>' except: pass try: tvshowDetails += '<fanart>' tvshowDetails += '<thumb dim="1920x1080" colors="" preview="' + tvdbfanart + '">' + tvdbposter + '</thumb></fanart>' except: pass try: epguide = common.TVDBURL + ( '/api/%s/series/%s/all/en.zip' % (common.TVDBAPIKEY, TVDB_ID)) tvshowDetails += '<episodeguide>' tvshowDetails += '<url cache="' + TVDB_ID + '.xml">' + epguide + '</url>' tvshowDetails += '</episodeguide>' tvshowDetails += '<id>' + TVDB_ID + '</id>' except: pass try: for genre in genres.split('|'): if genre: tvshowDetails += '<genre>' + genre + '</genre>' except: pass try: tvshowDetails += '<premiered>' + first_aired + '</premiered>' except: pass try: tvshowDetails += '<status>' + status + '</status>' except: pass try: tvshowDetails += '<studio>' + studio + '</studio>' except: pass try: for actor in actors.split('|'): if actor: tvshowDetails += '<actor><name>' + common.smart_unicode( actor) + '</name></actor>' except: pass tvshowDetails += '<dateadded>' + time.strftime( "%Y-%m-%d %H:%M:%S") + '</dateadded>' tvshowDetails += '</tvshow>' self.SaveFile('tvshow.nfo', tvshowDetails, directory) for episode in allepisodes: try: self.ExportVideo(episode, directory, studio=studio) except Exception, e: print "Can't export video", e self.Notification(addon.getLocalizedString(39036), addon.getLocalizedString(39037) % show_name, image=tvdbposter)
def load_map(self): #google geolocalisation static_url = "http://maps.google.com/maps/api/staticmap?" param_dic = { #location parameters (http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html) "center": "", #(required if markers not present) "zoom": self.zoomlevel, # 0 to 21+ (req if no markers #map parameters "size": "640x640", #widthxheight (required) "format": "jpg", #"png8","png","png32","gif","jpg","jpg-baseline" (opt) "maptype": "hybrid", #"roadmap","satellite","hybrid","terrain" (opt) "language": "", #Feature Parameters: "markers": "color:red|label:P|%s", #(opt) #markers=color:red|label:P|lyon|12%20rue%20madiraa|marseille|Lille #&markers=color:blue|label:P|Australie "path": "", #(opt) "visible": "", #(opt) #Reporting Parameters: "sensor": "false" #is there a gps on system ? (req) } param_dic["markers"] = param_dic["markers"] % self.place request_headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10' } request = Request(static_url + urlencode(param_dic), None, request_headers) try: urlfile = urlopen(request) except: dialog = xbmcgui.Dialog() dialog.ok('XBMC Network Error', 'Google maps is not reachable') self.close() return extension = urlfile.info().getheader("Content-Type", "").split("/")[1] filesize = int(urlfile.info().getheader("Content-Length", "")) mappath = xbmc.translatePath(self.datapath) mapfile = join( self.datapath, basename(self.filename).split(".")[0] + "_maps%s." % self.zoomlevel + extension) mapfile = xbmc.translatePath(mapfile) # test existence of path if not os.path.exists(mappath): os.makedirs(mappath) label = self.getControl(LABEL_TEXT) if not isfile(mapfile): #mapfile is not downloaded yet, download it now... try: #f=open(unicode(mapfile, 'utf-8'),"wb") f = open(common.smart_unicode(mapfile), "wb") except: try: f = open(common.smart_utf8(mapfile), "wb") except: print_exc() #print "GEO Exception: "+mapfile for i in range(1 + (filesize / 10)): f.write(urlfile.read(10)) label.setLabel( common.getstring(30221) % (100 * (float(i * 10) / filesize))) #getting map... (%0.2f%%) urlfile.close() #pDialog.close() try: f.close() except: print_exc() self.set_pic(self.filename) self.set_map(mapfile) label.setLabel( common.getstring(30222) % int(100 * (float(self.zoomlevel) / self.zoom_max))) #Zoom level %s
def ExportVideo(self, episode, directory, studio = None): strm, title, episode_thumb, data, qmode, ishd, media_type = episode title = data['title'] if media_type == 'Full Episode': season = data['season'] episode = data['episode'] show_name = data['TVShowTitle'] if season > 0 and episode > -1: filename = self.cleanfilename('S%sE%s - %s' % (season, episode, title)) try: strm = strm + '&name="'+ title +'"' except: pass try: strm = strm + '&thumb="' + urllib.quote_plus(episode_thumb) +'"' except: pass try: strm = strm + '&episode_number="' + str(episode) + '"&season_number="' + str(season) + '"&show_title="' + show_name +'"' except: pass self.SaveFile( filename + '.strm', strm, directory) if addon.getSetting('episodenfo') == 'true': episodeDetails = '<episodedetails>' episodeDetails += '<title>'+title+' '+ addon.getSetting('librarysuffix') +'</title>' try: rating = str(float(data['Rating'])) except: rating = '' episodeDetails += '<rating>' + rating + '</rating>' episodeDetails += '<season>' + str(season) + '</season>' episodeDetails += '<episode>' + str(episode) + '</episode>' try: plot = data['plot'] episodeDetails += '<plot>' + common.smart_unicode(plot) + '</plot>' except: pass try: episodeDetails += '<thumb>' + episode_thumb +'</thumb>' except: pass try: original_premiere = data['premiered'].replace(' 00:00:00','') year = original_premiere.split('-')[0] episodeDetails += '<year>' + year + '</year>' episodeDetails += '<aired>' + original_premiere + '</aired>' episodeDetails += '<premiered>' + original_premiere + '</premiered>' except: pass try: episodeDetails += '<studio>' + studio + '</studio>' except: pass try: episodeDetails += '<mpaa>' + data['mpaa'] + '</mpaa>' except: pass try: for actor in data['cast']: episodeDetails += '<actor><name>' + actor.strip()+'</name></actor>' except: pass try: episodeDetails += '<rating>' + data['Rating'] + '</rating>' except: pass episodeDetails += '</episodedetails>' self.SaveFile( filename+'.nfo', episodeDetails, directory) elif media_type == 'Movie': filename = self.cleanfilename(title) try: filename = filename + ' (%s)' % data['year'] except: pass directory = MOVIE_PATH try: strm = strm + '&name="' + title +'"' except: pass self.SaveFile(filename+'.strm', strm, directory) if addon.getSetting('movienfo') == 'true': movie = '<movie>' movie += '<title>' + title+' '+ addon.getSetting('librarysuffix') + '</title>' try: movie += '<rating>' + data['rating'] + '</rating>' except: pass try: movie += '<plot>' + common.smart_unicode(data['plot']) + '</plot>' except: pass try: movie += '<thumb>' + episode_thumb + '</thumb>' except: pass try: movie += '<year>' + str(data['year']) + '</year>' except: pass try: movie += '<genre>' + data['genre'] + '</genre>' except: pass try: movie += '<director>' + data['director'] + '</director>' except: pass try: movie += '<mpaa>' + data['mpaa'] + '</mpaa>' except: pass try: for actor in data['cast']: movie += '<actor><name>' + actor.strip() + '</name></actor>' except: pass try: durationseconds = data['durationinseconds'] duration = int(durationseconds / 60) movie += '<runtime>' + duration + '</runtime>' except: pass movie += '</movie>' self.SaveFile(filename + '.nfo', movie, directory)
def ExportShow(self, show): series_title, mode, sitemode, url, tvdb_id, imdb_id, tvdbbanner, tvdbposter, tvdbfanart, first_aired, date, year, actors, genres, studio, plot, runtime, rating, airs_dayofweek, airs_time, status, has_full_episodes, favor, hide, show_name = show allepisodes = [] has_episodes = False has_movies = False if '--' not in series_title: directory = os.path.join(TV_SHOWS_PATH, self.cleanfilename(show_name)) try: shutil.rmtree(directory) except: pass seasons = common.get_seasons(mode, sitemode, url) for season in seasons: section_title, site, subsitemode, suburl, locked, unlocked = season if 'Clips' not in section_title and ('Episode' in section_title or 'Season' in section_title): episodes = common.get_episodes(mode, subsitemode, suburl, tvdb_id) allepisodes.extend(episodes) if allepisodes != []: for episode in allepisodes: try: type = episode[-1] except: print "Type not found.............." try: info = episode[3] except: print "Info not found......................." try: number = info['episode'] except: number = -1 if type == 'Full Episode' and number > -1: has_episodes = True else: episodes = common.get_episodes(mode, sitemode, url, tvdb_id) allepisodes = episodes has_movies = True if has_movies: directory = MOVIE_PATH for episode in allepisodes: self.ExportVideo(episode, directory, studio = studio) icon = episode[2] self.Notification(addon.getLocalizedString(39036), addon.getLocalizedString(39037) % episode[1], image = icon) elif has_episodes: self.CreateDirectory(directory) if addon.getSetting('shownfo') == 'true': tvshowDetails = '<tvshow>' tvshowDetails += '<title>'+ show_name + '</title>' tvshowDetails += '<showtitle>' + show_name + '</showtitle>' tvshowDetails += '<rating>' + str(rating) + '</rating>' tvshowDetails += '<year>' + str(year) + '</year>' try: plot = common.replace_signs(plot) tvshowDetails += '<plot>' + plot + '</plot>' except: pass try: tvshowDetails += '<runtime>' + runtime +'</runtime>' except: pass try: tvshowDetails += '<thumb>' + tvdbposter +'</thumb>' except: try: tvshowDetails += '<thumb>' + tvdbbanner +'</thumb>' except: pass try: tvshowDetails += '<fanart>' tvshowDetails += '<thumb dim="1920x1080" colors="" preview="' + tvdbfanart + '">' + tvdbposter + '</thumb></fanart>' except: pass try: epguide = common.TVDBURL + ('/api/%s/series/%s/all/en.zip' % (common.TVDBAPIKEY, TVDB_ID)) tvshowDetails += '<episodeguide>' tvshowDetails += '<url cache="' + TVDB_ID + '.xml">'+ epguide +'</url>' tvshowDetails += '</episodeguide>' tvshowDetails += '<id>' + TVDB_ID +'</id>' except: pass try: for genre in genres.split('|'): if genre: tvshowDetails += '<genre>' + genre + '</genre>' except: pass try: tvshowDetails += '<premiered>' + first_aired + '</premiered>' except: pass try: tvshowDetails += '<status>' + status + '</status>' except: pass try: tvshowDetails += '<studio>' + studio + '</studio>' except: pass try: for actor in actors.split('|'): if actor: tvshowDetails += '<actor><name>' + common.smart_unicode(actor) + '</name></actor>' except: pass tvshowDetails +='<dateadded>' + time.strftime("%Y-%m-%d %H:%M:%S") + '</dateadded>' tvshowDetails +='</tvshow>' self.SaveFile( 'tvshow.nfo', tvshowDetails, directory) for episode in allepisodes: try: self.ExportVideo(episode, directory, studio = studio) except Exception, e: print "Can't export video", e self.Notification(addon.getLocalizedString(39036), addon.getLocalizedString(39037) % show_name, image = tvdbposter)
def getname(self, filename): filename = common.smart_unicode(filename) return os.path.basename(filename)
def load_map(self): #google geolocalisation static_url = "http://maps.google.com/maps/api/staticmap?" param_dic = {#location parameters (http://gmaps-samples.googlecode.com/svn/trunk/geocoder/singlegeocode.html) "center":"", #(required if markers not present) "zoom":self.zoomlevel, # 0 to 21+ (req if no markers #map parameters "size":"640x640", #widthxheight (required) "format":"jpg", #"png8","png","png32","gif","jpg","jpg-baseline" (opt) "maptype":"hybrid", #"roadmap","satellite","hybrid","terrain" (opt) "language":"", #Feature Parameters: "markers" :"color:red|label:P|%s",#(opt) #markers=color:red|label:P|lyon|12%20rue%20madiraa|marseille|Lille #&markers=color:blue|label:P|Australie "path" : "", #(opt) "visible" : "", #(opt) #Reporting Parameters: "sensor" : "false" #is there a gps on system ? (req) } param_dic["markers"]=param_dic["markers"]%self.place request_headers = { 'User-Agent': 'Mozilla/5.0 (Windows; U; Windows NT 6.1; fr; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10' } request = Request(static_url+urlencode(param_dic), None, request_headers) try: urlfile = urlopen(request) except: dialog = xbmcgui.Dialog() dialog.ok('XBMC Network Error', 'Google maps is not reachable') self.close() return extension = urlfile.info().getheader("Content-Type","").split("/")[1] filesize = int(urlfile.info().getheader("Content-Length","")) mappath = xbmc.translatePath(self.datapath) mapfile = join(self.datapath,basename(self.filename).split(".")[0]+"_maps%s."%self.zoomlevel+extension) mapfile = xbmc.translatePath(mapfile) # test existence of path if not os.path.exists(mappath): os.makedirs(mappath) label = self.getControl( LABEL_TEXT ) if not isfile(mapfile): #mapfile is not downloaded yet, download it now... try: #f=open(unicode(mapfile, 'utf-8'),"wb") f=open(common.smart_unicode(mapfile), "wb") except: try: f=open(common.smart_utf8(mapfile), "wb") except: print_exc() #print "GEO Exception: "+mapfile for i in range(1+(filesize/10)): f.write(urlfile.read(10)) label.setLabel(common.getstring(30221)%(100*(float(i*10)/filesize)))#getting map... (%0.2f%%) urlfile.close() #pDialog.close() try: f.close() except: print_exc() self.set_pic(self.filename) self.set_map(mapfile) label.setLabel(common.getstring(30222)%int(100*(float(self.zoomlevel)/self.zoom_max)))#Zoom level %s
def onAction(self, action): # Cancel if (action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM): arraytrue = [] arrayfalse = [] self.filter(arraytrue, arrayfalse, 0, '', '') self.close() # Okay elif (self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM): arraytrue = [] arrayfalse = [] for key, value in self.active_tags.iteritems(): if value == 1: arraytrue.append(key) if value == -1: arrayfalse.append(key) arraytrue.sort() arrayfalse.sort() self.filter(arraytrue, arrayfalse, self.use_and, self.start_date, self.end_date) self.getControl(BUTTON_OK).setEnabled(False) self.getControl(BUTTON_CANCEL).setEnabled(False) self.getControl(BUTTON_MATCHALL).setEnabled(False) self.getControl(LOAD_FILTER).setEnabled(False) self.getControl(SAVE_FILTER).setEnabled(False) self.getControl(CLEAR_FILTER).setEnabled(False) self.getControl(DELETE_FILTER).setEnabled(False) self.getControl(TAGS_LIST).setEnabled(False) self.getControl(TAGS_CONTENT_LIST).setEnabled(False) self.MPDB.filterwizard_save_filter(self.last_used_filter_name, self.active_tags, self.use_and, self.start_date, self.end_date) self.close() # Match all button elif (action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_MATCHALL): if self.use_and == 1: self.use_and = 0 else: self.use_and = 1 # Load filter settings elif (action.getId() in SELECT_ITEM and self.getFocusId() == LOAD_FILTER): self.show_filter_settings() # Save filter settings elif (action.getId() in SELECT_ITEM and self.getFocusId() == SAVE_FILTER): self.save_filter_settings() # Clear filter settings elif (action.getId() in SELECT_ITEM and self.getFocusId() == CLEAR_FILTER): self.clear_settings() # Delete filter settings elif (action.getId() in SELECT_ITEM and self.getFocusId() == DELETE_FILTER): self.delete_filter_settings() # Set start and end date elif (action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_DATE): self.set_filter_date() # Select or deselect item in TagTypes list elif (action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST): item = self.getControl(TAGS_LIST).getSelectedItem() pos = self.getControl(TAGS_LIST).getSelectedPosition() if self.currently_selected_tagtypes != self.tag_types[pos]: self.load_tag_content_list(self.tag_types[pos]) # Select or deselect item in TagContents list elif (action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_CONTENT_LIST): # get selected item item = self.getControl(TAGS_CONTENT_LIST).getSelectedItem() pos = self.getControl(TAGS_CONTENT_LIST).getSelectedPosition() if pos != -1 and item != None: checked = item.getProperty("checked") key = common.smart_unicode(self.currently_selected_tagtypes ) + '||' + common.smart_unicode( item.getLabel2()) if checked == "checkbutton.png": self.check_gui_tag_content(item, -1) self.active_tags[key] = -1 elif checked == "uncheckbutton.png": self.check_gui_tag_content(item, 0) self.active_tags[key] = 0 else: self.check_gui_tag_content(item, 1) self.active_tags[key] = 1 if self.checked_tags == 1: self.getControl(CHECKED_LABEL).setLabel( common.getstring(30611)) else: self.getControl(CHECKED_LABEL).setLabel( common.getstring(30612) % (self.checked_tags)) self.getControl(CHECKED_LABEL).setVisible(False) self.getControl(CHECKED_LABEL).setVisible(True)
def ExportVideo(self, episode, directory, studio=None): strm, title, episode_thumb, data, qmode, ishd, media_type = episode title = data['title'] if media_type == 'Full Episode': season = data['season'] episode = data['episode'] show_name = data['TVShowTitle'] if season > 0 and episode > -1: filename = self.cleanfilename('S%sE%s - %s' % (season, episode, title)) try: strm = strm + '&name="' + title + '"' except: pass try: strm = strm + '&thumb="' + urllib.quote_plus( episode_thumb) + '"' except: pass try: strm = strm + '&episode_number="' + str( episode) + '"&season_number="' + str( season) + '"&show_title="' + show_name + '"' except: pass self.SaveFile(filename + '.strm', strm, directory) if addon.getSetting('episodenfo') == 'true': episodeDetails = '<episodedetails>' episodeDetails += '<title>' + title + ' ' + addon.getSetting( 'librarysuffix') + '</title>' try: rating = str(float(data['Rating'])) except: rating = '' episodeDetails += '<rating>' + rating + '</rating>' episodeDetails += '<season>' + str(season) + '</season>' episodeDetails += '<episode>' + str(episode) + '</episode>' try: plot = data['plot'] episodeDetails += '<plot>' + common.smart_unicode( plot) + '</plot>' except: pass try: episodeDetails += '<thumb>' + episode_thumb + '</thumb>' except: pass try: original_premiere = data['premiered'].replace( ' 00:00:00', '') year = original_premiere.split('-')[0] episodeDetails += '<year>' + year + '</year>' episodeDetails += '<aired>' + original_premiere + '</aired>' episodeDetails += '<premiered>' + original_premiere + '</premiered>' except: pass try: episodeDetails += '<studio>' + studio + '</studio>' except: pass try: episodeDetails += '<mpaa>' + data['mpaa'] + '</mpaa>' except: pass try: for actor in data['cast']: episodeDetails += '<actor><name>' + actor.strip( ) + '</name></actor>' except: pass try: episodeDetails += '<rating>' + data[ 'Rating'] + '</rating>' except: pass episodeDetails += '</episodedetails>' self.SaveFile(filename + '.nfo', episodeDetails, directory) elif media_type == 'Movie': filename = self.cleanfilename(title) try: filename = filename + ' (%s)' % data['year'] except: pass directory = MOVIE_PATH try: strm = strm + '&name="' + title + '"' except: pass self.SaveFile(filename + '.strm', strm, directory) if addon.getSetting('movienfo') == 'true': movie = '<movie>' movie += '<title>' + title + ' ' + addon.getSetting( 'librarysuffix') + '</title>' try: movie += '<rating>' + data['rating'] + '</rating>' except: pass try: movie += '<plot>' + common.smart_unicode( data['plot']) + '</plot>' except: pass try: movie += '<thumb>' + episode_thumb + '</thumb>' except: pass try: movie += '<year>' + str(data['year']) + '</year>' except: pass try: movie += '<genre>' + data['genre'] + '</genre>' except: pass try: movie += '<director>' + data['director'] + '</director>' except: pass try: movie += '<mpaa>' + data['mpaa'] + '</mpaa>' except: pass try: for actor in data['cast']: movie += '<actor><name>' + actor.strip( ) + '</name></actor>' except: pass try: durationseconds = data['durationinseconds'] duration = int(durationseconds / 60) movie += '<runtime>' + duration + '</runtime>' except: pass movie += '</movie>' self.SaveFile(filename + '.nfo', movie, directory)
def onAction( self, action ): # Cancel if ( action.getId() in CANCEL_DIALOG or self.getFocusId() == BUTTON_CANCEL and action.getId() in SELECT_ITEM ): arraytrue = [] arrayfalse = [] self.filter (arraytrue,arrayfalse,False,'','') self.close() # Okay elif ( self.getFocusId() == BUTTON_OK and action.getId() in SELECT_ITEM ): arraytrue = [] arrayfalse = [] for key, value in self.active_tags.iteritems(): if value == 1: arraytrue.append( key) if value == -1: arrayfalse.append( key) arraytrue.sort() arrayfalse.sort() self.filter (arraytrue, arrayfalse, self.use_and, self.start_date, self.end_date ) self.getControl( BUTTON_OK ).setEnabled(False) self.getControl( BUTTON_CANCEL ).setEnabled(False) self.getControl( BUTTON_MATCHALL ).setEnabled(False) self.getControl( LOAD_FILTER ).setEnabled(False) self.getControl( SAVE_FILTER ).setEnabled(False) self.getControl( CLEAR_FILTER ).setEnabled(False) self.getControl( DELETE_FILTER ).setEnabled(False) self.getControl( TAGS_LIST ).setEnabled(False) self.getControl( TAGS_CONTENT_LIST ).setEnabled(False) self.MPDB.filterwizard_save_filter( self.last_used_filter_name, self.active_tags, self.use_and, self.start_date, self.end_date) self.close() # Match all button elif ( action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_MATCHALL ): self.use_and = not self.use_and # Load filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == LOAD_FILTER ): self.show_filter_settings() # Save filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == SAVE_FILTER ): self.save_filter_settings() # Clear filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == CLEAR_FILTER ): self.clear_settings() # Delete filter settings elif ( action.getId() in SELECT_ITEM and self.getFocusId() == DELETE_FILTER ): self.delete_filter_settings() # Set start and end date elif ( action.getId() in SELECT_ITEM and self.getFocusId() == BUTTON_DATE ): self.set_filter_date() # Select or deselect item in TagTypes list elif ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_LIST ): item = self.getControl( TAGS_LIST ).getSelectedItem() pos = self.getControl( TAGS_LIST ).getSelectedPosition() if self.currently_selected_tagtypes != self.tag_types[pos]: self.load_tag_content_list(self.tag_types[pos]) # Select or deselect item in TagContents list elif ( action.getId() in SELECT_ITEM and self.getFocusId() == TAGS_CONTENT_LIST ): # get selected item item = self.getControl( TAGS_CONTENT_LIST ).getSelectedItem() pos = self.getControl( TAGS_CONTENT_LIST ).getSelectedPosition() if pos != -1 and item != None: checked = item.getProperty("checked") key = common.smart_unicode(self.currently_selected_tagtypes) + '||' + common.smart_unicode(item.getLabel2()) if checked == "checkbutton.png": self.check_gui_tag_content(item, -1) self.active_tags[ key ] = -1 elif checked == "uncheckbutton.png": self.check_gui_tag_content(item, 0) self.active_tags[ key ] = 0 else : self.check_gui_tag_content(item, 1) self.active_tags[ key ] = 1 if self.checked_tags == 1: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30611) ) else: self.getControl( CHECKED_LABEL ).setLabel( common.getstring(30612)% (self.checked_tags) ) self.getControl( CHECKED_LABEL ).setVisible(False) self.getControl( CHECKED_LABEL ).setVisible(True)