def add_trakt(title, year=''):
    trakt_api = Trakt_API(kodi.get_setting('trakt_oauth_token'), kodi.get_setting('use_https') == 'true', timeout=int(kodi.get_setting('trakt_timeout')))
    results = trakt_api.search(SECTIONS.MOVIES, title)
    try: results = [result for result in results if result['year'] is not None and int(result['year']) - 1 <= int(year) <= int(result['year'] + 1)]
    except: pass
    if not results:
        kodi.notify(msg=i18n('no_movie_found'))
        return
    
    if len(results) == 1:
        index = 0
    else:
        pick_list = [movie['title'] if movie['year'] is None else '%s (%s)' % (movie['title'], movie['year']) for movie in results]
        index = xbmcgui.Dialog().select(i18n('pick_a_movie'), pick_list)
        
    if index > -1:
        slug = kodi.get_setting('default_slug')
        name = kodi.get_setting('default_list')
        if not slug:
            result = utils.choose_list(Trakt_API, translations)
            if result is None:
                return
            else:
                slug, name = result
        
        item = {'trakt': results[index]['ids']['trakt']}
        if slug == WATCHLIST_SLUG:
            trakt_api.add_to_watchlist(SECTIONS.MOVIES, item)
        elif slug:
            trakt_api.add_to_list(SECTIONS.MOVIES, slug, item)
            
        movie = results[index]
        label = movie['title'] if movie['year'] is None else '%s (%s)' % (movie['title'], movie['year'])
        kodi.notify(msg=i18n('added_to_list') % (label, name))
        kodi.refresh_container()
示例#2
0
def delete_link(index, path):
    path = os.path.join(path, LINK_FILE)
    new_lines = []
    with open(path) as f:
        for i, line in enumerate(f):
            if i == int(index):
                continue
            new_lines.append(line)

    write_links(path, new_lines)
    kodi.refresh_container()
示例#3
0
def create_dir(path, dir_name=None):
    if dir_name is None:
        dir_name = kodi.get_keyboard('Enter Directory Name')
        if dir_name is None:
            return

    try:
        os.mkdir(os.path.join(path, dir_name))
    except OSError as e:
        kodi.notify(msg=e.strerror)
    kodi.refresh_container()
示例#4
0
def delete_dir(path, dir_name):
    path = os.path.join(path, dir_name)
    try:
        os.rmdir(path)
    except OSError:
        delete = xbmcgui.Dialog().yesno('Directory Not Empty',
                                        'Delete it?',
                                        nolabel='No',
                                        yeslabel='Yes')
        if delete:
            shutil.rmtree(path)
            kodi.refresh_container()
示例#5
0
def rename_dir(path, dir_name, new_name=None):
    if new_name is None:
        new_name = kodi.get_keyboard('Enter Directory Name', dir_name)
        if new_name is None:
            return

    old_path = os.path.join(path, dir_name)
    new_path = os.path.join(path, new_name)
    try:
        os.rename(old_path, new_path)
    except OSError as e:
        kodi.notify(msg=e.strerror)
    kodi.refresh_container()
示例#6
0
def delete_link(index):
    new_lines = []
    with open(LINK_PATH) as f:
        for i, line in enumerate(f):
            if i == int(index):
                continue
            new_lines.append(line)
            
    with open(LINK_PATH, 'w') as f:
        for line in new_lines:
            f.write(line)

    kodi.refresh_container()
示例#7
0
def edit_link(index, path):
    path = os.path.join(path, LINK_FILE)
    new_lines = []
    with open(path) as f:
        for i, line in enumerate(f):
            if i == int(index):
                item = line.split('|')
                result = prompt_for_link(*item)
                if result:
                    line = '|'.join(result)

            new_lines.append(line)

    write_links(path, new_lines)
    kodi.refresh_container()
