Example #1
0
def Broadcast():
    """
    Send audio to *all* cast devices on the network
    """
    Log.Debug('Recieved a call to broadcast an audio clip.')
    params = ['Path']
    values = sort_headers(params, True)
    status = "No clip specified"
    if values is not False:
        do = False
        casts = fetch_devices()
        disconnect = []
        controllers = []
        try:

            for cast in casts:
                if cast['type'] == "audio":
                    mc = MediaController()
                    Log.Debug("We should be broadcasting to " + cast['name'])
                    uri = cast['uri'].split(":")
                    cast = pychromecast.Chromecast(uri[0], int(uri[1]))
                    cast.wait()
                    cast.register_handler(mc)
                    controllers.append(mc)
                    disconnect.append(cast)

            for mc in controllers:
                mc.play_media(values['Path'], 'audio/mp3', )

        except pychromecast.LaunchError, pychromecast.PyChromecastError:
            Log.Debug('Error connecting to host.')
        finally:
Example #2
0
def enable_chromecast():
    """
    Turn on the chromecast
    """
    cast = Chromecast('192.168.1.104')
    cast_name = cast.device.friendly_name
    print("Turning on the '{}' chromecast".format(cast_name))
    if cast:
        media = MediaController()
        cast.register_handler(media)
        time.sleep(1)
        print("Attempting to play media")
        media.play_media('http://upload.wikimedia.org/wikipedia/commons/7/7f/Pug_portrait.jpg', 'jpg')  # nopep8
        time.sleep(30)
        cast.quit_app()
Example #3
0
def enable_chromecast():
    """
    Turn on the chromecast
    """
    cast = Chromecast('192.168.1.104')
    cast_name = cast.device.friendly_name
    print("Turning on the '{}' chromecast".format(cast_name))
    if cast:
        media = MediaController()
        cast.register_handler(media)
        time.sleep(1)
        print("Attempting to play media")
        media.play_media(
            'http://upload.wikimedia.org/wikipedia/commons/7/7f/Pug_portrait.jpg',
            'jpg')  # nopep8
        time.sleep(30)
        cast.quit_app()
Example #4
0
def Test():
    values = {'Path': R(TEST_CLIP)}
    casts = fetch_devices()
    status = "Test successful!"
    try:
        for cast in casts:
            if cast['type'] == "audio":
                mc = MediaController()
                Log.Debug("We should be broadcasting to " + cast['name'])
                uri = cast['uri'].split(":")
                cast = pychromecast.Chromecast(uri[0], int(uri[1]))
                cast.wait()
                cast.register_handler(mc)
                mc.play_media(values['Path'], 'audio/mp3')

    except pychromecast.LaunchError, pychromecast.PyChromecastError:
        Log.Debug('Error connecting to host.')
        status = "Test failed!"
Example #5
0
    from os.path import isfile, join
    import random

    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
    imgFile = random.choice(onlyfiles)
    for castName, cast in allCasts.items():
        if castName != "Plantcastf":
            # cast.quit_app()

            # cast.quit_app()
            # print(cast.device)

            castMc = cast.media_controller
            print(castMc.status)

            mc = MediaController()
            cast.register_handler(mc)

            imgFile = onlyfiles[castIndex[castName]]
            castIndex[castName] += 1
            print(castName + " http://" + myIp + ":8000/" + imgFile)
            mc.play_media("http://" + myIp + ":8000/" + imgFile, "Image/jpg")
            # mc.play_media('http://172.22.27.48:8000/TMP/my whole brain is crying - panic - DuBMDLP.gif', 'Image/gif')
            # mc.play_media('http://172.22.27.48:8000/TMP/stupid%20human%20race%20-%20tumblr_mfoumwtO6I1ryw1t1o1_500.gif', 'Image/gif')
            # mc.play_media('https://pbs.twimg.com/media/CNbowwpWIAEe1Sm.jpg', 'Image/jpeg')

            # mi = MediaImage('http://asset-2.soupcdn.com/asset/12903/9698_26b1.jpeg', 100, 100)
            # mi.url
            # mc.play()

            # yt = YouTubeController()
Example #6
0
    import souper
    soup = souper.souperDuper(conf.soup)
    soupNext = soup.grabPart()

