コード例 #1
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def _get_magnet_list_item(magnet_link, magnet_data):
    _seeds = magnet_data.get('seeds') or magnet_data.get('_seeds')
    seeds = 0
    if _seeds:
        try:
            seeds = int(_seeds)
        except:
            pass

    _peers = magnet_data.get('peers') or magnet_data.get('_peers')
    peers = 0
    if _peers:
        try:
            peers = int(_peers)
        except:
            pass

    size = magnet_data.get('size') or magnet_data.get('_size')
    if not size or size == '?':
        size = _lang(33040)

    quality = magnet_data.get('quality') or magnet_data.get('_quality')
    if not quality or quality == '?':
        quality = _lang(33039)

    title = '%s, %s' % (quality, size)
    if seeds > 0:
        if peers > 0:
            title = '%s peers, %s' % (peers, title)
        title = '%s seeders, %s' % (seeds, title)

    return [magnet_link, title, seeds, peers]
コード例 #2
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def open_magnet(magnet_link):
    log("open magnet: %s" % magnet_link)
    if magnet_link:
        try:
            start_bitx(magnet_link)
            kodi_go_back()
            return
        except Exception as ex:
            log("BitX magnet start error: %s" % ex, level=xbmc.LOGERROR)

    notice(_lang(33023), _lang(33022), 2500)
    kodi_go_back()
コード例 #3
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def action_category_search(category):
    if category != 'movies' and category != 'tvshows':
        return result_not_supported_category(category)

    name = _lang(33003) if category == 'tvshows' else _lang(33001)
    while True:
        search_term = plugin.keyboard('', _lang(33034))
        if search_term is None:
            kodi_go_back()
            return

        if len(search_term.decode('utf-8')) >= 2:
            store['last_search_term'] = search_term
            break
        else:
            notice(_lang(33021), _lang(33020))

    url = plugin.url_for('action_category_media_search', category=category, search_term=search_term)
    plugin.redirect(url)
コード例 #4
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def create_kodi_list(data, page=1, category='movies', genre=NONE, search_term=NONE):
    if not data or not data.get('success') or data.get('err'):
        return result_error("Error " + str(next(iter(data.get('err')))), category)

    if category != 'movies' and category != 'tvshows':
        return result_not_supported_category(category)

    has_next_page = data.get('paging') and int(data['paging'].get('total_pages', '0')) > page
    has_prev_page = page > 1

    entries = data['data'][category]
    if category == "tvshows":
        items = [make_tvshow_item(entry) for entry in entries if entry]
    else:
        items = [make_movie_item(entry) for entry in entries if entry]

    store['store'] = entries

    if not items:
        return result_nothing_found(category)

    if has_next_page:
        new_page = str(page + 1)
        next_item = {
            'label': '[COLOR {}][B]{}[/B][/COLOR]'.format(PREV_NEXT_COLOR, _lang(33035).format(new_page)),
            'path': plugin.url_for('action_category_media_page', category=category, genre=genre, page=new_page, search_term=search_term)
        }
        items.insert(0, next_item)
        items.insert(len(items), next_item)

    if has_prev_page:
        new_page = str(page - 1)
        items.insert(0, {
            'label': '[COLOR {}][B]{}[/B][/COLOR]'.format(PREV_NEXT_COLOR, _lang(33036).format(new_page)),
            'path': plugin.url_for('action_category_media_page', category=category, genre=genre, page=new_page, search_term=search_term)
        })

    return items
コード例 #5
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def action_category_alphabet(category):
    if category != 'movies' and category != 'tvshows':
        return result_not_supported_category(category)

    name = _lang(33003) if category == 'tvshows' else _lang(33001)
    all_color = TVSHOWS_COLOR if category == 'tvshows' else MOVIES_COLOR

    result = [
        prepare_list_item({
            'label': '[COLOR %s]All %s[/COLOR]' % (all_color, name),
            'path': plugin.url_for('action_category_media', category=category),
            'info': {'plot': 'All %s' % name}
        }, category)
    ]

    for letter in "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z".split(","):
        result.insert(len(result), prepare_list_item({
            'label': "[B]%s[/B]" % letter,
            'path': plugin.url_for('action_category_media_search', category=category, search_term=letter),
            'info': {'plot': '%s by the [B]%s[/B] letter' % (name, letter)}
        }, category))

    log("alphabet %s route" % name)
    return result
