Пример #1
0
    def new_session(self):
        self.logged_in = True if userdata.get('_cookies') else False
        if not settings.getBool('save_password', False):
            userdata.delete(PASSWORD_KEY)

        if self.logged_in and settings.getBool(
                'save_password', True) and not userdata.get(PASSWORD_KEY):
            self.logout()
            gui.ok(_.SAVE_PASSWORD_RELOGIN)
Пример #2
0
def install():
    remove_file(SO_DST)
    shutil.copy(SO_SRC, SO_DST)

    if SYSTEM == 'libreelec':
        install_libreelec()
    elif SYSTEM == 'raspbian':
        install_raspbian()
    elif SYSTEM == 'osmc':
        install_osmc()
        return True
    elif SYSTEM == 'xbian':
        install_xbian()
        return True
    elif SYSTEM == 'mock':
        gui.ok(_.SYSTEM_UNSUPPORTED)
Пример #3
0
def search(**kwargs):
    query = gui.input(_.SEARCH, default=userdata.get('search', '')).strip()
    if not query:
        return

    userdata.set('search', query)

    folder = plugin.Folder(_(_.SEARCH_FOR, query=query))

    for row in api.search(query):
        if row['type'] == 'show':
            item = _process_show(row)
        elif row['type'] == 'category':
            slug = row['page']['href'].split('/')[-1]
            if slug == 'shows':
                slug = 'all'

            item = plugin.Item(
                label=row['title'],
                info={'plot': row['searchDescription'] or row['synopsis']},
                art={'thumb': row['tileImage']['src'] + '?width=400'},
                path=plugin.url_for(category, slug=slug),
            )
        elif row['type'] == 'channel':
            item = plugin.Item(
                label=row['title'],
                info={'plot': row['searchDescription'] or row['synopsis']},
                art={'thumb': row['tileImage']['src'] + '?width=400'},
                path=plugin.url_for(play,
                                    channel=row['page']['href'].split('/')[-1],
                                    _is_live=True),
                playable=True,
            )
        else:
            continue

        folder.add_items(item)

    if not folder.items:
        return gui.ok(_.NO_RESULTS, heading=folder.title)

    return folder
Пример #4
0
def _setup():
    addon = get_addon(IPTV_SIMPLE_ID, required=True, install=True)

    with gui.progress(_.SETTING_UP_IPTV) as progress:
        kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': False})

        output_dir = settings.get('output_dir', '').strip() or ADDON_PROFILE
        playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME)
        epg_path = os.path.join(output_dir, EPG_FILE_NAME)

        ## IMPORT ANY CURRENT URL SOURCES ##
        cur_epg_url  = addon.getSetting('epgUrl')
        cur_epg_type = addon.getSetting('epgPathType')
        if cur_epg_url:
            epg = EPG(source_type=EPG.TYPE_URL, path=cur_epg_url, enabled=cur_epg_type == '1')
            try: epg.save()
            except: pass

        cur_m3u_url  = addon.getSetting('m3uUrl')
        cur_m3u_type = addon.getSetting('m3uPathType')
        start_chno = int(addon.getSetting('startNum') or 1)
        #user_agent = addon.getSetting('userAgent')
        if cur_m3u_url:
            playlist = Playlist(source_type=Playlist.TYPE_URL, path=cur_m3u_url, enabled=cur_m3u_type == '1')
            if start_chno != 1:
                playlist.use_start_chno = True
                playlist.start_chno = start_chno

            try: playlist.save()
            except: pass
        ################################

        addon.setSetting('epgPath', epg_path)
        addon.setSetting('m3uPath', playlist_path)
        addon.setSetting('epgUrl', '')
        addon.setSetting('m3uUrl', '')
        addon.setSetting('m3uPathType', '0')
        addon.setSetting('epgPathType', '0')

        monitor = xbmc.Monitor()

        progress.update(30)

        monitor.waitForAbort(2)
        kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': True})

        progress.update(60)

        monitor.waitForAbort(2)

        progress.update(100)

        set_kodi_setting('epg.futuredaystodisplay', 7)
      #  set_kodi_setting('epg.ignoredbforclient', True)
        set_kodi_setting('pvrmanager.syncchannelgroups', True)
        set_kodi_setting('pvrmanager.preselectplayingchannel', True)
        set_kodi_setting('pvrmanager.backendchannelorder', True)
        set_kodi_setting('pvrmanager.usebackendchannelnumbers', True)

    set_kodi_string('_iptv_merge_force_run', '1')

    gui.ok(_.SETUP_IPTV_COMPLETE)

    return True
