Exemple #1
0
def sign_in(router, params):
    dialog = xbmcgui.Dialog()

    username = dialog.input(_('label.username'), type=xbmcgui.INPUT_ALPHANUM)
    if not username:
        return router.redirect('root', 'index')

    password = dialog.input(_('label.password'), type=xbmcgui.INPUT_ALPHANUM)
    if not password:
        return router.redirect('root', 'index')

    token = router.session.token
    regions = api.regions(token['token'])

    # Try to get region from contract number
    region = None
    if len(username) == 12:
        code = None
        try:
            code = int(username[0:3])
        except ValueError:
            pass
        if code:
            region = next((r for r in regions if r['code'] == code), None)

    # User selects a region
    if not region:
        pos = dialog.select(_('label.city'), list(map(lambda r: r['title'], regions)))
        if pos < 0:
            return router.redirect('root', 'index')
        region = regions[pos]

    token = api.auth(token['token'], username, password, region['extid'])
    utils.write_file('token.json', token)
    router.redirect('root', 'index', token=token)
Exemple #2
0
def show_error(error):
    default_header = _('error.default_header')
    default_message = _('error.default_message')
    if LANG == 'ru':
        header = error.get('header_ui') or default_header
        message = error.get('message_rus') or error.get('message') or default_message
    else:
        header = error.get('header_ui') or default_header
        message = error.get('reason') or error.get('message') or error.get('message_rus') or default_message
        message = message.capitalize()

    dialog = xbmcgui.Dialog()
    return dialog.ok(header, message)
Exemple #3
0
def index(router, params):
    handle = router.session.handle
    limit = utils.addon.getSettingInt('page_limit')
    offset = params.get('offset', 0)

    resp = api.serials(router.session.token['token'], limit, offset)
    serials = []
    for srl in resp['serials']:
        li = xbmcgui.ListItem(label=srl['title'], label2=srl['description'])
        li.setArt({'poster': api.art_url(srl['poster_id'])})
        if srl['fanart_id']:
            li.setArt({'fanart': api.art_url(srl['fanart_id'], 630, 354)})
        li.setInfo('video', dict(title=srl['title'], plot=srl['description']))
        url = router.serials_url('seasons',
                                 id=srl['id'],
                                 serials_offset=offset)
        serials.append((url, li, True))

    # Next page
    if resp['offset'] < resp['total']:
        label = _('li.next_page_left') % (resp['total'] - resp['offset'])
        li = xbmcgui.ListItem(label=label)
        url = router.serials_url('index', offset=resp['offset'])
        serials.append((url, li, True))

    xbmcplugin.addDirectoryItems(handle, serials, len(serials))
    xbmcplugin.endOfDirectory(handle, updateListing=router.session.is_redirect)
    xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_TITLE)
Exemple #4
0
def index(router, params):
    handle = router.session.handle
    limit = utils.addon.getSettingInt('page_limit')
    offset = params.get('offset', 0)
    free = utils.addon.getSettingBool('free_movies_only')

    resp = api.movies(router.session.token['token'], limit, offset, free)
    movies = []
    for mov in resp['movies']:
        li = xbmcgui.ListItem(label=mov['title'], label2=mov['description'])
        li.setArt({'poster': api.art_url(mov['poster_id'])})
        if mov['fanart_id']:
            li.setArt({'fanart': api.art_url(mov['fanart_id'], 630, 354)})
        li.setInfo('video', dict(
            title=mov['title'],
            plot=mov['description']
        ))
        li.setProperty('IsPlayable', 'true')
        url = router.root_url('play', id=mov['id'], hls_id=mov['hls_id'])
        movies.append((url, li, False))

    # Next page
    if resp['offset'] < resp['total']:
        label = _('li.next_page_left') % (resp['total'] - resp['offset'])
        li = xbmcgui.ListItem(label=label)
        url = router.movies_url('index', offset=resp['offset'])
        movies.append((url, li, True))

    xbmcplugin.addDirectoryItems(handle, movies, len(movies))
    xbmcplugin.endOfDirectory(handle)
    xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_TITLE)