while True:
    if soupNext != None:
        soupNext.__next__()
        onlyfiles = list(soup.knownUrls.keys())

    from os import listdir
    from os.path import isfile, join
    import random

    imgFile = random.choice(onlyfiles)
    for castName, cast in allCasts.items():
        if not castName in conf.blacklist:
            castMc = cast.media_controller

            mc = MediaController()
            cast.register_handler(mc)

            if conf.castmode == 'different':
                imgFile = random.choice(onlyfiles)

            if conf.imageSource == 'soup':
                mc.play_media(imgFile, 'Image/jpg')
            else:
                mc.play_media('http://'+ conf.localIp +':8000/'+ imgFile, 'Image/jpg')

    time.sleep(conf.showImageTime)
Example #7
0
while True:
    mypath = '/home/bison/Dropbox/Photos/Motivation'
    from os import listdir
    from os.path import isfile, join
    import random
    onlyfiles = [ f for f in listdir(mypath) if isfile(join(mypath,f)) ]
    imgFile = random.choice(onlyfiles)
    for castName, cast in allCasts.items():
        if castName != 'lockedName':
            #cast.quit_app()
            #print(cast.device)

            castMc = cast.media_controller
            print(castMc.status)

            mc = MediaController()
            cast.register_handler(mc)

            mc.play_media('http://'+ myIp +':8000/'+ imgFile, 'Image/jpg')
            #mc.play_media('http://172.22.27.48:8000/TMP/my whole brain is crying - panic - DuBMDLP.gif', 'Image/gif')
            #mc.play_media('http://172.22.27.48:8000/TMP/stupid%20human%20race%20-%20tumblr_mfoumwtO6I1ryw1t1o1_500.gif', 'Image/gif')
            #mc.play_media('https://pbs.twimg.com/media/CNbowwpWIAEe1Sm.jpg', 'Image/jpeg')

            #mi = MediaImage('http://asset-2.soupcdn.com/asset/12903/9698_26b1.jpeg', 100, 100)
            #mi.url
            #mc.play()

            #yt = YouTubeController()
            #cast.register_handler(yt)
            #yt.play_video(video)
    time.sleep(8.8)
Example #8
0
if sched_url == None:
    usage_die("Need --sched-url")

print("dev_name = " + str(dev_name) + ", sched_url = " + sched_url +
      ", host = " + str(host))
sch = Sched(sched_url)

while True:
    while True:
        print("Locating device dev_name=" + str(dev_name) + ", host = " +
              str(host))

        if dev_name != None:
            cast = pychromecast.get_chromecast(friendly_name=dev_name)
        else:
            cast = pychromecast.Chromecast(host)

        if cast != None:
            print(cast.device)
            break
    try:
        mc = MediaController()
        cast.register_handler(mc)
        sch.cast = cast
        sch.run(mc)
    except Exception as e:
        print("Got exception, sleeping before retry")
        traceback.print_exc(e)
        time.sleep(retry_sleep)
        sch.update_sched()
Example #9
0
while True:
    mypath = '/home/bison/Dropbox/Photos/Motivation'
    from os import listdir
    from os.path import isfile, join
    import random
    onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]
    imgFile = random.choice(onlyfiles)
    for castName, cast in allCasts.items():
        if castName != 'lockedName':
            #cast.quit_app()
            #print(cast.device)

            castMc = cast.media_controller
            print(castMc.status)

            mc = MediaController()
            cast.register_handler(mc)

            mc.play_media('http://' + myIp + ':8000/' + imgFile, 'Image/jpg')
            #mc.play_media('http://172.22.27.48:8000/TMP/my whole brain is crying - panic - DuBMDLP.gif', 'Image/gif')
            #mc.play_media('http://172.22.27.48:8000/TMP/stupid%20human%20race%20-%20tumblr_mfoumwtO6I1ryw1t1o1_500.gif', 'Image/gif')
            #mc.play_media('https://pbs.twimg.com/media/CNbowwpWIAEe1Sm.jpg', 'Image/jpeg')

            #mi = MediaImage('http://asset-2.soupcdn.com/asset/12903/9698_26b1.jpeg', 100, 100)
            #mi.url
            #mc.play()

            #yt = YouTubeController()
            #cast.register_handler(yt)
            #yt.play_video(video)
    time.sleep(8.8)