Пример #5
0
def show_score(slug, **kwargs):
    game = get_game(slug)
    gui.ok(heading=game.title, message=game.result)
Пример #6
0
def play(asset_id, **kwargs):
    use_ia_hls = settings.getBool('use_ia_hls')
    stream_data = api.get_stream_data(asset_id)
    token = userdata.get('access_token')

    play_item = plugin.Item(
        art=False,
        headers={'Authorization': 'Bearer {}'.format(token)},
        cookies={
            'access_token': token,
            'client_id': CLIENT_ID
        },
    )

    is_drm = stream_data.get('course_is_drmed', False)

    hls_url = stream_data.get('hls_url')
    if hls_url and not is_drm:
        play_item.path = hls_url
        play_item.inputstream = inputstream.HLS(live=False)
        return play_item

    stream_urls = stream_data.get('stream_urls') or {}
    streams = stream_urls.get('Video') or stream_urls.get('Audio') or []

    CODECS = {
        'libx264': 'H.264',
        'libx265': 'H.265',
    }

    urls = []
    qualities = []
    for item in streams:
        if item['type'] != 'application/x-mpegURL':
            data = stream_data['data']['outputs'][item['label']]

            if data.get('migrated_from_non_labeled_conversions'):
                bandwidth, resolution = BANDWIDTH_MAP.get(int(item['label']))
                codecs, fps = '', ''
            else:
                fps = _(_.QUALITY_FPS, fps=float(data['frame_rate']))
                resolution = '{}x{}'.format(data['width'], data['height'])
                bandwidth = data[
                    'video_bitrate_in_kbps'] * 1000  #(or total_bitrate_in_kbps)
                codecs = CODECS.get(data.get('video_codec'), '')

            urls.append([bandwidth, item['file']])
            qualities.append([
                bandwidth,
                _(_.QUALITY_BITRATE,
                  bandwidth=float(bandwidth) / 1000000,
                  resolution=resolution,
                  fps=fps,
                  codecs=codecs)
            ])

    if not urls:
        for row in stream_data.get('media_sources') or []:
            if row['type'] == 'application/x-mpegURL' and 'encrypted-files' not in row[
                    'src']:
                urls.append([row['src'], inputstream.HLS(live=False)])

            if row['type'] == 'application/dash+xml':
                play_item.path = row['src']

                if is_drm:
                    token = stream_data['media_license_token']
                    ia = inputstream.Widevine(license_key=WV_URL.format(
                        token=token))
                else:
                    ia = inputstream.MPD()

                urls.append([row['src'], ia])

        if urls:
            urls = sorted(urls,
                          key=lambda x: isinstance(x[1], inputstream.Widevine))
            play_item.path = urls[0][0]
            play_item.inputstream = urls[0][1]
            if isinstance(play_item.inputstream, inputstream.Widevine):
                system, arch = get_system_arch()
                if system == 'Windows' or (system == 'Linux'
                                           and arch == 'armv7'):
                    gui.ok(_.VMP_WARNING)

            return play_item

    if not urls:
        raise plugin.Error(_.NO_STREAM_ERROR)

    quality = kwargs.get(QUALITY_TAG)
    if quality is None:
        quality = settings.getEnum('default_quality',
                                   QUALITY_TYPES,
                                   default=QUALITY_ASK)
    else:
        quality = int(quality)

    urls = sorted(urls, key=lambda s: s[0], reverse=True)
    qualities = sorted(qualities, key=lambda s: s[0], reverse=True)

    if quality == QUALITY_CUSTOM:
        quality = int(settings.getFloat('max_bandwidth') * 1000000)
    elif quality == QUALITY_ASK:
        quality = select_quality(qualities)

    if quality == QUALITY_BEST:
        quality = qualities[0][0]
    elif quality == QUALITY_LOWEST:
        quality = qualities[-1][0]

    play_item.path = urls[-1][1]
    for item in urls:
        if item[0] <= quality:
            play_item.path = item[1]
            break

    return play_item
