예제 #1
0
def play(params):
    """
    Play a media file

    params: path, mirrors, mp4
    """
    path = params['path']
    mirrors = params.get('mirrors', [])
    mp4 = params.get('mp4')
    if mirrors or mp4:
        if plugin.choose_mirrors == 1:
            menu_items = []
            paths = []
            for index, mirror in enumerate(mirrors):
                menu_items.append(_('Mirror {0}').format(index + 1))
                paths.append(mirror)
            menu_items.insert(0, _('Original media'))
            paths.insert(0, path)
            if mp4:
                menu_items.append(_('Lightweight version'))
                paths.append(mp4)
            selection = dialog.select(_('Select media to play'), menu_items)
            if selection >= 0:
                path = paths[selection]
            else:
                return plugin.resolve_url(succeeded=False)
        elif plugin.choose_mirrors == 2 and mp4:
            path = mp4
    if webclient.SITE not in path:
        path = webclient.SITE + path
    if plugin.authorization and webclient.is_logged_in():
        path += '|Cookie=' + urllib.quote(urllib.urlencode(webclient.get_cookies()).replace('&', '; '))
    plugin.log_debug('Playing path: {0}'.format(path))
    return path
예제 #2
0
def bookmarks(params):
    """
    Login to display ex.ua bookmarks
    """
    if not webclient.is_logged_in():
        plugin.log_debug('Trying to login to ex.ua')
        username = plugin.get_setting('username', False)
        password = webclient.decode(plugin.get_setting('password', False))
        captcha = webclient.check_captcha()
        login_dialog = login_window.LoginWindow(username, password, captcha.image)
        login_dialog.doModal()
        if not login_dialog.login_cancelled:
            try:
                webclient.login(login_dialog.username,
                                login_dialog.password,
                                captcha.captcha_id,
                                login_dialog.captcha_text)
            except webclient.LoginError:
                plugin.log_debug('ex.ua login error')
                dialog.ok(_('Login error!'), _('Check your login and password, and try again.'))
            else:
                plugin.log_debug('Successful login to ex.ua')
                plugin.set_setting('username', login_dialog.username)
                if plugin.save_pass:
                    plugin.set_setting('password', webclient.encode(login_dialog.password))
                else:
                    plugin.set_setting('password', '')
        del login_dialog
    if webclient.is_logged_in():
        plugin.log_debug('The user is logged in, getting bookmarks.')
        media = exua.get_media_list('/buffer')
        plugin.log_debug('My bookmarks: {0}'.format(media))
        listing = _media_list('/buffer', media, from_bookmarks=True)
    else:
        listing = []
    return listing
예제 #3
0
def _media_list(path, media_listing, page=0, is_search_result=False, from_bookmarks=False):
    """
    Create the list of videos
    """
    if media_listing.original_id is not None and not page and not is_search_result:
        yield {
            'label': '[{0}]'.format(_('Search in the category...')),
            'url': plugin.get_url(action='search', original_id=media_listing.original_id),
            'thumb': os.path.join(icons, 'search.png')
        }
    if media_listing.prev_page is not None:
        yield {
            'label': '{0} < {1}'.format(media_listing.prev_page, _('Previous')),
            'url': plugin.get_url(action='media_list', path=path, page=str(page - 1)),
            'thumb': os.path.join(icons, 'previous.png')
        }
    is_logged_in = webclient.is_logged_in()
    for item in media_listing.media:
        list_item = {
            'label': item.title,
            'url': plugin.get_url(action='display_path', path=item.path),
            'thumb': item.thumb
        }
        if is_logged_in:
            item_id_match = re.search(r'^/(\d+)', item.path)
            if item_id_match is not None:
                if from_bookmarks:
                    list_item['context_menu'] = [(_('Remove from ex.ua bookmarks'),
                                                 'RunScript({commands},remove_bookmark,{link})'.format(
                                                     commands=commands,
                                                     link='/delete_link/{0}?link_id=4'.format(item_id_match.group(1))
                                                 ))]
                else:
                    list_item['context_menu'] = [(_('Add to ex.ua bookmarks'),
                                                  'RunScript({commands},add_bookmark,{link})'.format(
                                                      commands=commands,
                                                      link='/add_link/{0}?link_id=4'.format(item_id_match.group(1))
                                                  ))]
        yield list_item
    if media_listing.next_page is not None:
        yield {
            'label': '{0} > {1}'.format(_('Next'), media_listing.next_page),
            'url': plugin.get_url(action='media_list', path=path, page=str(page + 1)),
            'thumb': os.path.join(icons, 'next.png')
        }
