def handle_events(self, results): places = ItemList() if not isinstance(results, list): results = [results] for venue in results: venuename = venue['venue_name'] lat = venue['latitude'] lon = venue['longitude'] googlemap = googlemaps.get_static_map(lat=lat, lon=lon) photo = venue["image"]["large"]["url"] if venue.get("image") else "" if venue["start_time"] == venue["stop_time"] or not venue["stop_time"]: date = venue["start_time"] elif venue["start_time"][:10] == venue["stop_time"][:10]: date = venue["start_time"] + " - " + venue["stop_time"][:10] date = re.sub(r"\d{2}:\d{2}:\d{2}", "", date) else: date = venue["start_time"] + " - " + venue["stop_time"] date = re.sub(r"\d{2}:\d{2}:\d{2}", "", date) item = VideoItem(label=venuename, label2=date.replace("00:00:00", "")) item.set_properties({"id": str(venue['id']), "eventful_id": str(venue['venue_id']), "eventname": venue['title'], "description": venue['description'], "name": venuename, "date": date, "address": venue["venue_address"], "lat": lat, "lon": lon}) item.set_artwork({"thumb": photo, "googlemap": googlemap}) places.append(item) return places
def get_movies(movie_type): movies = ItemList(content_type="movies") url = '%s.json?apikey=%s' % (movie_type, RT_KEY) results = utils.get_JSON_response(BASE_URL + url, folder="RottenTomatoes") if "error" in results: utils.notify("Error", results["error"]) if not results or "movies" not in results: return [] for item in results["movies"]: if "alternate_ids" not in item: continue imdb_id = str(item["alternate_ids"]["imdb"]) if addon.bool_setting("infodialog_onclick"): path = PLUGIN_BASE + 'extendedinfo&&imdb_id=%s' % imdb_id else: search_string = "%s %s trailer" % (item["title"], item["year"]) path = PLUGIN_BASE + "playtrailer&&title=%s&&imdb_id=%s" % (search_string, imdb_id) movie = VideoItem(label=item.get('title'), path=path) movie.set_infos({'title': item["title"], 'mediatype': "movie", 'duration': item["runtime"] * 60, 'year': item["year"], 'premiered': item["release_dates"].get("theater", ""), 'rating': item["ratings"]["audience_score"] / 10.0, 'plot': item["synopsis"], 'imdbnumber': imdb_id, 'mpaa': item["mpaa_rating"]}) movie.set_properties({'imdb_id': imdb_id}) movie.set_artwork({'thumb': item["posters"]["original"], 'poster': item["posters"]["original"]}) movies.append(movie) return local_db.merge_with_local(media_type="movie", items=movies, library_first=False)
def handle_tvshow(self, tvshow): """ convert tvshow data to listitems """ if addon.setting("infodialog_onclick") != "false": path = PLUGIN_BASE + 'extendedtvinfo&&dbid=%s' % tvshow['tvshowid'] else: path = PLUGIN_BASE + 'action&&id=ActivateWindow(videos,videodb://tvshows/titles/%s/,return)' % tvshow['tvshowid'] db_tvshow = VideoItem(label=tvshow.get("label"), path=path) db_tvshow.set_infos({'title': tvshow.get('label'), 'dbid': tvshow['tvshowid'], 'genre': " / ".join(tvshow.get('genre')), 'rating': round(float(tvshow['rating']), 1), 'mediatype': "tvshow", 'mpaa': tvshow.get("mpaa"), 'plot': tvshow.get("plot"), 'votes': tvshow.get("votes"), 'studio': " / ".join(tvshow.get('studio')), 'premiered': tvshow.get("premiered"), 'playcount': tvshow.get("playcount"), 'imdbnumber': tvshow.get("imdbnumber"), 'userrating': tvshow.get("userrating"), 'duration': tvshow.get("duration"), # "tag": " / ".join(movie['tag']), 'year': tvshow.get('year'), 'originaltitle': tvshow.get('originaltitle')}) db_tvshow.set_properties({'imdb_id': tvshow.get('imdbnumber'), 'file': tvshow.get('file'), 'watchedepisodes': tvshow.get('watchedepisodes'), 'totalepisodes': tvshow.get('episode')}) db_tvshow.set_artwork(tvshow['art']) db_tvshow.set_cast(tvshow.get("cast")) return db_tvshow
def get_locations(self, lat, lon, radius, locationtype): params = {"key": GOOGLE_PLACES_KEY, "radius": min(30000, radius), "location": "%s,%s" % (lat, lon), "types": locationtype} base_url = BASE_URL + 'nearbysearch/json?' results = Utils.get_JSON_response(base_url + urllib.urlencode(params)) places = ItemList() if "meta" in results and results['meta']['code'] == 400: utils.log("LIMIT EXCEEDED") return "", [] if "results" not in results: return "", [] for place in results['results']: try: params = {"maxwidth": 400, "photoreference": place['photos'][0]['photo_reference'], "key": GOOGLE_PLACES_KEY} photo = BASE_URL + 'photo?' + urllib.urlencode(params) except: photo = "" description = place['vicinity'] if "vicinity" in place else place.get('formatted_address', "") item = VideoItem(label=place['name'], label2=" / ".join(place['types'])) item.set_artwork({"thumb": photo, "icon": place['icon']}) item.set_info("rating", place['rating'] * 2.0 if "rating" in place else "") item.set_properties({'description': description, "lat": place['geometry']['location']['lat'], "lon": place['geometry']['location']['lng']}) places.append(item) return places
def handle_movie(self, movie): """ convert movie data to listitems """ trailer = PLUGIN_BASE + "playtrailer&&dbid=%s" % movie['movieid'] if addon.setting("infodialog_onclick") != "false": path = PLUGIN_BASE + 'extendedinfo&&dbid=%s' % movie['movieid'] else: path = PLUGIN_BASE + 'playmovie&&dbid=%i' % movie['movieid'] resume = movie['resume'] if (resume['position'] and resume['total']) > 0: resumable = "true" played = int( (float(resume['position']) / float(resume['total'])) * 100) else: resumable = "false" played = 0 db_movie = VideoItem(label=movie.get('label'), path=path) db_movie.set_infos({ 'title': movie.get('label'), 'dbid': movie['movieid'], 'file': movie.get('file'), 'year': movie.get('year'), 'writer': " / ".join(movie['writer']), 'mediatype': "movie", 'set': movie.get("set"), 'playcount': movie.get("playcount"), 'setid': movie.get("setid"), 'top250': movie.get("top250"), 'imdbnumber': movie.get("imdbnumber"), 'userrating': movie.get('userrating'), 'trailer': trailer, 'rating': round(float(movie['rating']), 1), 'director': " / ".join(movie.get('director')), 'writer': " / ".join(movie.get('writer')), # "tag": " / ".join(movie['tag']), "genre": " / ".join(movie['genre']), 'plot': movie.get('plot'), 'plotoutline': movie.get('plotoutline'), 'studio': " / ".join(movie.get('studio')), 'mpaa': movie.get('mpaa'), 'originaltitle': movie.get('originaltitle') }) db_movie.set_properties({ 'imdb_id': movie.get('imdbnumber'), 'showlink': " / ".join(movie['showlink']), 'percentplayed': played, 'resume': resumable }) db_movie.set_artwork(movie['art']) db_movie.set_videoinfos(movie['streamdetails']["video"]) db_movie.set_audioinfos(movie['streamdetails']["audio"]) stream_info = media_streamdetails( movie['file'].encode('utf-8').lower(), movie['streamdetails']) db_movie.update_properties(stream_info) db_movie.set_cast(movie.get("cast")) return db_movie
def handle_videos(results, extended=False): """ process vidoe api result to ItemList """ videos = ItemList(content_type="videos") for item in results: snippet = item["snippet"] thumb = snippet["thumbnails"]["high"]["url"] if "thumbnails" in snippet else "" try: video_id = item["id"]["videoId"] except Exception: video_id = snippet["resourceId"]["videoId"] video = VideoItem(label=snippet["title"], path=PLUGIN_BASE + 'youtubevideo&&id=%s' % video_id) video.set_infos({'plot': snippet["description"], 'mediatype': "video", 'premiered': snippet["publishedAt"][:10]}) video.set_artwork({'thumb': thumb}) video.set_playable(True) video.set_properties({'channel_title': snippet["channelTitle"], 'channel_id': snippet["channelId"], 'type': "video", 'youtube_id': video_id}) videos.append(video) if not extended: return videos params = {"part": "contentDetails,statistics", "id": ",".join([i.get_property("youtube_id") for i in videos])} ext_results = get_data(method="videos", params=params) if not ext_results: return videos for item in videos: for ext_item in ext_results["items"]: if not item.get_property("youtube_id") == ext_item['id']: continue details = ext_item['contentDetails'] stats = ext_item['statistics'] likes = stats.get('likeCount') dislikes = stats.get('dislikeCount') item.update_infos({"duration": get_duration_in_seconds(details['duration'])}) props = {"duration": details['duration'][2:].lower(), "formatted_duration": get_formatted_duration(details['duration']), "dimension": details['dimension'], "definition": details['definition'], "caption": details['caption'], "viewcount": utils.millify(stats['viewCount']), "likes": likes, "dislikes": dislikes} item.update_properties(props) if likes and dislikes: vote_count = int(likes) + int(dislikes) if vote_count > 0: item.set_info("rating", round(float(likes) / vote_count * 10, 1)) break return videos
def get_episodes(content): shows = ItemList(content_type="episodes") url = "" if content == "shows": url = 'calendars/shows/%s/14' % datetime.date.today() elif content == "premieres": url = 'calendars/shows/premieres/%s/14' % datetime.date.today() results = get_data(url=url, params={"extended": "full,images"}, cache_days=0.3) count = 1 if not results: return None for day in results.iteritems(): for episode in day[1]: ep = episode["episode"] tv = episode["show"] title = ep["title"] if ep["title"] else "" label = u"{0} - {1}x{2}. {3}".format(tv["title"], ep["season"], ep["number"], title) show = VideoItem(label=label, path=PLUGIN_BASE + 'extendedtvinfo&&tvdb_id=%s' % tv["ids"]["tvdb"]) show.set_infos({'title': title, 'aired': ep["first_aired"], 'season': ep["season"], 'episode': ep["number"], 'tvshowtitle': tv["title"], 'mediatype': "episode", 'year': tv.get("year"), 'duration': tv["runtime"] * 60, 'studio': tv["network"], 'plot': tv["overview"], 'country': tv["country"], 'status': tv["status"], 'trailer': tv["trailer"], 'imdbnumber': ep["ids"]["imdb"], 'rating': tv["rating"], 'genre': " / ".join(tv["genres"]), 'mpaa': tv["certification"]}) show.set_properties({'tvdb_id': ep["ids"]["tvdb"], 'id': ep["ids"]["tvdb"], 'imdb_id': ep["ids"]["imdb"], 'homepage': tv["homepage"]}) show.set_artwork({'thumb': ep["images"]["screenshot"]["thumb"], 'poster': tv["images"]["poster"]["full"], 'banner': tv["images"]["banner"]["full"], 'clearart': tv["images"]["clearart"]["full"], 'clearlogo': tv["images"]["logo"]["full"], 'fanart': tv["images"]["fanart"]["full"]}) shows.append(show) count += 1 if count > 20: break return shows
def handle_movies(results): movies = ItemList(content_type="movies") path = 'extendedinfo&&id=%s' if addon.bool_setting( "infodialog_onclick") else "playtrailer&&id=%s" for i in results: item = i["movie"] if "movie" in i else i trailer = "%syoutubevideo&&id=%s" % ( PLUGIN_BASE, utils.extract_youtube_id(item["trailer"])) movie = VideoItem(label=item["title"], path=PLUGIN_BASE + path % item["ids"]["tmdb"]) movie.set_infos({ 'title': item["title"], 'duration': item["runtime"] * 60 if item["runtime"] else "", 'tagline': item["tagline"], 'mediatype': "movie", 'trailer': trailer, 'year': item["year"], 'mpaa': item["certification"], 'plot': item["overview"], 'imdbnumber': item["ids"]["imdb"], 'premiered': item["released"], 'rating': round(item["rating"], 1), 'votes': item["votes"], 'genre': " / ".join(item["genres"]) }) movie.set_properties({ 'id': item["ids"]["tmdb"], 'imdb_id': item["ids"]["imdb"], 'trakt_id': item["ids"]["trakt"], 'watchers': item.get("watchers"), 'language': item.get("language"), 'homepage': item.get("homepage") }) art_info = tmdb.get_movie(item["ids"]["tmdb"], light=True) movie.set_artwork( tmdb.get_image_urls(poster=art_info.get("poster_path"), fanart=art_info.get("backdrop_path"))) movies.append(movie) movies = local_db.merge_with_local(media_type="movie", items=movies, library_first=False) movies.set_sorts(["mpaa", "duration"]) return movies
def get_episodes(content): shows = ItemList(content_type="episodes") url = "" if content == "shows": url = 'calendars/shows/%s/14' % datetime.date.today() elif content == "premieres": url = 'calendars/shows/premieres/%s/14' % datetime.date.today() results = get_data(url=url, params={"extended": "full"}, cache_days=0.3) count = 1 if not results: return None for day in results.iteritems(): for episode in day[1]: ep = episode["episode"] tv = episode["show"] title = ep["title"] if ep["title"] else "" label = u"{0} - {1}x{2}. {3}".format(tv["title"], ep["season"], ep["number"], title) show = VideoItem(label=label, path=PLUGIN_BASE + 'extendedtvinfo&&tvdb_id=%s' % tv["ids"]["tvdb"]) show.set_infos({'title': title, 'aired': ep["first_aired"], 'season': ep["season"], 'episode': ep["number"], 'tvshowtitle': tv["title"], 'mediatype': "episode", 'year': tv.get("year"), 'duration': tv["runtime"] * 60 if tv["runtime"] else "", 'studio': tv["network"], 'plot': tv["overview"], 'country': tv["country"], 'status': tv["status"], 'trailer': tv["trailer"], 'imdbnumber': ep["ids"]["imdb"], 'rating': tv["rating"], 'genre': " / ".join(tv["genres"]), 'mpaa': tv["certification"]}) show.set_properties({'tvdb_id': ep["ids"]["tvdb"], 'id': ep["ids"]["tvdb"], 'imdb_id': ep["ids"]["imdb"], 'homepage': tv["homepage"]}) if tv["ids"].get("tmdb"): art_info = tmdb.get_tvshow(tv["ids"]["tmdb"], light=True) show.set_artwork(tmdb.get_image_urls(poster=art_info.get("poster_path"), fanart=art_info.get("backdrop_path"))) shows.append(show) count += 1 if count > 20: break return shows
def handle_movie(self, movie): """ convert movie data to listitems """ trailer = PLUGIN_BASE + "playtrailer&&dbid=%s" % movie['movieid'] if addon.setting("infodialog_onclick") != "false": path = PLUGIN_BASE + 'extendedinfo&&dbid=%s' % movie['movieid'] else: path = PLUGIN_BASE + 'playmovie&&dbid=%i' % movie['movieid'] resume = movie['resume'] if (resume['position'] and resume['total']) > 0: resumable = "true" played = int((float(resume['position']) / float(resume['total'])) * 100) else: resumable = "false" played = 0 db_movie = VideoItem(label=movie.get('label'), path=path) db_movie.set_infos({'title': movie.get('label'), 'dbid': movie['movieid'], 'file': movie.get('file'), 'year': movie.get('year'), 'writer': " / ".join(movie['writer']), 'mediatype': "movie", 'set': movie.get("set"), 'playcount': movie.get("playcount"), 'setid': movie.get("setid"), 'top250': movie.get("top250"), 'imdbnumber': movie.get("imdbnumber"), 'userrating': movie.get('userrating'), 'trailer': trailer, 'rating': round(float(movie['rating']), 1), 'director': " / ".join(movie.get('director')), 'writer': " / ".join(movie.get('writer')), # "tag": " / ".join(movie['tag']), "genre": " / ".join(movie['genre']), 'plot': movie.get('plot'), 'plotoutline': movie.get('plotoutline'), 'studio': " / ".join(movie.get('studio')), 'mpaa': movie.get('mpaa'), 'originaltitle': movie.get('originaltitle')}) db_movie.set_properties({'imdb_id': movie.get('imdbnumber'), 'showlink': " / ".join(movie['showlink']), 'percentplayed': played, 'resume': resumable}) db_movie.set_artwork(movie['art']) db_movie.set_videoinfos(movie['streamdetails']["video"]) db_movie.set_audioinfos(movie['streamdetails']["audio"]) stream_info = media_streamdetails(movie['file'].encode('utf-8').lower(), movie['streamdetails']) db_movie.update_properties(stream_info) db_movie.set_cast(movie.get("cast")) return db_movie
def handle_tvshows(results): shows = ItemList(content_type="tvshows") for i in results: item = i["show"] if "show" in i else i airs = item.get("airs", {}) show = VideoItem(label=item["title"], path='%sextendedtvinfo&&tvdb_id=%s' % (PLUGIN_BASE, item['ids']["tvdb"])) show.set_infos({ 'mediatype': "tvshow", 'title': item["title"], 'duration': item["runtime"] * 60, 'year': item["year"], 'premiered': item["first_aired"][:10], 'country': item["country"], 'rating': round(item["rating"], 1), 'votes': item["votes"], 'imdbnumber': item['ids']["imdb"], 'mpaa': item["certification"], 'trailer': item["trailer"], 'status': item.get("status"), 'studio': item["network"], 'genre': " / ".join(item["genres"]), 'plot': item["overview"] }) show.set_properties({ 'id': item['ids']["tmdb"], 'tvdb_id': item['ids']["tvdb"], 'imdb_id': item['ids']["imdb"], 'trakt_id': item['ids']["trakt"], 'language': item["language"], 'aired_episodes': item["aired_episodes"], 'homepage': item["homepage"], 'airday': airs.get("day"), 'airshorttime': airs.get("time"), 'watchers': item.get("watchers") }) show.set_artwork({ 'poster': item["images"]["poster"]["full"], 'banner': item["images"]["banner"]["full"], 'clearart': item["images"]["clearart"]["full"], 'clearlogo': item["images"]["logo"]["full"], 'fanart': item["images"]["fanart"]["full"], 'thumb': item["images"]["poster"]["thumb"] }) shows.append(show) shows = local_db.merge_with_local(media_type="tvshow", items=shows, library_first=False) shows.set_sorts(["mpaa", "duration"]) return shows
def handle_musicvideos(results): mvids = ItemList(content_type="musicvideos") if not results.get('mvids'): return mvids for item in results['mvids']: youtube_id = utils.extract_youtube_id(item.get('strMusicVid', '')) mvid = VideoItem(label=item['strTrack'], path="%syoutubevideo&&id=%s" % (PLUGIN_BASE, youtube_id)) mvid.set_infos({'title': item['strTrack'], 'plot': item['strDescriptionEN'], 'mediatype': "musicvideo"}) mvid.set_properties({'id': item['idTrack']}) mvid.set_artwork({'thumb': "http://i.ytimg.com/vi/%s/0.jpg" % youtube_id}) mvids.append(mvid) return mvids
def handle_tvshows(results): shows = ItemList(content_type="tvshows") for i in results: item = i["show"] if "show" in i else i airs = item.get("airs", {}) show = VideoItem(label=item["title"], path='%sextendedtvinfo&&tvdb_id=%s' % (PLUGIN_BASE, item['ids']["tvdb"])) show.set_infos({'mediatype': "tvshow", 'title': item["title"], 'duration': item["runtime"] * 60, 'year': item["year"], 'premiered': item["first_aired"][:10], 'country': item["country"], 'rating': round(item["rating"], 1), 'votes': item["votes"], 'imdbnumber': item['ids']["imdb"], 'mpaa': item["certification"], 'trailer': item["trailer"], 'status': item.get("status"), 'studio': item["network"], 'genre': " / ".join(item["genres"]), 'plot': item["overview"]}) show.set_properties({'id': item['ids']["tmdb"], 'tvdb_id': item['ids']["tvdb"], 'imdb_id': item['ids']["imdb"], 'trakt_id': item['ids']["trakt"], 'language': item["language"], 'aired_episodes': item["aired_episodes"], 'homepage': item["homepage"], 'airday': airs.get("day"), 'airshorttime': airs.get("time"), 'watchers': item.get("watchers")}) show.set_artwork({'poster': item["images"]["poster"]["full"], 'banner': item["images"]["banner"]["full"], 'clearart': item["images"]["clearart"]["full"], 'clearlogo': item["images"]["logo"]["full"], 'fanart': item["images"]["fanart"]["full"], 'thumb': item["images"]["poster"]["thumb"]}) shows.append(show) shows = local_db.merge_with_local(media_type="tvshow", items=shows, library_first=False) shows.set_sorts(["mpaa", "duration"]) return shows
def handle_tvshow(self, tvshow): """ convert tvshow data to listitems """ if addon.setting("infodialog_onclick") != "false": path = PLUGIN_BASE + 'extendedtvinfo&&dbid=%s' % tvshow['tvshowid'] else: path = PLUGIN_BASE + 'action&&id=ActivateWindow(videos,videodb://tvshows/titles/%s/,return)' % tvshow[ 'tvshowid'] db_tvshow = VideoItem(label=tvshow.get("label"), path=path) db_tvshow.set_infos({ 'title': tvshow.get('label'), 'dbid': tvshow['tvshowid'], 'genre': " / ".join(tvshow.get('genre')), 'rating': round(float(tvshow['rating']), 1), 'mediatype': "tvshow", 'mpaa': tvshow.get("mpaa"), 'plot': tvshow.get("plot"), 'votes': tvshow.get("votes"), 'studio': " / ".join(tvshow.get('studio')), 'premiered': tvshow.get("premiered"), 'playcount': tvshow.get("playcount"), 'imdbnumber': tvshow.get("imdbnumber"), 'userrating': tvshow.get("userrating"), 'duration': tvshow.get("duration"), # "tag": " / ".join(movie['tag']), 'year': tvshow.get('year'), 'originaltitle': tvshow.get('originaltitle') }) db_tvshow.set_properties({ 'imdb_id': tvshow.get('imdbnumber'), 'file': tvshow.get('file'), 'watchedepisodes': tvshow.get('watchedepisodes'), 'totalepisodes': tvshow.get('episode') }) db_tvshow.set_artwork(tvshow['art']) db_tvshow.set_cast(tvshow.get("cast")) return db_tvshow
def get_incidents(lat, lon, zoom): lat_high, lon_high, lat_low, lon_low = Utils.get_bounding_box(lat, lon, zoom) params = {"key": MAPQUEST_KEY, "inFormat": "kvp", "boundingBox": "%s,%s,%s,%s" % (lat_high, lon_high, lat_low, lon_low)} url = BASE_URL + 'incidents?' + urllib.urlencode(params) results = Utils.get_JSON_response(url) places = ItemList() if results['info']['statuscode'] == 400: utils.notify("Error", " - ".join(results['info']['messages']), time=10000) return [] elif "incidents" not in results: utils.notify("Error", "Could not fetch results") return [] for place in results['incidents'][:MAX_LIMIT]: lat = str(place['lat']) lon = str(place['lng']) params = {"key": MAPQUEST_KEY, "mapLat": place['lat'], "mapLng": place['lng'], "mapHeight": 400, "mapWidth": 400, "mapScale": 433342} url = BASE_URL + "flow?" + urllib.urlencode(params) item = VideoItem(label=place['shortDesc'], label2=place['startTime']) item.set_properties({'name': place['shortDesc'], 'description': place['fullDesc'], 'distance': str(place['distance']), 'delaytypical': str(place['delayFromTypical']), 'delayfreeflow': str(place['delayFromFreeFlow']), 'date': place['startTime'], 'severity': str(place['severity']), 'type': incident_types.get(place['type'], ""), "lat": lat, "lon": lon}) item.set_artwork({"thumb": url, "icon": place['iconURL'], "googlemap": googlemaps.get_static_map(lat=lat, lon=lon)}) places.append(item) return places
def handle_movies(results): movies = ItemList(content_type="movies") path = 'extendedinfo&&id=%s' if addon.bool_setting("infodialog_onclick") else "playtrailer&&id=%s" for i in results: item = i["movie"] if "movie" in i else i trailer = "%syoutubevideo&&id=%s" % (PLUGIN_BASE, utils.extract_youtube_id(item["trailer"])) movie = VideoItem(label=item["title"], path=PLUGIN_BASE + path % item["ids"]["tmdb"]) movie.set_infos({'title': item["title"], 'duration': item["runtime"] * 60, 'tagline': item["tagline"], 'mediatype': "movie", 'trailer': trailer, 'year': item["year"], 'mpaa': item["certification"], 'plot': item["overview"], 'imdbnumber': item["ids"]["imdb"], 'premiered': item["released"], 'rating': round(item["rating"], 1), 'votes': item["votes"], 'genre': " / ".join(item["genres"])}) movie.set_properties({'id': item["ids"]["tmdb"], 'imdb_id': item["ids"]["imdb"], 'trakt_id': item["ids"]["trakt"], 'watchers': item.get("watchers"), 'language': item.get("language"), 'homepage': item.get("homepage")}) movie.set_artwork({'poster': item["images"]["poster"]["full"], 'fanart': item["images"]["fanart"]["full"], 'clearlogo': item["images"]["logo"]["full"], 'clearart': item["images"]["clearart"]["full"], 'banner': item["images"]["banner"]["full"], 'thumb': item["images"]["poster"]["thumb"]}) movies.append(movie) movies = local_db.merge_with_local(media_type="movie", items=movies, library_first=False) movies.set_sorts(["mpaa", "duration"]) return movies
def handle_places(self, results): places = ItemList() for venue in results: try: photo = venue['venue']['photos']['groups'][0]['items'][0] photo = "%s%s%s" % (photo['prefix'], photo['height'], photo['suffix']) except: photo = "" if "name" not in venue: venue = venue["venue"] if venue['categories']: icon = venue['categories'][0]['icon'] icon = "%s88%s" % (icon['prefix'], icon['suffix']) else: icon = "" if 'formattedAddress' in venue['location']: formattedAddress = "[CR]".join(filter(None, venue['location']['formattedAddress'])) lat = venue['location']['lat'] lon = venue['location']['lng'] item = VideoItem(label=venue['name'], label2=venue['name']) item.set_properties({"id": venue['id'], "foursquare_id": venue['id'], "distance": venue['location']['distance'], "visited": venue['stats']['usersCount'], "twitter": venue['contact'].get('twitter', ""), "eventname": venue['location']['address'], "description": formattedAddress, "name": venue['name'], "lat": lat, "lon": lon, "phone": venue['contact'].get('phone', ""), "comments": venue['stats']['tipCount']}) item.set_artwork({"thumb": photo, "icon": icon, "googlemap": googlemaps.get_static_map(lat=lat, lon=lon)}) places.append(item) return places
def handle_videos(results, extended=False): """ process vidoe api result to ItemList """ videos = ItemList(content_type="videos") for item in results: snippet = item["snippet"] thumb = snippet["thumbnails"]["high"][ "url"] if "thumbnails" in snippet else "" try: video_id = item["id"]["videoId"] except Exception: video_id = snippet["resourceId"]["videoId"] video = VideoItem(label=snippet["title"], path=PLUGIN_BASE + 'youtubevideo&&id=%s' % video_id) video.set_infos({ 'plot': snippet["description"], 'mediatype': "video", 'premiered': snippet["publishedAt"][:10] }) video.set_artwork({'thumb': thumb}) video.set_playable(True) video.set_properties({ 'channel_title': snippet["channelTitle"], 'channel_id': snippet["channelId"], 'type': "video", 'youtube_id': video_id }) videos.append(video) if not extended: return videos params = { "part": "contentDetails,statistics", "id": ",".join([i.get_property("youtube_id") for i in videos]) } ext_results = get_data(method="videos", params=params) if not ext_results: return videos for item in videos: for ext_item in ext_results["items"]: if not item.get_property("youtube_id") == ext_item['id']: continue details = ext_item['contentDetails'] stats = ext_item.get('statistics') likes = stats.get('likeCount') if stats else None dislikes = stats.get('dislikeCount') if stats else None item.update_infos( {"duration": get_duration_in_seconds(details['duration'])}) props = { "duration": details['duration'][2:].lower(), "formatted_duration": get_formatted_duration(details['duration']), "dimension": details['dimension'], "definition": details['definition'], "caption": details['caption'], "viewcount": utils.millify(stats['viewCount']), "likes": likes, "dislikes": dislikes } item.update_properties(props) if likes and dislikes: vote_count = int(likes) + int(dislikes) if vote_count > 0: item.set_info("rating", round(float(likes) / vote_count * 10, 1)) break return videos