Exemple #5
0
def index(router, params):
    handle = router.session.handle
    limit = utils.addon.getSettingInt('page_limit')
    page = params.get('page', 1)

    resp = api.channel_packages(router.session.token['token'], limit, page)
    packages = []
    for pkg in resp['packages']:
        li = xbmcgui.ListItem(label=pkg['title'], label2=pkg['description'])
        li.setArt(dict(
            poster=api.art_url(pkg['poster_id']),
            fanart=api.art_url(pkg['fanart_id'])
        ))
        li.setInfo('video', dict(title=pkg['title'], plot=pkg['description']))
        adult = {'adult': 1} if pkg['adult'] == 'adult' else {}
        url = router.channel_packages_url('channels', id=pkg['id'], packages_page=page, **adult)
        packages.append((url, li, True))

    # Next page
    if page < resp['pages']:
        url = router.channel_packages_url('index', page=page + 1)
        label = _('li.next_page_number') % (page + 1, resp['pages'])
        li = xbmcgui.ListItem(label=label)
        packages.append((url, li, True))

    xbmcplugin.addDirectoryItems(handle, packages, len(packages))
    xbmcplugin.endOfDirectory(handle, updateListing=router.session.is_redirect)
Exemple #6
0
 def wrapper(*args):
     dialog = xbmcgui.DialogProgressBG()
     dialog.create(_('header.loading'), message)
     try:
         resp = func(*args)
     finally:
         dialog.close()
     return resp
Exemple #7
0
def _request(method, url, **kwargs):
    resp = None
    try:
        kwargs.setdefault('timeout', 30)
        resp = requests.request(method, url, **kwargs)
    except ConnectionError:
        msg = _('error.connection_error')
    except ConnectTimeout:
        msg = _('error.connect_timeout')
    except ReadTimeout:
        msg = _('error.read_timeout')
    except RequestException:
        msg = _('error.request_exception')
    if resp == None:
        raise ApiRequestError(msg)

    data = resp.json()
    if 'error' in data:
        raise ApiResponseError(data['error'])
    return data
Exemple #8
0
def sign_in_sms(router, params):
    dialog = xbmcgui.Dialog()

    phone = dialog.input(_('label.phone_number'), type=xbmcgui.INPUT_ALPHANUM)
    if not phone:
        return router.redirect('root', 'index')

    token = router.session.token
    resp = api.sms_auth(token['token'], phone)

    if not resp['send_sms']:
        utils.show_error(resp)

    code = dialog.input(_('label.sms_code'), type=xbmcgui.INPUT_NUMERIC)
    if not code:
        return router.redirect('root', 'index')

    token = api.sms_check(token['token'], phone, resp['region'], resp['agr_id'], code)
    utils.write_file('token.json', token)
    router.redirect('root', 'index', token=token)
Exemple #9
0
def sms_auth(token, phone):
    url = ANDROID_HOST + '/er/ott/get_agreements_by_phone'
    params = {'phone_number': phone}
    resp = _request('get', url, params=params, headers=_headers(token))
    if not resp['principals']:
        raise ApiResponseError(
            {'message': _('error.contract_not_found') % phone})

    url = ANDROID_HOST + '/er/sms/auth'
    region = resp['principals'][0]['domain']
    data = {'phone': phone, 'region': region}
    resp = _request('post', url, headers=_headers(token), data=data)
    result = utils.subset(resp['agreements'], 'send_sms',
                          ('sms_error_text', 'message'),
                          (lambda d: d['agreement'][0]['agr_id'], 'agr_id'))
    result['region'] = region
    return result