Пример #7
0
def _setup():
    addon = get_addon(IPTV_SIMPLE_ID, required=True, install=True)

    with gui.progress(_.SETTING_UP_IPTV) as progress:
        kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': False})

        output_dir    = xbmc.translatePath(settings.get('output_dir', '').strip() or ADDON_PROFILE)
        playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME)
        epg_path      = os.path.join(output_dir, EPG_FILE_NAME)

        if not os.path.exists(playlist_path):
            with open(playlist_path, 'w') as f:
                f.write('''#EXTM3U
#EXTINF:-1 tvg-id="iptv_merge" tvg-chno="1000" tvg-logo="{}",{}
{}'''.format(ADDON_ICON, 'IPTV Merge: Click me to run a merge!', plugin.url_for(merge)))

        if not os.path.exists(epg_path):
            with open(epg_path, 'w') as f:
                f.write('''<?xml version="1.0" encoding="utf-8" ?><tv><channel id="iptv_merge"></channel></tv>''')

        ## IMPORT ANY CURRENT SOURCES ##
        cur_epg_url  = addon.getSetting('epgUrl')
        cur_epg_path = addon.getSetting('epgPath')
        cur_epg_type = addon.getSetting('epgPathType')

        if cur_epg_path != epg_path and os.path.exists(xbmc.translatePath(cur_epg_path)):
            epg = EPG(source_type=EPG.TYPE_FILE, path=cur_epg_path, enabled=cur_epg_type == '0')
            epg.auto_archive_type()
            try: epg.save()
            except: pass

        if cur_epg_url:
            epg = EPG(source_type=EPG.TYPE_URL, path=cur_epg_url, enabled=cur_epg_type == '1')
            epg.auto_archive_type()
            try: epg.save()
            except: pass

        cur_m3u_url  = addon.getSetting('m3uUrl')
        cur_m3u_path = addon.getSetting('m3uPath')
        cur_m3u_type = addon.getSetting('m3uPathType')
        start_chno   = int(addon.getSetting('startNum') or 1)
        #user_agent   = addon.getSetting('userAgent')

        if cur_m3u_path != playlist_path and os.path.exists(xbmc.translatePath(cur_m3u_path)):
            playlist = Playlist(source_type=Playlist.TYPE_FILE, path=cur_m3u_path, enabled=cur_m3u_type == '0')
            playlist.auto_archive_type()
            if start_chno != 1:
                playlist.use_start_chno = True
                playlist.start_chno = start_chno

            try: playlist.save()
            except: pass

        if cur_m3u_url:
            playlist = Playlist(source_type=Playlist.TYPE_URL, path=cur_m3u_url, enabled=cur_m3u_type == '1')
            playlist.auto_archive_type()
            if start_chno != 1:
                playlist.use_start_chno = True
                playlist.start_chno = start_chno

            try: playlist.save()
            except: pass
        #####

        addon.setSetting('epgPath', epg_path)
        addon.setSetting('m3uPath', playlist_path)
        addon.setSetting('epgUrl', '')
        addon.setSetting('m3uUrl', '')
        addon.setSetting('m3uPathType', '0')
        addon.setSetting('epgPathType', '0')

        monitor = xbmc.Monitor()

        progress.update(30)

        monitor.waitForAbort(2)
        kodi_rpc('Addons.SetAddonEnabled', {'addonid': IPTV_SIMPLE_ID, 'enabled': True})

        progress.update(60)

        monitor.waitForAbort(2)

        progress.update(100)

        set_kodi_setting('epg.futuredaystodisplay', 7)
      #  set_kodi_setting('epg.ignoredbforclient', True)
        set_kodi_setting('pvrmanager.syncchannelgroups', True)
        set_kodi_setting('pvrmanager.preselectplayingchannel', True)
        set_kodi_setting('pvrmanager.backendchannelorder', True)
        set_kodi_setting('pvrmanager.usebackendchannelnumbers', True)

    gui.ok(_.SETUP_IPTV_COMPLETE)

    return True
