Ejemplo n.º 1
0
def handle_events(results):
    events = ItemList()
    for event in results:
        venue = event['venue']
        item = VideoItem(label=venue['name'])
        item.set_properties({
            'date':
            event['datetime'].replace("T", " - ").replace(":00", "", 1),
            'city':
            venue['city'],
            'lat':
            venue['latitude'],
            'lon':
            venue['longitude'],
            'id':
            venue['id'],
            'url':
            venue['url'],
            'region':
            venue['region'],
            'country':
            venue['country'],
            'artists':
            " / ".join([art for art in event["artists"]])
        })
        events.append(item)
    return events
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
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
Ejemplo n.º 4
0
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
Ejemplo n.º 5
0
 def __init__(self, *args, **kwargs):
     super(DialogBaseInfo, self).__init__(*args, **kwargs)
     self.logged_in = tmdb.Login.check_login()
     self.bouncing = False
     self.last_focus = None
     self.lists = None
     self.states = False
     self.yt_listitems = []
     self.info = VideoItem()
     self.last_control = None
     self.last_position = None
Ejemplo n.º 6
0
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
Ejemplo n.º 7
0
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
Ejemplo n.º 8
0
def handle_playlists(results):
    """
    process playlist api result to ItemList
    """
    playlists = ItemList(content_type="videos")
    for item in results:
        snippet = item["snippet"]
        thumb = snippet["thumbnails"]["high"][
            "url"] if "thumbnails" in snippet else ""
        try:
            playlist_id = item["id"]["playlistId"]
        except Exception:
            playlist_id = snippet["resourceId"]["playlistId"]
        playlist = VideoItem(label=snippet["title"],
                             path=PLUGIN_BASE +
                             'youtubeplaylist&&id=%s' % playlist_id)
        playlist.set_infos({
            'plot': snippet["description"],
            "mediatype": "video",
            'premiered': snippet["publishedAt"][:10]
        })
        playlist.set_art("thumb", thumb)
        playlist.set_properties({
            'youtube_id':
            playlist_id,
            'channel_title':
            snippet["channelTitle"],
            'type':
            "playlist",
            'live':
            snippet["liveBroadcastContent"].replace("none", "")
        })
        playlists.append(playlist)
    params = {
        "id": ",".join([i.get_property("youtube_id") for i in playlists]),
        "part": "contentDetails"
    }
    ext_results = get_data(method="playlists", params=params)
    for item, ext_item in itertools.product(playlists, ext_results["items"]):
        if item.get_property("youtube_id") == ext_item['id']:
            item.set_property("itemcount",
                              ext_item['contentDetails']['itemCount'])
    return playlists
Ejemplo n.º 9
0
 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
Ejemplo n.º 10
0
def handle_channels(results):
    """
    process channel api result to ItemList
    """
    channels = ItemList(content_type="videos")
    for item in results:
        snippet = item["snippet"]
        thumb = snippet["thumbnails"]["high"][
            "url"] if "thumbnails" in snippet else ""
        try:
            channel_id = item["id"]["channelId"]
        except Exception:
            channel_id = snippet["resourceId"]["channelId"]
        channel = VideoItem(label=snippet["title"],
                            path=PLUGIN_BASE +
                            'youtubechannel&&id=%s' % channel_id)
        channel.set_infos({
            'plot': snippet["description"],
            'mediatype': "video",
            'premiered': snippet["publishedAt"][:10]
        })
        channel.set_art("thumb", thumb)
        channel.set_properties({"youtube_id": channel_id, "type": "channel"})
        channels.append(channel)
    channel_ids = [item.get_property("youtube_id") for item in channels]
    params = {
        "id": ",".join(channel_ids),
        "part": "contentDetails,statistics,brandingSettings"
    }
    ext_results = get_data(method="channels", params=params)
    for item, ext_item in itertools.product(channels, ext_results["items"]):
        if item.get_property("youtube_id") == ext_item['id']:
            item.set_property("itemcount",
                              ext_item['statistics']['videoCount'])
            item.set_art(
                "fanart", ext_item["brandingSettings"]["image"].get(
                    "bannerTvMediumImageUrl"))
    return channels
Ejemplo n.º 11
0
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