コード例 #6
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def action_category_genres(category):
    if category != 'movies' and category != 'tvshows':
        return result_not_supported_category(category)

    name = _lang(33003) if category == 'tvshows' else _lang(33001)
    all_color = TVSHOWS_COLOR if category == 'tvshows' else MOVIES_COLOR

    result = [
        prepare_list_item({
            'label': '[COLOR %s][B]Any genre[/B][/COLOR]' % all_color,
            'path': plugin.url_for('action_category_media', category=category),
            'info': {'plot': '%s of any genre' % name}
        }, category)
    ]

    for genre in genres_list:
        result.insert(len(result), prepare_list_item({
            'label': "[COLOR %s]%s[/COLOR]" % (GENRE_COLOR, genre),
            'path': plugin.url_for('action_category_media_genre', category=category, genre=genre),
            'info': {'plot': '%s %s' % (genre, name)}
        }, category))

    log("genres %s route" % name)
    return result
コード例 #7
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def custom_action(argv=None):
    log("custom_action: %s" % argv)
    if argv and len(argv) > 2:
        action = argv[2]
        if action == 'add_to_favorites':
            if len(argv) > 3 and argv[3]:
                entry_id = argv[3]
                log("add_to_favorites by EntryID: %s" % entry_id)
        elif action == 'update_plugin':
            check_update()
        elif action == 'authorization':
            pass
        elif action == 'show_log':
            pass
        elif action == 'bug_report':
            report_text = plugin.keyboard('', _lang(33030))
            if report_text and len(report_text.decode('utf-8')) >= 1:
                # {"title":"SiTo Feedback","description":"","email":"unknown"}
                api('feedback', '{"title":"SiTo Feedback","description":"'+report_text.replace('"', '\\"')+'","email":"unknown"}', method='POST')
コード例 #8
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def check_update(force=True):
    log('SiTo.tv update requested ...')
    current_time = int(time.time())

    # Test the "check" status itself
    last_update_check = plugin.get_setting('last_update_check_time', str)
    last_update_check = int(last_update_check) if last_update_check else 0
    if not force and (current_time - last_update_check < 86400):
        # checked already
        return

    vinfo = get_server_versions()
    # Save time of this check
    plugin.set_setting('last_update_check_time', str(current_time))

    if vinfo and vinfo.get('min_version'):
        min_version = vinfo['min_version']
        latest_version = vinfo['current_version']
        current_version = plugin.addon.getAddonInfo('version')
        log("Current plugin version {} required versions {}".format(current_version, vinfo))
        try:
            from distutils.version import StrictVersion
            if StrictVersion(min_version) > StrictVersion(current_version):
                # Update Requed
                notice(_lang(33025), _lang(33024))
                xbmc.executebuiltin('UpdateAddonRepos')
            elif StrictVersion(latest_version) == StrictVersion(current_version):
                # Latest Version
                notice(_lang(33031), _lang(33024))
            else:
                # Can be updated
                notice(_lang(33032), _lang(33024))
                if force:
                    xbmc.executebuiltin('UpdateAddonRepos')
        except Exception as ex:
            log("StrictVersion error: %s" % ex, level=xbmc.LOGERROR)
            notice(_lang(33033), _lang(33024))
コード例 #9
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def action_index():
    result = [
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(MOVIES_COLOR, _lang(33001)),
            'path': plugin.url_for('action_category', category='movies'),
            'poster': plugin.addon.getAddonInfo('icon'),
            'info': {'plot': _lang(33002)}
        }, 'movies'),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(COLOR_DISABLED, _lang(33003)),
            'path': plugin.url_for('action_ok_dialog',
                                   title='SiTo.tv',
                                   text=_lang(33004)),
            'poster': plugin.addon.getAddonInfo('icon'),
            'info': {'plot': _lang(33005)}
        }, 'tvshows'),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(COLOR_WHITE, _lang(33006)),
            'path': plugin.url_for('action_custom_action', action='Addon.OpenSettings(%s)' % PLUGIN_ID),
            'info': {'plot': _lang(33007)}
        }, 'settings')
    ]
    log("index route")
    return plugin.finish(result, view_mode=ViewMode.IconWall)