def play(content_id=None, family_id=None, skip_intro=None, **kwargs):
    if KODI_VERSION > 18:
        ver_required = '2.6.0'
    else:
        ver_required = '2.4.5'

    ia = inputstream.Widevine(
        license_key=api.get_config()['services']['drm']['client']['endpoints']
        ['widevineLicense']['href'],
        manifest_type='hls',
        mimetype='application/vnd.apple.mpegurl',
    )

    if not ia.check() or not inputstream.require_version(ver_required):
        gui.ok(
            _(_.IA_VER_ERROR, kodi_ver=KODI_VERSION,
              ver_required=ver_required))

    if family_id:
        data = api.video_bundle(family_id)
        if not data.get('video'):
            raise PluginError(_.NO_VIDEO_FOUND)

        video = data['video']
    else:
        data = api.videos(content_id)
        if not data.get('videos'):
            raise PluginError(_.NO_VIDEO_FOUND)

        video = data['videos'][0]

    playback_url = video['mediaMetadata']['playbackUrls'][0]['href']
    playback_data = api.playback_data(playback_url)
    media_stream = playback_data['stream']['complete']
    original_language = video.get('originalLanguage') or 'en'

    headers = api.session.headers
    ia.properties['original_audio_language'] = original_language

    ## Allow fullres worldwide ##
    media_stream = media_stream.replace('/mickey/ps01/', '/ps01/')
    ##############

    item = _parse_video(video)
    item.update(
        path=media_stream,
        inputstream=ia,
        headers=headers,
        proxy_data={
            'default_language': original_language,
            'original_language': original_language
        },
    )

    if kwargs[ROUTE_RESUME_TAG] and settings.getBool('disney_sync', False):
        continue_watching = api.continue_watching()
        item.resume_from = continue_watching.get(video['contentId'], 0)
        item.force_resume = True

    elif (int(skip_intro) if skip_intro is not None else settings.getBool(
            'skip_intros', False)):
        item.resume_from = _get_milestone(
            video.get('milestones'), 'intro_end', default=0) / 1000

    item.play_next = {}

    if settings.getBool('skip_credits', False):
        next_start = _get_milestone(
            video.get('milestones'), 'up_next', default=0) / 1000
        item.play_next['time'] = next_start

    if video['programType'] == 'episode' and settings.getBool(
            'play_next_episode', True):
        data = api.up_next(video['contentId'])
        for row in data.get('items', []):
            if row['type'] == 'DmcVideo' and row[
                    'programType'] == 'episode' and row[
                        'encodedSeriesId'] == video['encodedSeriesId']:
                item.play_next['next_file'] = _get_play_path(row['contentId'])
                break

    elif video['programType'] != 'episode' and settings.getBool(
            'play_next_movie', False):
        data = api.up_next(video['contentId'])
        for row in data.get('items', []):
            if row['type'] == 'DmcVideo' and row['programType'] != 'episode':
                item.play_next['next_file'] = _get_play_path(row['contentId'])
                break

    if settings.getBool('wv_secure', False):
        item.inputstream.properties['license_flags'] = 'force_secure_decoder'

    if settings.getBool('disney_sync', False):
        telemetry = playback_data['tracking']['telemetry']
        item.callback = {
            'type':
            'interval',
            'interval':
            20,
            'callback':
            plugin.url_for(callback,
                           media_id=telemetry['mediaId'],
                           fguid=telemetry['fguid']),
        }

    return item