示例#8
0
def add_trakt(title, year=''):
    trakt_api = Trakt_API(kodi.get_setting('trakt_oauth_token'),
                          kodi.get_setting('use_https') == 'true',
                          timeout=int(kodi.get_setting('trakt_timeout')))
    results = trakt_api.search(SECTIONS.MOVIES, title)
    try:
        results = [
            result for result in results
            if result['year'] is not None and int(result['year']) -
            1 <= int(year) <= int(result['year'] + 1)
        ]
    except:
        pass
    if not results:
        kodi.notify(msg=i18n('no_movie_found'))
        return

    if len(results) == 1:
        index = 0
    else:
        pick_list = [
            movie['title'] if movie['year'] is None else '%s (%s)' %
            (movie['title'], movie['year']) for movie in results
        ]
        index = xbmcgui.Dialog().select(i18n('pick_a_movie'), pick_list)

    if index > -1:
        slug = kodi.get_setting('default_slug')
        name = kodi.get_setting('default_list')
        if not slug:
            result = utils.choose_list(Trakt_API, translations)
            if result is None:
                return
            else:
                slug, name = result

        item = {'trakt': results[index]['ids']['trakt']}
        if slug == WATCHLIST_SLUG:
            trakt_api.add_to_watchlist(SECTIONS.MOVIES, item)
        elif slug:
            trakt_api.add_to_list(SECTIONS.MOVIES, slug, item)

        movie = results[index]
        label = movie['title'] if movie['year'] is None else '%s (%s)' % (
            movie['title'], movie['year'])
        kodi.notify(msg=i18n('added_to_list') % (label, name))
        kodi.refresh_container()
示例#9
0
def edit_link(index):
    new_lines = []
    with open(LINK_PATH) as f:
        for i, line in enumerate(f):
            if i == int(index):
                item = line.split('|')
                result = prompt_for_link(*item)
                if result:
                    line = '|'.join(result)
                
            new_lines.append(line)

    with open(LINK_PATH, 'w') as f:
        for line in new_lines:
            if not line.endswith('\n'):
                line += '\n'
                
            f.write(line)

    kodi.refresh_container()
示例#10
0
def add_link(link=None, name=None, refresh=True):
    if link is None:
        result = prompt_for_link()
    else:
        if name is None:
            result = (link, )
        else:
            result = (link, name)
            
    if result:
        if not os.path.exists(os.path.dirname(LINK_PATH)):
            os.mkdir(os.path.dirname(LINK_PATH))
            
        with open(LINK_PATH, 'a') as f:
            line = '|'.join(result)
            if not line.endswith('\n'):
                line += '\n'
            f.write(line)
        
        if refresh:
            kodi.refresh_container()
示例#11
0
def add_link(link=None, name=None, refresh=True, path=None):
    if path is None: path = LINK_PATH
    if link is None:
        result = prompt_for_link()
    else:
        if name is None:
            result = (link, )
        else:
            result = (link, name)

    if result:
        if not os.path.exists(os.path.dirname(path)):
            os.mkdir(os.path.dirname(path))

        path = os.path.join(path, LINK_FILE)
        with open(path, 'a') as f:
            line = '|'.join(result)
            if not line.endswith('\n'):
                line += '\n'
            f.write(line)

        if refresh:
            kodi.refresh_container()
示例#12
0
def showSettings():

    kodi.show_settings()
    kodi.refresh_container()
