def previous_song(): if queue.previous: speech = 'playing previously played song' prev_stream = queue.step_back() dump_stream_info() return audio(speech).play(prev_stream) else: return audio('There are no songs in your playlist history.')
def next_song(): if queue.up_next: speech = 'playing next queued song' next_stream = queue.step() _infodump('Stepped queue forward to {}'.format(next_stream)) dump_stream_info() return audio(speech).play(next_stream) else: return audio('There are no more songs in the queue')
def pause(): seconds = current_stream.offsetInMilliseconds / 1000 msg = 'Paused the Playlist on track {}, offset at {} seconds'.format( queue.current_position, seconds) _infodump(msg) dump_stream_info() return audio(msg).stop().simple_card(msg)
def restart_track(): if queue.current: speech = 'Restarting current track' dump_stream_info() return audio(speech).play(queue.current, offset=0) else: return statement('There is no current song')
def play_song(uri): response = subprocess.Popen(["youtube-dl", uri, "-j"], stdout=subprocess.PIPE) raw = json.loads(response.stdout.read()) source = '' for format in raw['formats']: if format['ext'] == 'mp4': source = format['url'] return audio().play(source)
def nearly_finished(): next_id = queue.up_next() if next_id is not None: stream_url = api.get_stream_url(next_id) return audio().enqueue(stream_url) return empty_response()
def stop(): # try: # firstname = session.attributes['firstname'] # except KeyError: # firstname = 'my friend' # bye_message = render_template("bye", firstname=firstname) bye_message = render_template("bye") return audio(bye_message).clear_queue(stop=True)
def e_dance(): speech_text = "Model 4 says it's a dance party!" stream_url = 'https://archive.org/download/mc_hammer_202012_202012/mc_hammer.mp3' ser.write(b'd') client.send({'type': 'dance', 'foo': [1, 2, 3, 4, 5]}) #return statement(speech_text).simple_card('Model 4', speech_text) return audio(speech_text).play(stream_url)
def test_custom_token(self): """ Check to see that the provided opaque token remains constant""" token = "hello_world" audio_item = audio()._audio_item(stream_url='https://fakestream', offset=10, opaque_token=token) self.assertEqual(token, audio_item['stream']['token']) self.assertEqual(10, audio_item['stream']['offsetInMilliseconds'])
def loop_off(): if len(queue.song_ids) == 0: return statement("There are no songs in the queue.") first_song_id = queue.loop_mode(False) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def funky(): logger.info('Hitting the funky intent.') speech = "Oh yeah... feeling funky!" stream_url = config['funky_music_url'] hue_url = 'https://maker.ifttt.com/trigger/' + \ config['funky_ifttt_url'] + '/with/key/' + config['secret_ifttt_key'] pause_the_lights(hue_url, 1) return audio(speech).play(stream_url)
def demo(): speech = ("You got it bud!", "Let's get this party started", "Let's go amigos!", "Get ready for a good time!", "Awesome, I love this song!", "I'm so excited!", "You got it buddy") stream_url = 'https://ia601500.us.archive.org/34/items/DESPACITOBASSBOOSTEDdespacito2/DESPACITO%20-%20BASS%20BOOSTED%20%28despacito%202%29.mp3' return audio(speech[np.random.randint(0, len(speech))]).play(stream_url, offset=0)
def loop_off(): if len(queue.song_ids) == 0: return statement(render_template("loop_text")) first_song_id = queue.loop_mode(False) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def nearly_finished(): if queue.up_next: _infodump('Alexa is now ready for a Next or Previous Intent') # dump_stream_info() next_stream = queue.up_next _infodump('Enqueueing {}'.format(next_stream)) return audio().enqueue(next_stream) else: _infodump('Nearly finished with last song in playlist')
def shuffle_off(): if len(queue.song_ids) == 0: return statement(render_template("shuffle_off")) # Start streaming the first track in the new shuffled list first_song_id = queue.shuffle_mode(False) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def _play_track(idx): print('play track index #%d' % idx) t = tracks[idx] url = t['urls'][0].replace('http', 'https') url = url.replace('s3.castbox.fm', 'd1asnxkov2i2k7.cloudfront.net') title = t['title'] print('url = %s' % url) resp = audio('RoboTalk. %s' % title).play(url) return resp
def nearly_finished(): redis_conn = get_redis_conn_pool() queue_key = REMIX_QUEUE_PREFIX next_stream = redis_conn.lpop(queue_key) if next_stream: _infodump("发现下一个播放队列") return audio().enqueue(next_stream) else: _infodump('Nearly finished with last reminx in playlist')
def shuffle_on(): if len(queue.song_ids) == 0: return statement("There are no songs to shuffle.") # Start streaming the first track in the new shuffled list first_song_id = queue.shuffle_mode(True) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def play_audio(guest_artist): session.attributes['guest_artist'] = guest_artist artist_request = guest_artist stream_url = get_url(artist_request) if not stream_url: no_result = render_template('no result', guest_artist=guest_artist) return question(no_result) speech = "Here's one of my favorites" return audio(speech).play(stream_url, offset=0)
def play_artist_radio(artist_name): # TODO: Handle track duplicates? tracks = api.get_station_tracks("IFL") # Get a streaming URL for the first song first_song_id = queue.reset(tracks) stream_url = api.get_stream_url(first_song_id) speech_text = "Playing music from your personalized station" return audio(speech_text).play(stream_url)
def playRandomAudio(): # get welcome message from template if request["locale"] == "es-MX": speech = render_template('welcome_message_es') else: speech = render_template('welcome_message_en') logger.debug("speech: " + speech) # play a random audio file from my S3 bucket stream_url = getRandomAudio(s3, logger) return audio(speech).play(stream_url)
def chileNews(): # get welcome message from template if request["locale"] == "es-MX": speech = render_template('welcome_message_es') else: speech = render_template('welcome_message_en') logger.debug("speech: " + speech) # play latest newsflash from feed stream_url = getTodayNews() return audio(speech).play(stream_url)
def stop(): """ This method handles Alexa skill stop and cancel requests :return: json for response for Alexa """ try: return audio('Stopping').clear_queue(stop=True) except Exception as err: logging.error(err) return statement('Nothing to stop or cancel.')
def resume(): """ This method handles Alexa skill resume requests :return: json for response for Alexa """ try: return audio('Resuming.').resume() except Exception as err: logging.error(err) return statement('Nothing to resume.')
def resume(): """ This method handles Alexa skill start over requests :return: json for response for Alexa """ try: return audio('Starting over.').start_over() except Exception as err: logging.error(err) return statement('Nothing to start over.')
def stop_audio(): """ This method handles Alexa skill pause requests :return: json for response for Alexa """ try: return audio('Ok, pausing the audio').stop() except Exception as err: logging.error(err) return statement('Nothing to pause.')
def play(): feedurl = 'http://feeds.lds.org/ScriptureStories' parsed = podcastparser.parse(feedurl, urllib.request.urlopen(feedurl)) episode = random.choice(parsed['episodes']) url = episode['enclosures'][0]['url'] url = requests.get(url, allow_redirects=False).headers['location'] url = url.replace('http', 'https') speech = f"Playing Scripture Story {episode['title']}" _infodump(f"{speech} ({url})") return audio(speech).play(url) #, offset=93000)
def launch(): text = 'Welcome to See Be See Radio (Unofficial).' prompt = 'For example say, play Radio One Edmonton' ''' return question(text).reprompt(prompt) \ .simple_card(title='Welcome to CBC Radio (Unofficial)', content='Try asking me to play a station') ''' return audio(text).play( 'https://cbcliveradio-lh.akamaihd.net/i/CBCR1_EDM@372985/master.m3u8')
def search_immediately_term(lied): audio().stop() term = lied.replace("for", "") term = term.replace("search", "") term = term.strip() s = { 'search_query':term.encode('utf-8') } raw = urllib2.urlopen('https://www.youtube.com/results?'+urllib.urlencode(s)) html = BeautifulSoup(raw, "html.parser") videos = html.findAll(match_class(["yt-lockup-title"])) res = [] for video in videos: link = video.findAll('a')[0] res.append([link.text, link['href']]) return play_song('https://www.youtube.com'+str(res[0][1]))
def nearly_finished(): ssconn.scrobble(queue.current) if queue.up_next: _infodump('Alexa is now ready for a Next or Previous Intent') # dump_stream_info() next_stream = sauth.getStreamUrl(queue.up_next) _infodump('Enqueueing {}'.format(next_stream)) return audio().enqueue(next_stream) else: _infodump('Nearly finished with last song in playlist')
def random_song_intent(): """ Alexa plays the random audio from the playlist """ speech = 'Here is a random song from the playlist.' _infodump("random") x = random.randrange(0, 5) stream_url = random_song() _infodump(stream_url) return audio(speech).play(stream_url)
def shuffle_off(): if len(queue.song_ids) == 0: return statement("There are no songs to unshuffle.") api = GMusicWrapper.generate_api() # Start streaming the first track in the new shuffled list first_song_id = queue.shuffle_mode(False) stream_url = api.get_stream_url(first_song_id) return audio().enqueue(stream_url)
def nearly_finished(): with open('playlist.json', 'r') as file: f = json.loads(file.read()) response = subprocess.Popen(["youtube-dl", f[f[0][0]+1][1], "-j"], stdout=subprocess.PIPE) raw = json.loads(response.stdout.read()) source = '' for format in raw['formats']: if format['ext'] == 'mp4': source = format['url'] return audio().enqueue(source)
def play_library(): if api.is_indexing(): return statement("Please wait for your tracks to finish indexing") tracks = api.library.values() first_song_id = queue.reset(tracks) first_song_id = queue.shuffle_mode(True) stream_url = api.get_stream_url(first_song_id) speech_text = "Playing music from your library" return audio(speech_text).play(stream_url)
def start_playlist(): speech = 'Heres a playlist of some sounds. You can ask me Next, Previous, or Start Over' stream_url = queue.start() return audio(speech).play(stream_url)
def test_token_generation(self): """ Confirm we get a new token when setting a stream url """ audio_item = audio()._audio_item(stream_url='https://fakestream', offset=123) self.assertEqual(36, len(audio_item['stream']['token'])) self.assertEqual(123, audio_item['stream']['offsetInMilliseconds'])
def custom_token_intents(): return audio('playing with custom token').play(self.stream_url, opaque_token=self.custom_token)
def play(): return audio('playing').play(self.stream_url)
def stop(): return audio('stopping').clear_queue(stop=True)
def resume(): return audio('Resuming.').resume()
def pause(): return audio('Paused the stream.').stop()
def george_michael(): speech = 'yeah you got it!' stream_url = 'https://ia800203.us.archive.org/27/items/CarelessWhisper_435/CarelessWhisper.ogg' return audio(speech).play(stream_url)
def demo(): speech = "Here's one of my favorites" stream_url = 'https://www.vintagecomputermusic.com/mp3/s2t9_Computer_Speech_Demonstration.mp3' return audio(speech).play(stream_url, offset=93000)