Пример #1
0
def play_url(url, name):
    """
    Play media on page (scrapes it to find it)

    :param url: The page url
    :param name: Text to display in media player
    """
    video_url = scraper.get_media_url(url)
    if video_url == -1:
        GUI.info_box(u"Vesen", u"Fann ekki upptöku")
    else:
        player.play(video_url, name)
Пример #2
0
def play_url(url, name):
    """
    Play media on page (scrapes it to find it)

    :param url: The page url
    :param name: Text to display in media player
    """
    video_url = scraper.get_media_url(url)
    if video_url == -1:
        GUI.info_box(u"Vesen", u"Fann ekki upptöku")
    else:
        player.play(video_url, name)
Пример #3
0
def play_live_stream(channel, name):
    """
    Play one of the live streams.

    :param channel: The channel/radio station
    :param name: Text to display in media player
    """
    url = scraper.get_live_url(channel)
    if url == -1:
        GUI.info_box(
            sarpur.getLocalizedString(30906),
            sarpur.getLocalizedString(30907),
        )
    else:
        player.play(url, name, live=True)
Пример #4
0
def play_live_stream(category_id, name):
    """
    Play one of the live streams.

    :param category_id: The channel/radio station id (see index())
    :param name: Text to display in media player
    """
    channel_slugs = {
        "1": "ruv",
        "10": "ruv2",
        "2": "ras1",
        "3": "ras2",
        "rondo": "ras3"
    }
    url = scraper.get_live_url(channel_slugs[category_id])
    if url == -1:
        GUI.info_box(u"Vesen", u"Fann ekki straum")
    else:
        player.play(url, name)
Пример #5
0
def view_schedule(channel, date_string):
    """
    Display the available media in category

    :param channel: The channel/radio station
    :param date_string: Display media at this date. Format is %Y%m%d

    TODO: Simplify/extract
    """

    if date_string.startswith('<<'):
        format = "<< %d.%m.%Y"
    elif date_string.endswith('>>'):
        format = "%d.%m.%Y >>"
    else:
        format = None
        date = datetime.today()

    if format:
        date = strptime(date_string, format)

    url = 'https://api.ruv.is/api/schedule/{0}/{1}/'.format(
        channel,
        date.strftime('%Y-%m-%d'),
    )
    shows = requests.get(url).json()

    if 'error' in shows:
        if 'message' in shows:
            GUI.info_box(
                sarpur.getLocalizedString(30906),
                shows['error']['message'],
            )
        else:
            GUI.info_box(
                sarpur.getLocalizedString(30906),
                json.dumps(shows['error']),
            )
        return

    day_before = date + timedelta(days=-1)
    next_day = date + timedelta(days=1)
    INTERFACE.add_dir(u"<< {0}".format(day_before.strftime("%d.%m.%Y")),
                      'view_schedule',
                      channel)
    INTERFACE.add_dir("{0} >>".format((next_day.strftime("%d.%m.%Y"))),
                      'view_schedule',
                      channel)
    for ev in shows['events']:
        if 'start_time' not in ev:
            continue
        showtime = strptime(ev['start_time'], EVENT_DATE_FORMAT)
        end_time = strptime(ev['end_time'], EVENT_DATE_FORMAT)
        in_progress = showtime <= datetime.now() < end_time
        duration = (end_time - showtime).seconds
        in_progress_str = u"[COLOR blue]%s[/COLOR]" % (
            sarpur.getLocalizedString(30908),
        )
        display_show_time = (
            in_progress and in_progress_str or
            showtime.strftime("%H:%M")
        )

        title = u"{1} - {0}".format(
            ev['title'],
            display_show_time,
        )
        original_title = ev.get('orginal_title')
        description = '\n'.join(ev.get('description', []))
        if original_title and description:
            plot = u"{0} - {1}".format(original_title, description)
        elif description:
            plot = description
        elif original_title:
            plot = original_title
        else:
            plot = u""

        image = ev.get('image', ev.get('default_image'))
        meta = {
            'TVShowTitle': title,
            'Premiered': showtime.strftime("%d.%m.%Y"),
            'Plot': plot,
            'Duration': duration,
            'fanart_image': image,
        }
        if 'episode_number' in ev:
            meta['Episode'] = ev['episode_number']
        if 'number_of_episodes' in ev:
            meta['TotalEpisodes'] = ev['number_of_episodes']

        has_passed = ev['program'] and ev['program']['episodes']
        is_available = ev['web_accessible'] and ev['program'] is not None
        is_playable = has_passed and is_available

        if in_progress:
            INTERFACE.add_item(title,
                               'play_live_stream',
                               channel,
                               image=image,
                               extra_info=meta,
                               )

        elif is_playable:
            episode = ev['program']['episodes'][0]
            subtitles = [episode.get('subtitles_url')]
            INTERFACE.add_item(title,
                               'play_video',
                               episode['file'],
                               image=image,
                               extra_info=meta,
                               subtitles=subtitles,
                               )
        else:
            INTERFACE.add_unselectable_item(
                title,
                image=image,
                extra_info=meta
            )