コード例 #10
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def prepare_media_info(data, category, as_stub=False):
    title = data.get('title') or data.get('_title') or 'Title unknown'

    synopsis = data.get('synopsis') or data.get('_synopsis')
    if synopsis == 'None' or synopsis == 'N/A':
        synopsis = None

    description = data.get('description') or data.get('_description') or data.get('desc') or data.get('_desc')
    if description == 'None' or description == 'N/A':
        description = None

    description = description or synopsis or _lang(33042)
    synopsis = synopsis or description or _lang(33043)

    info = {
        'title': title,
        'tvshowtitle': title,
        'plot': description,
        'plotoutline': synopsis,
        'tagline': synopsis,
        'language': (data.get('language') or 'en').lower()[0:2],
    }

    description = "\n" + description

    if data.get('imdb_code'):
        info['code'] = data['imdb_code']

    if data.get('mpa_rating'):
        info['mpaa'] = data['mpa_rating']

    if data.get('ratings'):
        ratings = data['ratings']
        imdb_rating = None
        if isinstance(ratings, dict):
            imdb_rating = ratings.get('imdb')
        elif isinstance(ratings, list):
            for ritem in ratings:
                if isinstance(ritem, dict) and ritem.get('imdb'):
                    imdb_rating = ritem['imdb']
        if imdb_rating and imdb_rating != 'N/A':
            description = "IMDB: %s\n%s" % (imdb_rating, description)
            info['rating'] = float(imdb_rating)

    if data.get('genres'):
        genres = data['genres']
        if 'N/A' in genres:
            genres.remove('N/A')
        if genres:
            genres = ", ".join(genres)
            description = "Genres: %s\n%s" % (genres, description)
            info['genre'] = genres

    if data.get('year') and not as_stub:
        try:
            info['year'] = int(data['year'])
        except:
            parts = data['year'].split(u'–', 2)
            if len(parts) >= 2:
                info['year'] = int(parts[1] if parts[1] else parts[0])

    if data.get('trailer'):
        info['trailer'] = 'plugin://plugin.video.youtube/?action=play_video&videoid=' + data['trailer']

    if data.get('actors'):
        info['cast'] = data['actors']

    if data.get('timeadded'):
        # string (Y-m-d h:m:s = 2009-04-05 23:16:04)
        info['dateadded'] = datetime.date.fromtimestamp(data['timeadded']).strftime('%Y-%m-%d %H:%M:%S')

    if data.get('magnets'):
        sizes = [int(magnet.get('_size_bytes') or magnet.get('size_bytes') or 0) for magnet in data['magnets']]
        sizes = [bytes_num for bytes_num in sizes if bytes_num > 0]
        if sizes:
            info['size'] = sorted(sizes)[0]

    if as_stub:
        description = "%s\n%s" % (title, description)

    label = title
    if data.get('seasons'):
        length = len(data['seasons'])
        if length or category == 'tvshows':
            label = '[B]%s[/B]  [COLOR %s](%s %s)[/COLOR]' % (label, ADDITIONS_COLOR, length, 'season' if length == 1 else 'seasons')

    description = description.strip()
    info['plot'] = description

    entry_id = _get_entry_id(data)
    result = {
        'label': label,
        'label2': description,
        'info': info,
        '__entry_id__': entry_id
    }

    result = prepare_list_item(result, category, api_data=data, is_structural=False)
    return result
コード例 #11
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def result_nothing_found(category='movies'):
    if category not in ('tvshows', 'movies'):
        category = 'movies'

    label = _lang(33041)
    return result_error(label, category, do_notice=False)
コード例 #12
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def result_not_supported_category(category):
    return result_error('{}: {}'.format(_lang(33044), category), 'movies')
