Exemplo n.º 1
0
def play(url):
    url = url.decode('utf-8', 'ignore')
    resolved = u''
    try:
        import urlresolver
        resolved = urlresolver.HostedMediaFile(url).resolve()
        vitem = ListItem(label=url, path=resolved)
        vitem.is_folder = False
        vitem.set_is_playable = True
        vitem.set_info(type='video', info_labels={'Title': url})
        vitem.add_stream_info(stream_type='video', stream_values={})
        plugin.set_resolved_url(resolved)
        return plugin.play_video(vitem)
    except:
        plugin.notify(
            msg="Failed to resolve {0} to a playable video.".format(url))
    try:
        if resolved is None or len(resolved) < 5:
            import YoutubeDLWrapper
            ytdl = YoutubeDLWrapper._getYTDL()
            ytdl.clearDownloadParams()
            resolved = ytdl.extract_info(url, download=False)
            vitem = ListItem(label=url, path=resolved)
            vitem.is_folder = False
            vitem.set_is_playable = True
            vitem.set_info(type='video', info_labels={'Title': url})
            vitem.add_stream_info(stream_type='video', stream_values={})
            plugin.set_resolved_url(resolved)
            return plugin.play_video(vitem)
    except:
        plugin.notify(
            msg="Failed to resolve {0} to a playable video.".format(url))
    return None
Exemplo n.º 2
0
def play(url):
    url = url.decode('utf-8','ignore')
    resolved = u''
    try:
        import urlresolver
        resolved = urlresolver.HostedMediaFile(url).resolve()
        vitem = ListItem(label=url, path=resolved)
        vitem.is_folder = False
        vitem.set_is_playable = True
        vitem.set_info(type='video', info_labels={'Title': url})
        vitem.add_stream_info(stream_type='video', stream_values={})
        plugin.set_resolved_url(resolved)
        return plugin.play_video(vitem)
    except:
        plugin.notify(msg="Failed to resolve {0} to a playable video.".format(url))
    try:
        if resolved is None or len(resolved) < 5:
            import YoutubeDLWrapper
            ytdl = YoutubeDLWrapper._getYTDL()
            ytdl.clearDownloadParams()
            resolved = ytdl.extract_info(url, download=False)
            vitem = ListItem(label=url, path=resolved)
            vitem.is_folder = False
            vitem.set_is_playable = True
            vitem.set_info(type='video', info_labels={'Title': url})
            vitem.add_stream_info(stream_type='video', stream_values={})
            plugin.set_resolved_url(resolved)
            return plugin.play_video(vitem)
    except:
        plugin.notify(msg="Failed to resolve {0} to a playable video.".format(url))
    return None
Exemplo n.º 3
0
Arquivo: addon.py Projeto: giogris/tvs
def tvitem(adapter, channel):
    titleandtime = channel.nowstarttimeandtitle()

    item = ListItem(label=channel.name,
                    label2=titleandtime,
                    icon=channel.getimagefile(config.tvconfig.channelsdir),
                    thumbnail=channel.getimagefile(config.tvconfig.channelsdir),
                    path=plugin.url_for(str('play_channel'), adapter=adapter, channelid=str(channel.channelid)))

    item.set_is_playable(True)
    item.set_info('video',
                  {
                      'title': channel.name[:15],
                      'tvshowtitle': titleandtime,
                      'duration': channel.v_nowduration,
                      'plot': channel.v_nowdescription,
                      'plotoutline': channel.v_nowdescription,
                      'tagline': channel.nowstarttimeandtitle(),
                      'playcount': 0,
                      #'cast': channel.v_nowactors,
                      'fanart': channel.v_nowfanart,
                      'extrafanart': channel.v_nowposter,
                      'originaltitle': channel.v_nowtitle,
                      'year': channel.v_nowyear,
                      'album': titleandtime,  # I used album 'cause I haven't found another field to display label2
                      'genre': channel.v_nowgenre
                  })
    item.add_context_menu_items(create_context_menu(channel.name, adapter, channel.channelid), replace_items=True)
    item.add_stream_info('video',
                         {'duration': try_parse_int(channel.v_nowduration) * 60, 'plot': channel.v_nowdescription})
    return item
Exemplo n.º 4
0
 def test_stream_info(self):
     with patch.object(xbmcgui.ListItem, 'addStreamInfo') as mock_stream_info:
         item = ListItem()
         item.add_stream_info('video', {'duration': 185})
         mock_stream_info.assert_called_with('video', {'duration': 185})
         item.add_stream_info('audio', {'languange': 'en'})
         mock_stream_info.assert_called_with('audio', {'languange': 'en'})
