Ejemplo n.º 1
0
def top(limit=10, offset=0, game=None, period=Period.WEEK):
    q = Qry('videos/top')
    q.add_param(keys.LIMIT, limit, 10)
    q.add_param(keys.OFFSET, offset, 0)
    q.add_param(keys.GAME, game)
    q.add_param(keys.PERIOD, Period.validate(period), Period.WEEK)
    return q
Ejemplo n.º 2
0
def get_top(limit=10, offset=0, game=None, period=Period.WEEK, broadcast_type=BroadcastType.HIGHLIGHT):
    q = Qry('videos/top', use_token=False)
    q.add_param(keys.LIMIT, limit, 10)
    q.add_param(keys.OFFSET, offset, 0)
    q.add_param(keys.GAME, game)
    q.add_param(keys.PERIOD, Period.validate(period), Period.WEEK)
    q.add_param(keys.BROADCAST_TYPE, BroadcastType.validate(broadcast_type))
    return q
Ejemplo n.º 3
0
def route(list_type, sort_type):
    if sort_type == 'by':
        choices = list()
        if list_type == 'followed_channels':
            choices = [(valid.replace('_', ' ').capitalize(), valid) for valid in SortBy.valid()]
        elif list_type == 'channel_videos':
            choices = [(valid.capitalize().replace('_', ' '), valid) for valid in VideoSort.valid()]
        elif list_type == 'clips':
            choices = [(i18n('popular'), Boolean.TRUE), (i18n('views'), Boolean.FALSE)]
        if choices:
            result = kodi.Dialog().select(i18n('change_sort_by'), [label for label, value in choices])
            if result > -1:
                sorting = utils.get_sort(list_type)
                utils.set_sort(list_type, sort_by=choices[result][1], period=sorting['period'], direction=sorting['direction'])

    elif sort_type == 'period':
        choices = list()
        if list_type == 'top_videos':
            choices = [(valid.replace('_', ' ').capitalize(), valid) for valid in Period.valid()]
        elif list_type == 'clips':
            choices = [(valid.replace('_', ' ').capitalize(), valid) for valid in ClipPeriod.valid()]
        if choices:
            result = kodi.Dialog().select(i18n('change_period'), [label for label, value in choices])
            if result > -1:
                sorting = utils.get_sort(list_type)
                utils.set_sort(list_type, sort_by=sorting['by'], period=choices[result][1], direction=sorting['direction'])

    elif sort_type == 'direction':
        choices = list()
        if list_type == 'followed_channels':
            choices = [(valid.replace('_', ' ').capitalize(), valid) for valid in Direction.valid()]
        if choices:
            result = kodi.Dialog().select(i18n('change_direction'), [label for label, value in choices])
            if result > -1:
                sorting = utils.get_sort(list_type)
                utils.set_sort(list_type, sort_by=sorting['by'], period=sorting['period'], direction=choices[result][1])
    def test_period(self):
        Period.validate(Period.WEEK)
        Period.validate(Period.MONTH)
        Period.validate(Period.ALL)
        Period.validate('week')
        Period.validate('month')
        Period.validate('all')

        with self.assertRaises(ValueError):
            Period.validate(0)
        with self.assertRaises(ValueError):
            Period.validate(-1)
        with self.assertRaises(ValueError):
            Period.validate('')
        with self.assertRaises(ValueError):
            Period.validate('year')
        with self.assertRaises(ValueError):
            Period.validate(9.4124)