示例#1
0
def parse_search_results(data):
    json_data = json.loads(data)
    show_list = []
    for show in json_data['results'].get('items', []):
        if show.get('_entity') == 'show':
            s = classes.Series()
            s.num_episodes = show.get('episodeCount')
            s.title = show.get('title')
            additional_title = ''
            if show.get('status'):
                additional_title = show['status'].get('title', '').lower()
            title_match = re.match('^[Ss]eries\\s?(?P<series>\\w+)',
                                   additional_title)
            if title_match:
                s.title += ' Series ' + title_match.groups()[0]
            s.url = show.get('_links', '').get('deeplink', '').get('href')
        elif show.get('_entity') == 'video':
            s = classes.Program()
            s.title = show.get('showTitle')
            s.duration = show.get('duration')
            s.house_number = show.get('houseNumber')
            s.url = show.get('_links').get('self').get('href')
        else:
            continue
        s.description = show.get('title')
        s.thumb = show.get('thumbnail')
        show_list.append(s)
    if len(show_list) == 0:
        s = classes.Series()
        s.title = 'No results!'
        s.num_episodes = 0
        s.dummy = True
        show_list.append(s)
    return show_list
示例#2
0
def create_fav_category(title, feed_url):
    s = classes.Series()
    s.title = title
    s.feed_url = feed_url
    s.require_login = True
    s.favourite = True
    return s
示例#3
0
def parse_programme_from_feed(data, params):
    json_data = json.loads(data)
    show_list = []
    for show in json_data.get('items'):
        if show.get('_entity') == 'show':
            s = classes.Series()
            s.num_episodes = show.get('episodeCount')
            s.title = show.get('title')
            additional_title = ''
            if show.get('status'):
                additional_title = show['status'].get('title', '').lower()
            title_match = re.match('^[Ss]eries\\s?(?P<series>\\w+)',
                                   additional_title)
            if title_match:
                s.title += ' Series ' + title_match.groups()[0]
            s.url = show.get('_links', '').get('deeplink', '').get('href')
        elif show.get('_entity') == 'video':
            s = classes.Program()
            s.title = show.get('showTitle')
            s.duration = show.get('duration')
            s.house_number = show.get('houseNumber')
            s.url = show.get('_links').get('self').get('href')
            parse_subtitle(s, show)
        else:
            continue
        s.description = show.get('title')
        s.thumb = show.get('thumbnail')
        fanart = params.get('fanart')
        if fanart:
            s.fanart = params.get('fanart')
        else:
            s.fanart = s.thumb
        show_list.append(s)
    return show_list
 def test_get_list_title(self):
     s = classes.Series()
     s.title = 'Foo Bar'
     s.num_episodes = 3
     observed = s.get_list_title()
     expected = 'Foo Bar (3)'
     self.assertEqual(expected, observed)
示例#5
0
def list_series():
    """
    Create and return list of series objects
    """
    data = cache.getData(name=ADDON_ID, url=config.TVSERIES_URL)

    if isinstance(data, list):
        return data

    listing = []
    for show in data['items']:
        if show.get('containsSeason'):
            for season in reversed(show['containsSeason']):
                s = classes.Series()
                s.multi_season = len(show['containsSeason']) > 1
                s.season_slug = season.get('slug')
                s.series_name = utils.ensure_ascii(show.get('name'))
                s.season_name = utils.ensure_ascii(season.get('name'))
                s.series_slug = season['partOfSeries'].get('slug')
                s.fanart = show['image']['sizes'].get('w1280')
                s.thumb = season['image']['sizes'].get('w480')
                s.genre = season['genre'].get('name')
                s.genre_slug = season['genre'].get('slug')
                s.title = s.get_title()
                s.desc = season.get('description')
                listing.append(s)

    cache.getData(name=ADDON_ID, url=config.TVSERIES_URL, data=listing)
    return listing
示例#6
0
def create_series(entry):
    s = classes.Series()
    s.entry_type = entry.get('type')
    s.title = str(entry.get('name'))
    s.id = entry.get('id', '').split("/")[-1]
    s.thumb = entry.get('thumbnailUrl')
    s.description = entry.get('description')
    s.rating = entry.get('contentRating', '').upper()
    s.country = entry.get('country', {}).get('name')
    genres = [
        genre.get('name')
        for genre in entry.get('taxonomy', {}).get('genre', [])
    ]
    s.category = ' / '.join(genres)
    genres = [
        genre.get('name')
        for genre in entry.get('taxonomy', {}).get('collection', [])
    ]
    s.sub_category = ' / '.join(genres)
    seasons = entry.get('containSeasons', [])
    if seasons:
        s.multi_series = 'True'
    else:
        s.single_series = 'True'
    s.feed_url = config.SERIES_URL.replace('[SERIESID]', s.id)
    return s
示例#7
0
def create_search(entry, name):
    s = classes.Series()
    s.title = str(entry.get('name'))
    s.feed_url = entry.get('feedUrl').replace('[QUERY]', name)
    json_data = json.loads(fetch_url(s.feed_url))
    s.num_episodes = json_data.get('totalNumberOfItems')
    return s
示例#8
0
def create_page(begin, size, feed_url):
    s = classes.Series()
    end = begin + size - 1
    s.title = 'Next page ({0} - {1})'.format(begin, end)
    s.page_begin = begin
    s.page_size = size
    s.feed_url = feed_url
    return s