コード例 #13
0
ファイル: api.py プロジェクト: SiTo-tv/kodi.sito.tv
def make_playlist_item(data, category):
    title = data.get('title') or _lang(33037)
    description = data.get('desc') or data.get('description') or data.get('synopsis')
    if not description or description == 'None':
        description = _lang(33038)

    info = {
        'title': title,
        'plot': description,
        'language': (data.get('language') or 'en').lower()
    }

    description = "\n" + description + "\n"

    background_image = None
    large_cover_image = None
    small_cover_image = None

    if data.get('tags'):
        tags = data['tags']
        description = "Tags: %s\n%s" % (", ".join(tags), description)

    label = title
    if data.get('items'):
        length = len(data['items'])
        label = '[B]%s[/B]  [COLOR %s](%s %s)[/COLOR]' % (label, ADDITIONS_COLOR, length, 'item' if length == 1 else 'items')

        for pitem in data['items']:
            if not pitem:
                continue

            if pitem.get('title'):
                description = description + "\n - " + pitem['title'].strip()

            if not background_image and pitem.get('background_image'):
                background_image = pitem['background_image']

            if not large_cover_image and pitem.get('large_cover_image'):
                large_cover_image = pitem['large_cover_image']

            if not small_cover_image and pitem.get('small_cover_image'):
                small_cover_image = pitem['small_cover_image']

    description = description.strip()
    info['plot'] = description

    playlist_id = "%s: %s" % (_get_entry_id_raw(data), data.get('title'))

    result = {
        'label': label,
        'label2': description,
        'info': info,
        'path': url_for('action_category_playlist_show', playlist_id=playlist_id, category=category),
        '__playlist_id__': playlist_id,
    }

    if background_image:
        result['fanart'] = background_image

    if large_cover_image:
        result['poster'] = large_cover_image
        result['thumbnail'] = large_cover_image
        result['icon'] = large_cover_image

    if small_cover_image:
        result['favicon'] = small_cover_image
        if not large_cover_image:
            result['poster'] = small_cover_image
            result['thumbnail'] = small_cover_image
            result['icon'] = small_cover_image

    return prepare_list_item(result, category, is_structural=True)
コード例 #14
0
ファイル: views.py プロジェクト: SiTo-tv/kodi.sito.tv
def action_category(category):
    if category != 'movies' and category != 'tvshows':
        return result_not_supported_category(category)

    name = _lang(33003) if category == 'tvshows' else _lang(33001)
    all_color = TVSHOWS_COLOR if category == 'tvshows' else MOVIES_COLOR

    result = [
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(all_color, _lang(33008)),
            'path': plugin.url_for('action_category_media', category=category),
            'info': {'plot': _lang(33014)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(GENRE_COLOR, _lang(33009)),
            'path': plugin.url_for('action_category_genres', category=category),
            'info': {'plot': _lang(33015)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(ALPHABET_COLOR, _lang(33010)),
            'path': plugin.url_for('action_category_alphabet', category=category),
            'info': {'plot': _lang(33016)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(COLOR_DISABLED, _lang(33011)),
            'path': plugin.url_for('action_ok_dialog',
                                   title='SiTo.tv',
                                   text=_lang(33045)),
            'info': {'plot': _lang(33017)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(SEARCH_COLOR, _lang(33012)),
            'path': plugin.url_for('action_category_search', category=category),
            'info': {'plot': _lang(33018)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(LAST_VIEWED_COLOR, _lang(33013)),
            'path': plugin.url_for('action_category_last_viewed', category=category),
            'info': {'plot': _lang(33019)}
        }, category),
        prepare_list_item({
            'label': '[COLOR {}]{}[/COLOR]'.format(all_color, _lang(33006)),
            'path': plugin.url_for('action_custom_action', action='Addon.OpenSettings(%s)' % PLUGIN_ID),
            'info': {'plot': _lang(33007)}
        }, 'settings')
    ]

    log("index %s route" % name)
    return plugin.finish(result, view_mode=ViewMode.ListView)