Exemple #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)
Exemple #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)
Exemple #3
0
def main():

    parser = argparse.ArgumentParser()
    parser.add_argument("-g",
                        "--gui",
                        help="Initialize GUI version of the game.")
    parser.add_argument(
        "--file",
        help=
        "Path to file. Read the grid from file. Size arguments will be ignored.",
    )
    parser.add_argument(
        "--size",
        help=
        "Input grid size in format: X-Y or just X if it's a rectangle. Default 50-50",
        default="8-8",
    )
    parser.add_argument(
        "--max",
        help="Input the number of maximum generations. Default 100",
        type=int,
        default=100,
    )
    parser.add_argument(
        "--cell_size",
        help="Input cell size. Only for GUI version. Default 50",
        type=int,
        default=50,
    )

    args = parser.parse_args()

    if args.file:
        life = GameOfLife.from_file(args.file, args.max)
    else:
        grid_size = (int(args.size.split("-")[0]),
                     int(args.size.split("-")[1]))
        life = GameOfLife(
            size=grid_size,
            randomize=True,
            max_generations=args.max,
            cell_size=args.cell_size,
        )

    if args.gui:
        ui = GUI(life)
    else:
        ui = Console(life)

    ui.run()
Exemple #4
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)
Exemple #5
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)
Exemple #6
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
            )
Exemple #7
0
                  env=Tetris,
                  env_args=env_args,
                  n_actions=7)
    agent.update_root(game, ngames)
else:
    agent = None

if save:
    saver = DataSaver(save_dir, save_file, cycle)
    saver_all = DataSaver(save_dir, 'tree', cycle)
    agent.saver = saver_all

tracker = ScoreTracker()

if gui:
    G = GUI()

if print_board_to_file:
    board_output = open('board_output', 'wb')
"""
MAIN GAME LOOP
"""
while True:
    if interactive:
        game.printState()
        print('Current score:%d' % game.getScore())
        action = int(input('Play:'))

    elif agent:

        if printboard:
Exemple #8
0
#!/usr/bin/env python
# encoding: UTF-8


import sarpur
import sarpur.scraper as scraper
import util.player as player
from util.gui import GUI


INTERFACE = GUI(sarpur.ADDON_HANDLE, sarpur.BASE_URL)

def index():
    """
    .. py:function:: index()

    The front page (i.e. the first one the user sees when opening the plugin)
    """

    INTERFACE.addItem('Bein útsending RÚV', 'play_live', 'ruv')
    INTERFACE.addItem('Bein útsending RÚV Íþróttir', 'play_live', 'ruvSport')
    INTERFACE.addItem('Bein útsending RÁS 1', 'play_live', 'ras1')
    INTERFACE.addItem('Bein útsending RÁS 2', 'play_live', 'ras2')
    INTERFACE.addItem('Bein útsending Rondó', 'play_live', 'rondo')
    INTERFACE.addDir('Nýtt', 'view_group', '/')
    INTERFACE.addDir('Fréttir', 'view_group', '/flokkar/frettir')
    INTERFACE.addDir('Íþróttir', 'view_group', '/flokkar/ithrottir')
    INTERFACE.addDir('Barnaefni', 'view_group', '/flokkar/born')
    INTERFACE.addDir('Rás 1', 'view_group', '/ras1')
    INTERFACE.addDir('Rás 2', 'view_group', '/ras2')
    INTERFACE.addDir('Sjónvarpsefni', 'view_group', '/flokkar/1')