Esempio n. 1
0
def queue():
    url = request.query['url']

    if 'slow' in request.query:
        if request.query['slow'] in ["True", "true"]:
            config["slow_mode"] = True
        else:
            config["slow_mode"] = False
        with open('raspberrycast.conf', 'w') as f:
            json.dump(config, f)

    try:
        if getState() != "0":
            logger.info('Adding URL to queue: '+url)
            if (
                    ("youtu" in url and "list=" in url) or
                    ("soundcloud" in url and "/sets/" in url)):
                playlist(url, False, config)
            else:
                queuevideo(url, config)
            return "2"
        else:
            logger.info('No video currently playing, playing url : '+url)
            if (
                    ("youtu" in url and "list=" in url) or
                    ("soundcloud" in url and "/sets/" in url)):
                playlist(url, True, config)
            else:
                launchvideo(url, config, sub=False)
            return "1"
    except Exception as e:
        logger.error('Error in launchvideo or queuevideo function !')
        logger.exception(e)
        return "0"
Esempio n. 2
0
def stream():
    url = request.query['url']
    logger.debug('Received URL to cast: '+url)

    if 'slow' in request.query:
        if request.query['slow'] in ["True", "true"]:
            config["slow_mode"] = True
        else:
            config["slow_mode"] = False
        # TODO: Do we really want to write this to disk?
        with open(config_file, 'w') as f:
            json.dump(config, f)

    try:
        if ('localhost' in url) or ('127.0.0.1' in url):
            ip = request.environ['REMOTE_ADDR']
            logger.debug('''URL contains localhost adress. \
Replacing with remote ip : ''' + ip)
            url = url.replace('localhost', ip).replace('127.0.0.1', ip)

        if 'subtitles' in request.query:
            subtitles = request.query['subtitles']

            if ('localhost' in subtitles) or ('127.0.0.1' in subtitles):
                            ip = request.environ['REMOTE_ADDR']
                            logger.debug(
                                '''Subtitle path contains localhost adress.
Replacing with remote IP.''')
                            subtitles = subtitles\
                                .replace('localhost', ip)\
                                .replace('127.0.0.1', ip)

            logger.debug('Subtitles link is '+subtitles)
            urlretrieve(subtitles, "subtitle.srt")
            launchvideo(url, config, sub=True)
        else:
            logger.debug('No subtitles for this stream')
            if (
                    ("youtu" in url and "list=" in url) or
                    ("soundcloud" in url and "/sets/" in url)):
                playlist(url, True, config)
            else:
                launchvideo(url, config, sub=False)
            return "1"
    except Exception as e:
        logger.error(
            'Error in launchvideo function or during downlading the subtitles')
        logger.exception(e)
        return "0"