示例#13
0
def play_this(item, title='', thumbnail='', player=True, history=None):
    if history is None:
        history = kodi.get_setting('history-add-on-play') == "true"
    override_history = kodi.get_setting('history-add-on-play') == "true"
    stream_url = None
    headers = None
    content_type = 'video'
    override_content_type = None
    is_dash = False
    direct = [
        'rtmp:', 'rtmpe:', 'ftp:', 'ftps:', 'special:', 'plugin:', 'udp:',
        'upnp:'
    ]
    unresolved_source = None
    label = title
    source_label = label
    source_thumbnail = thumbnail
    history_item = None

    if item.startswith('http'):
        with kodi.ProgressDialog(
                '%s...' % kodi.i18n('resolving'),
                '%s:' % kodi.i18n('attempting_determine_type'),
                item) as progress_dialog:
            while not progress_dialog.is_canceled():
                url_override = __check_for_new_url(item)
                if item != url_override:
                    log_utils.log(
                        'Source |{0}| has been replaced by |{1}|'.format(
                            item, url_override), log_utils.LOGDEBUG)
                    progress_dialog.update(
                        5, '%s: %s' % (kodi.i18n('source'), item),
                        '%s: %s' % (kodi.i18n('replaced_with'), url_override),
                        ' ')
                    item = url_override
                result = __get_content_type_and_headers(item)
                content_type = result['content_type']
                headers = result['headers']
                url_override = result['url_override']
                if url_override:
                    log_utils.log(
                        'Source |{0}| has been replaced by |{1}|'.format(
                            item, url_override), log_utils.LOGDEBUG)
                    progress_dialog.update(
                        10, '%s: %s' % (kodi.i18n('source'), item),
                        '%s: %s' % (kodi.i18n('replaced_with'), url_override),
                        ' ')
                    item = url_override

                log_utils.log(
                    'Source |{0}| has media type |{1}|'.format(
                        item, content_type), log_utils.LOGDEBUG)
                progress_dialog.update(
                    20, '%s: %s' % (kodi.i18n('source'), item),
                    '%s: %s' % (kodi.i18n('using_media_type'), content_type),
                    ' ')
                if content_type == 'video' or content_type == 'audio' or content_type == 'image' \
                        or content_type == 'mpd' or content_type == 'smil':
                    source = item
                    if content_type == 'smil':
                        content_type = 'video'
                        smil_result = __get_html_and_headers(item, headers)
                        source = pick_source(
                            parse_smil_source_list(smil_result['contents']))
                    elif content_type == 'mpd':
                        content_type = 'video'
                        if not dash_supported:
                            source = None
                        else:
                            is_dash = True
                    if source:
                        stream_url = source

                elif content_type == 'text':
                    if progress_dialog.is_canceled():
                        sys.exit(0)
                    progress_dialog.update(
                        40, '%s: %s' % (kodi.i18n('source'), item),
                        '%s: URLResolver' % kodi.i18n('attempt_resolve_with'),
                        ' ')
                    content_type = 'video'
                    headers.update({'Referer': item})
                    source = resolve(item, title=title)
                    if source:
                        log_utils.log(
                            'Source |{0}| was |URLResolver supported|'.format(
                                source), log_utils.LOGDEBUG)
                        sd_result = __check_smil_dash(source, headers)
                        source = sd_result['url']
                        is_dash = sd_result['is_dash']
                        if source:
                            progress_dialog.update(
                                98, '%s: %s' % (kodi.i18n('source'), item),
                                '%s: URLResolver' %
                                kodi.i18n('attempt_resolve_with'), '%s: %s' %
                                (kodi.i18n('resolution_successful'), source))
                            stream_url = source

                    if not stream_url:
                        if progress_dialog.is_canceled():
                            sys.exit(0)
                        progress_dialog.update(
                            60, '%s: %s' % (kodi.i18n('source'), item),
                            '%s: youtube-dl' %
                            kodi.i18n('attempt_resolve_with'), ' ')
                        if ytdl_supported(item):
                            ytdl_result = resolve_youtube_dl(item)
                            if ytdl_result['resolved_url']:
                                headers = ytdl_result['headers']
                                label = ytdl_result['label'] if ytdl_result[
                                    'label'] is not None else label
                                source_thumbnail = ytdl_result[
                                    'thumbnail'] if ytdl_result[
                                        'thumbnail'] is not None else source_thumbnail
                                log_utils.log(
                                    'Source |{0}| found by |youtube-dl|'.
                                    format(ytdl_result['resolved_url']),
                                    log_utils.LOGDEBUG)
                                sd_result = __check_smil_dash(
                                    ytdl_result['resolved_url'], headers)
                                source = sd_result['url']
                                is_dash = sd_result['is_dash']
                                if source:
                                    progress_dialog.update(
                                        98,
                                        '%s: %s' % (kodi.i18n('source'), item),
                                        '%s: youtube-dl' %
                                        kodi.i18n('attempt_resolve_with'),
                                        '%s: %s' %
                                        (kodi.i18n('resolution_successful'),
                                         source))
                                    stream_url = source

                if not progress_dialog.is_canceled():
                    progress_dialog.update(100, ' ',
                                           kodi.i18n('resolution_completed'),
                                           ' ')
                    break
                else:
                    sys.exit(0)

        if not stream_url:
            content_type = 'executable'
            scrape_result = scrape(item)
            source = scrape_result['resolved_url']
            override_content_type = scrape_result['content_type']
            unresolved_source = scrape_result['unresolved_url']
            source_label = scrape_result['label']
            headers = scrape_result['headers']
            if scrape_result['thumbnail']:
                source_thumbnail = scrape_result['thumbnail']
            if scrape_result['title']:
                label = scrape_result['title']
            if source:
                log_utils.log(
                    'Source |{0}| found by |Scraping for supported|'.format(
                        source), log_utils.LOGDEBUG)
                if override_content_type == 'video':
                    sd_result = __check_smil_dash(source, headers)
                    source = sd_result['url']
                    is_dash = sd_result['is_dash']
                if source:
                    stream_url = source

        if stream_url:
            stream_url = stream_url.replace(r'\\', '')

    elif any(item.startswith(p) for p in direct):
        log_utils.log('Source |{0}| may be supported'.format(item),
                      log_utils.LOGDEBUG)
        stream_url = item

    if is_dash and (not dash_supported
                    or not kodi.addon_enabled('inputstream.adaptive')):
        stream_url = None

    if stream_url and (content_type == 'video' or content_type == 'audio'
                       or content_type == 'image'
                       or content_type == 'executable'):
        working_dialog = kodi.WorkingDialog()
        with working_dialog:
            play_history = utils.PlayHistory()
            working_dialog.update(20)
            if history or player == 'history':
                history_item = item.split('|')[0]
                if '%' not in history_item:
                    history_item = urllib2.quote(history_item)
                log_utils.log(
                    'Adding source |{0}| to history with content_type |{1}|'.
                    format(item, content_type), log_utils.LOGDEBUG)
                play_history.add(history_item, content_type,
                                 label if label else item,
                                 urllib2.quote(thumbnail))
            working_dialog.update(40)
            if override_content_type and override_history:
                history_item = stream_url
                if history_item.startswith('plugin://') or unresolved_source:
                    history_item = unresolved_source
                history_item = history_item.split('|')[0]
                if '%' not in history_item:
                    history_item = urllib2.quote(history_item)
                log_utils.log(
                    'Adding source |{0}| to history with content_type |{1}|'.
                    format(unresolved_source,
                           override_content_type), log_utils.LOGDEBUG)
                play_history.add(history_item, override_content_type,
                                 source_label, urllib2.quote(source_thumbnail))
            if player == 'history':
                return
            if history_item:
                kodi.refresh_container()
            working_dialog.update(60)
            if (not stream_url.startswith('plugin://')) and (headers
                                                             is not None):
                stream_url = get_url_with_headers(stream_url, headers)

            working_dialog.update(80)
            if any(plugin_id in stream_url
                   for plugin_id in RUNPLUGIN_EXCEPTIONS):
                log_utils.log('Running plugin: |{0!s}|'.format(stream_url),
                              log_utils.LOGDEBUG)
                kodi.execute_builtin('RunPlugin(%s)' % stream_url)
            else:
                if override_content_type:
                    content_type = override_content_type

                source = {
                    'content_type': content_type,
                    'url': stream_url,
                    'is_dash': is_dash,
                    'info': {
                        'title': source_label
                    },
                    'art': {
                        'icon': source_thumbnail,
                        'thumb': source_thumbnail
                    }
                }

                play(source, player)

    else:
        log_utils.log('Found no potential sources: |{0!s}|'.format(item),
                      log_utils.LOGDEBUG)