Exemplo n.º 5
0
 def test_stream_info(self):
     with patch.object(xbmcgui.ListItem,
                       'addStreamInfo') as mock_stream_info:
         item = ListItem()
         item.add_stream_info('video', {'duration': 185})
         mock_stream_info.assert_called_with('video', {'duration': 185})
         item.add_stream_info('audio', {'languange': 'en'})
         mock_stream_info.assert_called_with('audio', {'languange': 'en'})
Exemplo n.º 6
0
def resolveurl():
    url = plugin.keyboard(default='', heading='Video Page URL')
    if url is not None:
        name = url
        if len(url) > 0:
            item = ListItem(label=name, label2=url, icon='DefaultVideo.png', thumbnail='DefaultVideo.png',
                            path=plugin.url_for(endpoint=play, url=url))
            item.set_is_playable(True)
            item.set_info(type='video', info_labels={'Title': url, 'Plot': url})
            item.add_stream_info(stream_type='video', stream_values={})
            playable = play(url)
            plugin.notify(msg=playable.path, title="Playing..")
            plugin.play_video(playable)
    # plugin.redirect(plugin.url_for(index))
    plugin.clear_added_items()
    plugin.end_of_directory()
def title_page(url):
    for i in re.findall('date\[(\d+)\]', url):
        url = url.replace(
            'date[%s]' % i,
            (datetime.datetime.now() -
             datetime.timedelta(days=int(i))).strftime('%Y-%m-%d'))
    global big_list_view
    big_list_view = True
    r = requests.get(url, headers=headers)
    html = r.content
    #html = HTMLParser.HTMLParser().unescape(html)

    lister_items = html.split('<div class="lister-item ')
    items = []
    for lister_item in lister_items:
        if not re.search(r'^mode-advanced">', lister_item):
            continue
        title_type = ''
        trakt_type = ''
        #loadlate="http://ia.media-imdb.com/images/M/MV5BMjIyMTg5MTg4OV5BMl5BanBnXkFtZTgwMzkzMjY5NzE@._V1_UX67_CR0,0,67,98_AL_.jpg"
        img_url = ''
        img_match = re.search(r'<img.*?loadlate="(.*?)"',
                              lister_item,
                              flags=(re.DOTALL | re.MULTILINE))
        if img_match:
            img = img_match.group(1)
            if plugin.get_setting('enhance') == '2':
                img_url = re.sub(r'U[XY].*_.jpg', 'SX344_.jpg',
                                 img)  #NOTE 344 is Confluence List View width
            else:
                if plugin.get_setting('enhance') == '0':
                    img_url = img
                else:
                    img_url = re.sub(r'UX67_CR(.*?),0,67,98',
                                     'UX182_CR\g<1>,0,182,268', img)
                    img_url = re.sub(r'UY98_CR(.*?),0,67,98',
                                     'UY268_CR\g<1>,0,182,268', img_url)

        title = ''
        imdbID = ''
        year = ''
        #<a href="/title/tt1985949/?ref_=adv_li_tt"\n>Angry Birds</a>
        title_match = re.search(
            r'<a href="/title/(tt[0-9]*)/\?ref_=adv_li_tt".>(.*?)</a>',
            lister_item,
            flags=(re.DOTALL | re.MULTILINE))
        if title_match:
            imdbID = title_match.group(1)
            title = title_match.group(2)
            #log((imdbID,title))
        else:
            #log(lister_item)
            pass

        info_type = ''
        #<span class="lister-lister_item-year text-muted unbold">(2016)</span>
        #title_match = re.search(r'<span class="lister-lister_item-year text-muted unbold">.*?\(([0-9]*?)\)<\/span>', lister_item, flags=(re.DOTALL | re.MULTILINE))
        title_match = re.search(
            r'<span class="lister-item-year text-muted unbold">.*?\(([0-9]{4})\)<\/span>',
            lister_item,
            flags=(re.DOTALL | re.MULTILINE))
        if title_match:
            year = title_match.group(1)
            title_type = "movie"
            trakt_type = 'movies'
            info_type = 'extendedinfo'
            #log(year)
        else:
            #log(lister_item)
            #pass

            title_match = re.search(
                r'<span class="lister-item-year text-muted unbold">.*?\(([0-9]{4}).*?\)<\/span>',
                lister_item,
                flags=(re.DOTALL | re.MULTILINE))
            if title_match:
                year = title_match.group(1)
                title_type = "tv_series"
                trakt_type = 'shows'
                info_type = 'extendedtvinfo'
                #log(year)
            else:
                #log(lister_item)
                pass

        #Episode:</small>\n    <a href="/title/tt4480392/?ref_=adv_li_tt"\n>\'Cue Detective</a>\n    <span class="lister-lister_item-year text-muted unbold">(2015)</span>
        #Episode:</small>\n    <a href="/title/tt4952864/?ref_=adv_li_tt"\n>#TeamLucifer</a>\n    <span class="lister-lister_item-year text-muted unbold">(2016)</span
        episode = ''
        episode_id = ''
        episode_match = re.search(
            r'Episode:</small>\n    <a href="/title/(tt.*?)/?ref_=adv_li_tt"\n>(.*?)</a>\n    <span class="lister-lister_item-year text-muted unbold">\((.*?)\)</span>',
            lister_item,
            flags=(re.DOTALL | re.MULTILINE))
        if episode_match:
            episode_id = episode_match.group(1)
            episode = "%s (%s)" % (episode_match.group(2),
                                   episode_match.group(3))
            year = episode_match.group(3)
            title_type = "tv_episode"
            trakt_type = 'episodes'

        #Users rated this 6.1/10 (65,165 votes)
        rating = ''
        votes = ''
        rating_match = re.search(
            r'title="Users rated this (.+?)/10 \((.+?) votes\)',
            lister_item,
            flags=(re.DOTALL | re.MULTILINE))
        if rating_match:
            rating = rating_match.group(1)
            votes = rating_match.group(2)
            votes = re.sub(',', '', votes)

        #<p class="text-muted">\nRusty Griswold takes his own family on a road trip to "Walley World" in order to spice things up with his wife and reconnect with his sons.</p>
        plot = ''
        plot_match = re.search(r'<p class="text-muted">(.+?)</p>',
                               lister_item,
                               flags=(re.DOTALL | re.MULTILINE))
        if plot_match:
            plot = plot_match.group(1).strip()
            plot = re.sub('<a.*?</a>', '', plot)

        #Stars:\n<a href="/name/nm0255124/?ref_=adv_li_st_0"\n>Tom Ellis</a>, \n<a href="/name/nm0314514/?ref_=adv_li_st_1"\n>Lauren German</a>, \n<a href="/name/nm1204760/?ref_=adv_li_st_2"\n>Kevin Alejandro</a>, \n<a href="/name/nm0940851/?ref_=adv_li_st_3"\n>D.B. Woodside</a>\n    </p>
        cast = []
        cast_match = re.search(r'<p class="">(.*?)</p>',
                               lister_item,
                               flags=(re.DOTALL | re.MULTILINE))
        if cast_match:
            cast = cast_match.group(1)
            cast_list = re.findall(r'<a.+?>(.+?)</a>',
                                   cast,
                                   flags=(re.DOTALL | re.MULTILINE))
            cast = cast_list

        #<span class="genre">\nAdventure, Comedy            </span>
        genres = ''
        genre_match = re.search(r'<span class="genre">(.+?)</span>',
                                lister_item,
                                flags=(re.DOTALL | re.MULTILINE))
        if genre_match:
            genres = genre_match.group(1).strip()
            #genre_list = re.findall(r'<a.+?>(.+?)</a>', genre)
            #genres = ",".join(genre_list)

        #class="runtime">99 min</span>
        runtime = ''
        runtime_match = re.search(r'class="runtime">(.+?) min</span>',
                                  lister_item,
                                  flags=(re.DOTALL | re.MULTILINE))
        if runtime_match:
            runtime = int(re.sub(',', '', runtime_match.group(1))) * 60

        sort = ''
        #sort_match = re.search(r'<span class="sort"><span title="(.+?)"', lister_item, flags=(re.DOTALL | re.MULTILINE))
        #if sort_match:
        #    sort = sort_match.group(1)

        #<span class="certificate">PG</span>
        certificate = ''
        certificate_match = re.search(
            r'<span class="certificate">(.*?)</span>',
            lister_item,
            flags=(re.DOTALL | re.MULTILINE))
        if certificate_match:
            certificate = certificate_match.group(1)

        vlabel = title
        playable = True
        if imdbID:
            id = imdbID
            #log(title_type)
            if title_type == "tv_series" or title_type == "mini_series":
                playable = False
                trakt_type = 'shows'
                meta_url = "plugin://plugin.video.imdb.search/meta_tvdb/%s/%s" % (
                    id, urllib.quote_plus(title.encode("utf8")))
                #meta_url = "plugin://%s/tv/search_term/%s/1" % (plugin.get_setting('catchup.plugin').lower(),urllib.quote_plus(title))
            elif title_type == "tv_episode":
                vlabel = "%s - %s" % (title, episode)
                vlabel = urllib.quote_plus(vlabel.encode("utf8"))
                meta_url = "plugin://plugin.video.imdb.search/?action=episode&imdb_id=%s&episode_id=%s&title=%s" % (
                    imdbID, episode_id, vlabel)  #TODO
                id = episode_id
            else:
                imdb_id = imdbID
                xbmcvfs.mkdirs(
                    'special://profile/addon_data/plugin.video.search.and.play/Movies.temp'
                )
                f = xbmcvfs.File(
                    'special://profile/addon_data/plugin.video.search.and.play/Movies.temp/%s.strm'
                    % (imdb_id), "wb")
                movie_library_url = plugin.get_setting('movie.library.url')
                meta_url = plugin.get_setting('movie.library')
                if movie_library_url == "true" and meta_url:
                    meta_url = "plugin://plugin.video.search.and.play/play_movie/%s/%s/%s" % (
                        imdb_id, year, urllib.quote_plus(title))
                else:
                    meta_url = 'plugin://%s/movies/play/imdb/%s/library' % (
                        plugin.get_setting('catchup.plugin').lower(), imdb_id)
                f.write(meta_url.encode("utf8"))
                f.close()
                #f = xbmcvfs.File('special://profile/addon_data/plugin.video.imdb.search/Movies.temp/%s.nfo' % (imdb_id), "wb")
                #str = "http://www.imdb.com/title/%s/" % imdb_id
                #f.write(str.encode("utf8"))
                #f.close()
                meta_url = 'special://profile/addon_data/plugin.video.search.and.play/Movies.temp/%s.strm' % (
                    imdb_id)
            #log(meta_url)
        if imdbID:
            item = ListItem(label=title, thumbnail=img_url, path=meta_url)
            item.set_is_playable(playable)
            item.set_info(
                'video', {
                    'title': vlabel,
                    'genre': genres,
                    'code': imdbID,
                    'year': year,
                    'mediatype': 'movie',
                    'rating': rating,
                    'plot': plot,
                    'mpaa': certificate,
                    'cast': cast,
                    'duration': runtime,
                    'votes': votes
                })
            video_streaminfo = {'codec': 'h264'}
            video_streaminfo['aspect'] = round(1280.0 / 720.0, 2)
            video_streaminfo['width'] = 1280
            video_streaminfo['height'] = 720
            item.add_stream_info('video', video_streaminfo)
            item.add_stream_info('audio', {
                'codec': 'aac',
                'language': 'en',
                'channels': 2
            })
            context_items = []
            '''
            context_items.append(('Information', 'XBMC.Action(Info)'))
            try:
                if info_type and xbmcaddon.Addon('script.extendedinfo'):
                    context_items.append(('Extended Info', "XBMC.RunScript(script.extendedinfo,info=%s,imdb_id=%s)" % (info_type,imdbID)))
            except:
                pass
            #context_items.append(('Add to Trakt Watchlist', 'XBMC.RunPlugin(%s)' % (plugin.url_for('add_to_trakt_watchlist', type=trakt_type, imdb_id=imdbID, title=title))))
            try:
                if title_type == 'movie' and xbmcaddon.Addon('plugin.video.couchpotato_manager'):
                    context_items.append(('Add to Couch Potato', "XBMC.RunPlugin(plugin://plugin.video.couchpotato_manager/movies/add-by-id/%s)" % imdbID))
            except:
                pass
            if title_type == "tv_series" or title_type == "mini_series":
                try:
                    if xbmcaddon.Addon('plugin.video.sickrage'):
                        context_items.append(('Add to Sickrage', "XBMC.RunPlugin(plugin://plugin.video.sickrage?action=addshow&&show_name=%s)" % title))
                except:
                    context_items.append(('Add to Sickrage', 'XBMC.RunPlugin(%s)' % (plugin.url_for('sickrage_addshow', title=title))))

            item.add_context_menu_items(context_items)
            '''
            items.append(item)

    #href="?count=50&sort=moviemeter,asc&production_status=released&languages=en&release_date=2015,2016&boxoffice_gross_us=6.0,10.0&start=1&num_votes=100,&title_type=feature&page=2&ref_=adv_nxt"
    pagination_match = re.findall('<a href="([^"]*?&ref_=adv_nxt)"',
                                  html,
                                  flags=(re.DOTALL | re.MULTILINE))
    if pagination_match:
        next_page = 'http://www.imdb.com/search/title?' + pagination_match[
            -1].strip('?')
        #log(next_page)
        items.append({
            'label': "Next Page >>",
            'path': plugin.url_for('title_page', url=next_page),
            'thumbnail': get_icon_path('nextpage'),
        })

    return items