Пример #9
0
def home(**kwargs):
    folder = plugin.Folder(cacheToDisc=False)

    if not gpio.INSTALLED:
        folder.add_item(
            label=_(_.INSTALL_SERVICE, _bold=True),
            path=plugin.url_for(install_service),
            info={'plot': _.INSTALL_SERVICE_DESC},
            bookmark=False,
        )

    if gpio.SYSTEM == 'mock':
        if not userdata.get('_warning'):
            gui.ok(_.SYSTEM_UNSUPPORTED)
            userdata.set('_warning', True)

        folder.title = _(_.SIMULATION, _color='red')

    btns = list(Button.select())

    for btn in btns:
        label, description = btn.label()

        item = plugin.Item(
            label=label,
            info={'plot': description},
            path=plugin.url_for(view_btn, id=btn.id),
        )

        item.context.append(
            (_.DELETE_BTN,
             'RunPlugin({})'.format(plugin.url_for(delete_btn, id=btn.id))))

        if btn.when_pressed:
            item.context.append((_.TEST_PRESS, 'RunPlugin({})'.format(
                plugin.url_for(test_btn, id=btn.id, method='when_pressed'))))

        if btn.when_released:
            item.context.append((_.TEST_RELEASE, 'RunPlugin({})'.format(
                plugin.url_for(test_btn, id=btn.id, method='when_released'))))

        if btn.when_held:
            item.context.append((_.TEST_HOLD, 'RunPlugin({})'.format(
                plugin.url_for(test_btn, id=btn.id, method='when_held'))))

        folder.add_items([item])

    folder.add_item(
        label=_(_.ADD_BTN, _bold=True),
        path=plugin.url_for(add_btn),
        info={'plot': _.ADD_BTN_DESC},
    )

    if not settings.getBool(AUTO_RELOAD_SETTING, False):
        folder.add_item(
            label=_.RELOAD_SERVICE,
            path=plugin.url_for(reload_service),
            info={'plot': _.RELOAD_SERVICE_DESC},
        )

    if settings.getBool('bookmarks', True):
        folder.add_item(label=_(_.BOOKMARKS, _bold=True),
                        path=plugin.url_for(plugin.ROUTE_BOOKMARKS),
                        bookmark=False)

    folder.add_item(label=_.SETTINGS,
                    path=plugin.url_for(plugin.ROUTE_SETTINGS),
                    _kiosk=False,
                    bookmark=False)

    return folder
Пример #10
0
def _setup(check_only=False, reinstall=True, run_merge=True):
    addon = get_addon(IPTV_SIMPLE_ID,
                      required=not check_only,
                      install=not check_only)
    if not addon:
        return False

    output_dir = settings.get('output_dir', '').strip() or ADDON_PROFILE
    playlist_path = os.path.join(output_dir, PLAYLIST_FILE_NAME)
    epg_path = os.path.join(output_dir, EPG_FILE_NAME)

    is_setup = addon.getSetting('m3uPathType') == '0' and addon.getSetting('epgPathType') == '0' \
                and addon.getSetting('m3uPath') == playlist_path and addon.getSetting('epgPath') == epg_path

    if check_only:
        return is_setup

    elif is_setup and not reinstall:
        if run_merge:
            set_kodi_string('_iptv_merge_force_run', '1')

        return True

    ## IMPORT ANY CURRENT URL SOURCES ##
    cur_epg_url = addon.getSetting('epgUrl')
    cur_epg_type = addon.getSetting('epgPathType')
    if cur_epg_url:
        epg = EPG(source_type=EPG.TYPE_URL,
                  path=cur_epg_url,
                  enabled=cur_epg_type == '1')
        try:
            epg.save()
        except:
            pass

    cur_m3u_url = addon.getSetting('m3uUrl')
    cur_m3u_type = addon.getSetting('m3uPathType')
    start_chno = int(addon.getSetting('startNum') or 1)
    #user_agent = addon.getSetting('userAgent')
    if cur_m3u_url:
        playlist = Playlist(source_type=Playlist.TYPE_URL,
                            path=cur_m3u_url,
                            enabled=cur_m3u_type == '1')
        if start_chno != 1:
            playlist.use_start_chno = True
            playlist.start_chno = start_chno

        try:
            playlist.save()
        except:
            pass
    ################################

    addon.setSetting('epgPath', epg_path)
    addon.setSetting('m3uPath', playlist_path)
    addon.setSetting('epgUrl', '')
    addon.setSetting('m3uUrl', '')
    addon.setSetting('m3uPathType', '0')
    addon.setSetting('epgPathType', '0')

    set_kodi_setting('epg.futuredaystodisplay', 7)
    #  set_kodi_setting('epg.ignoredbforclient', True)
    set_kodi_setting('pvrmanager.syncchannelgroups', True)
    set_kodi_setting('pvrmanager.preselectplayingchannel', True)
    set_kodi_setting('pvrmanager.backendchannelorder', True)
    set_kodi_setting('pvrmanager.usebackendchannelnumbers', True)

    if run_merge:
        set_kodi_string('_iptv_merge_force_run', '1')

    gui.ok(_.SETUP_IPTV_COMPLETE)

    return True