Exemple #10
0
def index(router, params):
    handle = router.session.handle
    token = router.session.token
    paginate = utils.addon.getSettingBool('channels_pagination')

    if token['is_bound'] and paginate:
        limit = utils.addon.getSettingInt('page_limit')
        page = params.get('page', 1)
        resp = api.channels(token['token'], limit, page)
    else:
        resp = api.channels_all(token['token'], not token['is_bound'])

    channels = []
    for ch in resp['channels']:
        li = xbmcgui.ListItem(label=ch['title'], label2=ch['description'])
        li.setArt({'poster': api.art_url(ch['poster_id'])})
        li.setInfo(
            'video',
            dict(title=ch['title'],
                 plot=ch['description'],
                 tracknumber=ch['lcn']))
        li.setProperty('IsPlayable', 'true')
        url = router.root_url('play', id=ch['id'], hls_id=ch['hls_id'])
        channels.append((url, li, False))

    # Next page
    if paginate and page < resp['pages']:
        url = router.channels_url('index', page=page + 1)
        label = _('li.next_page_number') % (page + 1, resp['pages'])
        li = xbmcgui.ListItem(label=label)
        channels.append((url, li, True))

    xbmcplugin.addDirectoryItems(handle, channels, len(channels))
    xbmcplugin.endOfDirectory(handle)
    xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_TRACKNUM)
    xbmcplugin.addSortMethod(handle, xbmcplugin.SORT_METHOD_TITLE)
Exemple #11
0
        self.error = {'message': message}


class ApiResponseError(Exception):
    def __init__(self, error):
        super(ApiResponseError, self).__init__(error.get('message'))
        self.error = error


def _headers(token):
    headers = dict(HEADERS)
    headers.update({'X-Auth-Token': token})
    return headers


@show_progress(_('progress.device_registration'))
def token():
    """Requests initial token is_bound=false"""
    url = ANDROID_HOST + '/token/device'
    params = dict(client_id='er_android_device',
                  device_id=DEVICE_ID,
                  timestamp=str(int(time.time())))
    resp = _request('get', url, params=params, headers=HEADERS)
    return utils.subset(resp, 'is_bound', 'token', 'expires')


@cache(CACHE_MAX_AGE)
@show_progress(_('progress.regions'))
def regions(token):
    url = ANDROID_HOST + '/er/misc/domains'
    resp = _request('get', url, headers=_headers(token))
Exemple #12
0
def index(router, _params=None):
    handle = router.session.handle
    token = router.session.token

    if not token:
        token = api.token()
        utils.write_file('token.json', token)

    items = []

    def add_channels_item(label):
        li = xbmcgui.ListItem(label=label)
        li.setInfo('video', dict(plot=_('text.tv_channels')))
        url = router.channels_url('index')
        items.append((url, li, True))

    if token['is_bound']:
        status = api.status(
            token['token'],
            invalidate_cache=(handle == 1),
            cache_condition=lambda d: d.get('is_bound')
        )

        # TODO: handle case with no slot available for device
        if not status['is_bound']:
            api.bind_device(token['token'])

        # Channels
        add_channels_item(_('text.channels'))

        # Channel packages
        li = xbmcgui.ListItem(label=_('text.channel_packages'))
        li.setInfo('video', dict(plot=_('text.channel_packages')))
        url = router.channel_packages_url('index')
        items.append((url, li, True))

        # Movies
        free = utils.addon.getSettingBool('free_movies_only')
        label = _('text.free_movies') if free else _('text.movies')
        li = xbmcgui.ListItem(label=label)
        url = router.movies_url('index')
        items.append((url, li, True))

        # Serials
        li = xbmcgui.ListItem(label=_('text.serials'))
        url = router.serials_url('index')
        items.append((url, li, True))
    else:
        # Sign in
        url = router.root_url('sign_in')
        li = xbmcgui.ListItem(label=_('li.sign_in'))
        items.append((url, li, True))

        # Sign in by SMS
        url = router.root_url('sign_in_sms')
        li = xbmcgui.ListItem(label=_('label.sign_in_sms'))
        items.append((url, li, True))

        # Channels
        add_channels_item(_('li.public_channels'))

    xbmcplugin.addDirectoryItems(handle, items, len(items))
    xbmcplugin.endOfDirectory(handle, updateListing=router.session.is_redirect)
Exemple #13
0
 def add_channels_item(label):
     li = xbmcgui.ListItem(label=label)
     li.setInfo('video', dict(plot=_('text.tv_channels')))
     url = router.channels_url('index')
     items.append((url, li, True))