def get_images(self, override=False): # Read google images from json file self.images = [] if kodiutils.get_setting_as_int( "screensaver-mode") == 0 or kodiutils.get_setting_as_int( "screensaver-mode") == 2 or override: with open(IMAGE_FILE, "r") as f: images = f.read() self.images = json.loads(images) # Check if we have images to append if kodiutils.get_setting_as_int( "screensaver-mode") == 1 or kodiutils.get_setting_as_int( "screensaver-mode") == 2 and not override: if kodiutils.get_setting("my-pictures-folder") and xbmcvfs.exists( xbmc.translatePath( kodiutils.get_setting("my-pictures-folder"))): for image in screensaverutils.get_own_pictures( kodiutils.get_setting("my-pictures-folder")): self.images.append(image) else: return self.get_images(override=True) shuffle(self.images) return
def set_property(self): if "estuary" in xbmc.getSkinDir(): self.setProperty("clockfont", "fontclock") else: self.setProperty("clockfont", "fontmainmenu") # Set skin properties as settings for setting in [ "hide-clock-info", "hide-kodi-logo", "hide-weather-info", "hide-pic-info" ]: self.setProperty(setting, kodiutils.get_setting(setting)) # Set animations if kodiutils.get_setting_as_int("animation") == 1: self.setProperty("animation", "panzoom") return
def onInit(self): self.exit_monitor = self.ExitMonitor(self.exit) self.backgroud = self.getControl(32500) self.metadata_line2 = self.getControl(32503) self.metadata_line3 = self.getControl(32504) # Grab images self.get_images() # Start Image display loop if self.images: while not self.exit_monitor.abortRequested(): rand_index = randint(0, len(self.images) - 1) # if it is a google image.... if "private" not in self.images[rand_index]: if requests.head(url=self.images[rand_index] ["url"]).status_code != 200: continue # photo metadata if "location" in self.images[rand_index].keys( ) and "photographer" in self.images[rand_index].keys(): self.metadata_line2.setLabel( self.images[rand_index]["location"]) self.metadata_line3.setLabel( "%s %s" % (kodiutils.get_string(32001), screensaverutils.remove_unknown_author( self.images[rand_index]["photographer"]))) elif "location" in self.images[rand_index].keys( ) and "photographer" not in self.images[rand_index].keys(): self.metadata_line2.setLabel( self.images[rand_index]["location"]) self.metadata_line3.setLabel("") elif "location" not in self.images[rand_index].keys( ) and "photographer" in self.images[rand_index].keys(): self.metadata_line2.setLabel( "%s %s" % (kodiutils.get_string(32001), screensaverutils.remove_unknown_author( self.images[rand_index]["photographer"]))) self.metadata_line3.setLabel("") else: self.metadata_line2.setLabel("") self.metadata_line3.setLabel("") else: # Logic for user owned photos - custom information if "line1" in self.images[rand_index]: self.metadata_line2.setLabel( self.images[rand_index]["line1"]) else: self.metadata_line2.setLabel("") if "line2" in self.images[rand_index]: self.metadata_line3.setLabel( self.images[rand_index]["line2"]) else: self.metadata_line2.setLabel("") # Insert photo self.backgroud.setImage(self.images[rand_index]["url"]) # Pop image and wait del self.images[rand_index] self.exit_monitor.waitForAbort( kodiutils.get_setting_as_int( "wait-time-before-changing-image")) # Check if images dict is empty, if so read the file again self.get_images()
def get_videos(name,playlist_id,token="",page_num=1): items_per_page = kodiutils.get_setting_as_int("items_per_page") url_api = 'https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet,contentDetails&maxResults=%s&playlistId=%s&key=%s' \ % (str(items_per_page), playlist_id, YOUTUBE_API_KEY) if page_num != 1: url_api += "&pageToken=%s" % (token) try: resp = requests.get(url_api).json() except ValueError: kodiutils.log(kodiutils.get_string(32004), xbmc.LOGERROR) resp = None if resp: nextpagetoken = resp["nextPageToken"] if "nextPageToken" in resp.keys() else "" availablevideos = resp["pageInfo"]["totalResults"] if "pageInfo" in resp.keys() and "totalResults" in resp["pageInfo"].keys() else 1 returnedVideos = resp["items"] totalpages = int(math.ceil((float(availablevideos) / items_per_page))) video_ids = [] if returnedVideos: for video in returnedVideos: videoid = video["contentDetails"]["videoId"] video_ids.append(videoid) video_ids = ','.join(video_ids) url_api = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s' % (video_ids,YOUTUBE_API_KEY) try: resp = requests.get(url_api).json() except ValueError: kodiutils.log(kodiutils.get_string(32005), xbmc.LOGERROR) resp = None if resp: returnedVideos = resp["items"] for video in returnedVideos: title = video["snippet"]["title"] plot = video["snippet"]["description"] aired = video["snippet"]["publishedAt"] thumb = video["snippet"]["thumbnails"]["high"]["url"] videoid = video["id"] # process duration duration_string = video["contentDetails"]["duration"] duration = addonutils.return_duration_as_seconds(duration_string) try: aired = re.compile('(.+?)-(.+?)-(.+?)T').findall(aired)[0] date = aired[2] + '.' + aired[1] + '.' + aired[0] aired = aired[0] + '-' + aired[1] + '-' + aired[2] except IndexError: aired = '' date = '' infolabels = {'plot': plot.encode('utf-8'), 'aired': aired, 'date': date, 'tvshowtitle': TVSHOWTITLE, 'title': title.encode('utf-8'), 'originaltitle': title.encode('utf-8'), 'status': STATUS, 'cast': CAST, 'duration': duration} # Video and audio info video_info = {'codec': 'avc1', 'aspect': 1.78} audio_info = {'codec': 'aac', 'language': 'en'} if video["contentDetails"]["definition"].lower() == 'hd': video_info['width'] = 1280 video_info['height'] = 720 audio_info['channels'] = 2 else: video_info['width'] = 854 video_info['height'] = 480 audio_info['channels'] = 1 if xbmcaddon.Addon(id='plugin.video.youtube').getSetting('kodion.video.quality.ask') == 'false' and xbmcaddon.Addon( id='plugin.video.youtube').getSetting('kodion.video.quality') != '3' and xbmcaddon.Addon( id='plugin.video.youtube').getSetting('kodion.video.quality') != '4': video_info['width'] = 854 video_info['height'] = 480 audio_info['channels'] = 1 yield build_video_item(title.encode('utf-8'), thumb, videoid, infolabels, video_info, audio_info) if totalpages > 1 and (page_num + 1) <= totalpages: nextpage = ListItem("[B]%s[/B] (%s/%s)" % (kodiutils.get_string(32008), str(page_num), str(totalpages))) nextpage.setProperty("type", "next") nextpage.setProperty("page", str(page_num+1)) nextpage.setProperty("token", str(nextpagetoken)) nextpage.setInfo(type="video",infoLabels={"plot": kodiutils.get_string(32002)}) yield nextpage
def get_videos(name, playlist_id, token="", page_num=1): items_per_page = kodiutils.get_setting_as_int("items_per_page") url_api = 'https://www.googleapis.com/youtube/v3/playlistItems?part=id,snippet,contentDetails&maxResults=%s&playlistId=%s&key=%s' \ % (str(items_per_page), playlist_id, YOUTUBE_API_KEY) if page_num != 1: url_api += "&pageToken=%s" % (token) try: resp = requests.get(url_api).json() except ValueError: kodiutils.log(kodiutils.get_string(32004), xbmc.LOGERROR) resp = None if resp: nextpagetoken = resp["nextPageToken"] if "nextPageToken" in resp.keys( ) else "" availablevideos = resp["pageInfo"][ "totalResults"] if "pageInfo" in resp.keys( ) and "totalResults" in resp["pageInfo"].keys() else 1 returnedVideos = resp["items"] totalpages = int(math.ceil((float(availablevideos) / items_per_page))) video_ids = [] if returnedVideos: for video in returnedVideos: videoid = video["contentDetails"]["videoId"] video_ids.append(videoid) video_ids = ','.join(video_ids) url_api = 'https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails&id=%s&key=%s' % ( video_ids, YOUTUBE_API_KEY) try: resp = requests.get(url_api).json() except ValueError: kodiutils.log(kodiutils.get_string(32005), xbmc.LOGERROR) resp = None if resp: returnedVideos = resp["items"] for video in returnedVideos: title = video["snippet"]["title"] plot = video["snippet"]["description"] aired = video["snippet"]["publishedAt"] thumb = video["snippet"]["thumbnails"]["high"]["url"] videoid = video["id"] # process duration duration_string = video["contentDetails"]["duration"] duration = addonutils.return_duration_as_seconds( duration_string) try: aired = re.compile('(.+?)-(.+?)-(.+?)T').findall( aired)[0] date = aired[2] + '.' + aired[1] + '.' + aired[0] aired = aired[0] + '-' + aired[1] + '-' + aired[2] except IndexError: aired = '' date = '' infolabels = { 'plot': plot.encode('utf-8'), 'aired': aired, 'date': date, 'tvshowtitle': TVSHOWTITLE, 'title': title.encode('utf-8'), 'originaltitle': title.encode('utf-8'), 'status': STATUS, 'cast': CAST, 'duration': duration } # Video and audio info video_info = {'codec': 'avc1', 'aspect': 1.78} audio_info = {'codec': 'aac', 'language': 'en'} if video["contentDetails"]["definition"].lower() == 'hd': video_info['width'] = 1280 video_info['height'] = 720 audio_info['channels'] = 2 else: video_info['width'] = 854 video_info['height'] = 480 audio_info['channels'] = 1 if xbmcaddon.Addon(id='plugin.video.youtube').getSetting( 'kodion.video.quality.ask' ) == 'false' and xbmcaddon.Addon( id='plugin.video.youtube').getSetting( 'kodion.video.quality' ) != '3' and xbmcaddon.Addon( id='plugin.video.youtube').getSetting( 'kodion.video.quality') != '4': video_info['width'] = 854 video_info['height'] = 480 audio_info['channels'] = 1 yield build_video_item(title.encode('utf-8'), thumb, videoid, infolabels, video_info, audio_info) if totalpages > 1 and (page_num + 1) <= totalpages: nextpage = ListItem( "[B]%s[/B] (%s/%s)" % (kodiutils.get_string(32008), str(page_num), str(totalpages))) nextpage.setProperty("type", "next") nextpage.setProperty("page", str(page_num + 1)) nextpage.setProperty("token", str(nextpagetoken)) nextpage.setInfo(type="video", infoLabels={"plot": kodiutils.get_string(32002)}) yield nextpage
def build_episode_item(episode, show_fanart=None): #create episode listitem episode_title = episode["name"] if episode["name"] else "None" liz = ListItem(episode["name"]) #infolabels infolabels = { "title": episode["name"] } if "summary" in episode.keys(): infolabels["plot"] = episode["summary"] if "number" in episode.keys() and episode["number"].isdigit(): infolabels["episode"] = int(episode["number"]) if "published" in episode.keys(): try: infolabels["aired"] = episode['published'].rsplit('T')[0] infolabels["date"] = episode['published'].rsplit('T')[0].replace("-",".") infolabels["year"] = int(episode['published'].rsplit('T')[0].split("-")[0]) except: xbmc.log(msg='[Revision3] could not get date information', level=xbmc.LOGERROR) if "show" in episode.keys() and "name" in episode["show"].keys(): infolabels["tvshowtitle"] = episode["show"]["name"] if "duration" in episode.keys() and episode["duration"].isdigit(): infolabels["duration"] = int(episode["duration"]) #Art art = {} if "images" in episode.keys(): if "medium" in episode["images"].keys(): art["thumb"] = episode["images"]["medium"] art["icon"] = episode["images"]["medium"] art["poster"] = episode["images"]["medium"] if show_fanart: art["fanart"] = urllib.unquote(show_fanart) liz.setInfo( type="Video", infoLabels=infolabels) liz.setArt(art) #Videos url = "" if "media" in episode.keys(): media_urls = [] video_info = {} if "hd720p30" in episode["media"].keys(): media_urls.append(episode["media"]["hd720p30"]["url"]) if "large" in episode["media"].keys(): media_urls.append(episode["media"]["large"]["url"]) if "small" in episode["media"].keys(): media_urls.append(episode["media"]["small"]["url"]) #Parse user preference if len(media_urls) > 0: if kodiutils.get_setting_as_int("format") == 0: url = media_urls[0]; video_info['width'] = 1280; video_info['height'] = 720 if kodiutils.get_setting_as_int("format") == 1: url = media_urls[1] if len(media_urls) > 1 else media_urls[-1]; video_info['width'] = 854; video_info['height'] = 480 if kodiutils.get_setting_as_int("format") == 2: url = media_urls[-1]; video_info['width'] = 854; video_info['height'] = 480 #context menu items cm = [] cm.append((kodiutils.get_string(32063), 'XBMC.Action(Info)')) if url: if kodiutils.get_setting_as_bool("download") and kodiutils.get_setting("downloadPath") and xbmcvfs.exists(kodiutils.get_setting("downloadPath")): cm.append((kodiutils.get_string(32062), 'XBMC.RunPlugin(plugin://%s/download/%s/%s)' % (ADDON.getAddonInfo("id"),urllib.quote(episode_title, safe=''),urllib.quote(url, safe='')) )) liz.setPath("plugin://%s/play/%s" % (ADDON.getAddonInfo("id"),urllib.quote(url, safe='')) ) liz.setProperty('IsPlayable', 'true') liz.addStreamInfo('video', video_info) liz.addContextMenuItems(cm, replaceItems=False) return liz else: return None