示例#9
0
def parse_programs_from_feed(data, from_series_list=False):
    json_data = json.loads(data)
    programs_list = []
    serieslist_data = []

    fanart = json_data.get('thumbnail')
    if json_data.get('type') == 'series':
        item_list = json_data['_embedded']['selectedSeries']['_embedded'].get(
            'videoEpisodes')
        if not item_list:  # let's see if there are 'extras' instead
            item_list = json_data['_embedded']['selectedSeries'][
                '_embedded'].get('videoExtras')
        serieslist_data = json_data['_embedded']['seriesList']
    else:
        item_list = [json_data['_embedded']['highlightVideo']]

    for item in item_list:
        p = classes.Program()
        title = item.get('seriesTitle')
        if title:
            p.title = title
        else:
            p.title = item.get('title')

        parse_subtitle(p, item)
        p.house_number = item.get('houseNumber')
        p.description = item.get('description')
        p.thumb = item.get('thumbnail')
        p.fanart = fanart
        p.url = item['_links']['self'].get('href')
        p.rating = item.get('classification')
        p.duration = item.get('duration')
        p.captions = item.get('captions')
        p.set_date(item.get('pubDate'))
        p.set_expire(item.get('expireDate'))

        programs_list.append(p)

    sorted_programs = sorted(programs_list,
                             key=lambda x: x.get_date_time(),
                             reverse=True)
    if len(serieslist_data) > 1 and not from_series_list:
        for series in serieslist_data:
            if series.get('id') == json_data['_embedded'][
                    'selectedSeries'].get('id'):
                continue
            s = classes.Series()
            s.title = series.get('title')
            s.url = series.get('_links', '').get('deeplink', '').get('href')
            s.description = series.get('description')
            s.thumb = series.get('thumbnail')
            s.num_episodes = 0
            s.from_serieslist = True
            s.fanart = fanart
            sorted_programs.append(s)

    return sorted_programs
示例#10
0
def create_collection(entry):
    s = classes.Series()
    s.title = str(entry.get('name'))
    s.description = entry.get('description')
    s.feed_url = entry.get('feedUrl')
    s.item_type = entry.get('type')
    thumbs = entry.get('thumbnails', [])
    s.fanart = get_attr(thumbs, 'name', 'Background 2X', 'contentUrl')
    s.thumb = get_attr(thumbs, 'name', 'Thumbnail Large', 'contentUrl')
    return s
示例#11
0
def get_category(params):
    """Fetch a given top level category from the index.
    This is usually programs and movies.
    """
    sub_cat = False
    category = params.get('category')
    if not category:
        sub_cat = True
        category = params.get('item_type')  # genre
        if category == 'FilmGenre':
            category = 'MovieGenre'
    utils.log("Fetching category: %s" % category)
    json_data = get_config()
    category_data = json_data.get('contentStructure').get('screens').get(
        category)
    listing = []

    for c in category_data.get('rows'):
        if 'feeds' in c:
            data_list = c.get('feeds')
        else:
            data_list = [c]
        for data in data_list:
            title = data.get('name')
            if (title == 'Football Highlights'
                    and params.get('title') != 'Sport'):
                continue
            s = classes.Series()
            s.title = title
            layout = data.get('layout')
            if not layout:
                continue
            if layout.get('rowType') in ['policyChanges']:
                continue
            s.item_type = layout.get('itemType')
            s.feed_url = data.get('feedUrl')
            if s.item_type in ['genre']:
                s.feed_url += '&range=1-100'
            display = data.get('display')
            if display:
                if display.get('loggedIn'):
                    s.require_login = '******'
            if sub_cat:
                s.sub_category = 'True'
                if '[GENRE]' in s.feed_url:
                    s.feed_url = s.feed_url.replace('[GENRE]',
                                                    params.get('title'))
                if '[CHANNEL]' in s.feed_url:
                    s.feed_url = s.feed_url.replace('[CHANNEL]',
                                                    params.get('feed_id'))

            listing.append(s)
    return listing
示例#12
0
def create_channel(entry):
    s = classes.Series()
    s.title = str(entry.get('name'))
    s.feed_id = entry.get('feedId')
    s.thumb = entry.get('thumbnailUrl')
    return s
示例#13
0
 def test_get_sort_title(self):
     s = classes.Series()
     s.title = 'The Foo'
     observed = s.get_sort_title()
     expected = 'foo'
     self.assertEqual(expected, observed)
示例#14
0
 def test_get_list_title(self):
     s = classes.Series()
     s.title = 'Foo Bar'
     observed = s.get_list_title()
     expected = 'Foo Bar (1)'
     self.assertEqual(expected, observed)
示例#15
0
 def test_get_title(self):
     s = classes.Series()
     s.title = '&lt;spam&amp;eggs&gt;'
     observed = s.get_title()
     expected = '<spam&eggs>'
     self.assertEqual(expected, observed)
示例#16
0
def create_season(entry, thumb):
    s = classes.Series()
    s.title = str(entry.get('name'))
    s.thumb = thumb
    s.feed_url = entry.get('feedUrl')
    return s
示例#17
0
def create_genre_index(entry):
    s = classes.Series()
    s.title = str(entry.get('name'))
    s.item_type = entry.get('type')
    s.thumb = entry.get('thumbnailUrl')
    return s