예제 #4
0
def root(params):
    """
    Plugin root action
    """
    # The 'content_type' parameter may be passed by Kodi if a plugin is called
    # from "Music add-ons" or "Video add-ons" section.
    if plugin.content_type == 1 or params.get('content_type') == 'video':
        listing = media_categories({'content': 'video'})
    elif plugin.content_type == 2 or params.get('content_type') == 'audio':
        listing = media_categories({'content': 'audio'})
    else:
        listing = [
            {'label': '[{0}]'.format(_('Video')),
             'url': plugin.get_url(action='categories', content='video'),
             'thumb': os.path.join(icons, 'video.png')
             },
            {'label': '[{0}]'.format(_('Audio')),
             'url': plugin.get_url(action='categories', content='audio'),
             'thumb': os.path.join(icons, 'audio.png')
             }
        ]
    for item in listing:
        yield item
    yield {
        'label': '[{0}]'.format(_('Search...')),
        'url': plugin.get_url(action='search'),
        'thumb': os.path.join(icons, 'search.png')
    }
    if plugin.savesearch:
        yield {
            'label': '[{0}]'.format(_('Search history')),
            'url': plugin.get_url(action='search_history'),
            'thumb': os.path.join(icons, 'search_history.png')
        }
    if plugin.authorization:
        bookmarks_item = {'url': plugin.get_url(action='bookmarks')}
        if webclient.is_logged_in():
            bookmarks_item['label'] = '[{0}]'.format(_('My bookmarks'))
            bookmarks_item['thumb'] = os.path.join(icons, 'bookmarks.png')
        else:
            bookmarks_item['label'] = '[{0}]'.format(_('ex.ua login'))
            bookmarks_item['thumb'] = os.path.join(icons, 'key.png')
        yield bookmarks_item
예제 #5
0
def root(params):
    """
    Plugin root action
    """
    if plugin.content_type == 1:
        listing = media_categories({'content': 'video'})
    elif plugin.content_type == 2:
        listing = media_categories({'content': 'audio'})
    else:
        listing = [
            {'label': '[{0}]'.format(_('Video')),
             'url': plugin.get_url(action='categories', content='video'),
             'thumb': os.path.join(icons, 'video.png')
             },
            {'label': '[{0}]'.format(_('Audio')),
             'url': plugin.get_url(action='categories', content='audio'),
             'thumb': os.path.join(icons, 'audio.png')
             }
        ]
    for item in listing:
        yield item
    yield {
        'label': '[{0}]'.format(_('Search...')),
        'url': plugin.get_url(action='search'),
        'thumb': os.path.join(icons, 'search.png')
    }
    if plugin.savesearch:
        yield {
            'label': '[{0}]'.format(_('Search history')),
            'url': plugin.get_url(action='search_history'),
            'thumb': os.path.join(icons, 'search_history.png')
        }
    if plugin.authorization:
        bookmarks_item = {'url': plugin.get_url(action='bookmarks')}
        if webclient.is_logged_in():
            bookmarks_item['label'] = '[{0}]'.format(_('My bookmarks'))
            bookmarks_item['thumb'] = os.path.join(icons, 'bookmarks.png')
        else:
            bookmarks_item['label'] = '[{0}]'.format(_('ex.ua login'))
            bookmarks_item['thumb'] = os.path.join(icons, 'key.png')
        yield bookmarks_item