def create_channel_and_get_first_video(artist_name): """ Constructs a new channel from a given seed artist, and returns first video that should be displayed """ # Take care of the channel stuff channel = create_channel(artist_name) playlist_info = echonest.start_dynamic_playlist(artist_name) channel.echonest_session_id = playlist_info['session_id'] channel.save() rval = {} rval['channel'] = channel # Get the video! videos = youtube.find_music_videos(playlist_info['artist_name'], playlist_info['song_title'], 1) if videos is None: for _ in xrange(MAX_FIRST_VIDEO_RETRY_SEARCH_ATTEMPT): song_info = echonest.get_next_song_dynamic_playlist(channel.echonest_session_id, channel.seed_artist) videos = youtube.find_music_videos(song_info['artist_name'], song_info['song_title'], 1) if videos is not None: # We're done here, move along... break time.sleep(RETRY_WAIT_TIME) if videos != None: rval['video_info'] = videos[0] rval['artist'] = playlist_info['artist_name'] rval['song'] = playlist_info['song_title'] return rval
def search_and_create_video(artist_name, song_name, channel_hash): """ Searches YouTube for a video for a given artist and song title, and then saves a corresponding music video object in the persistence layer. Video object is then returned """ # Look for a music video on youtube videos = youtube.find_music_videos(artist_name, song_name, 1) if videos != None: # Save video to DB video_info = videos[0] video = create_video(artist_name, song_name, video_info['source_url'], video_info['thumbnail_url'], channel_hash) return video return None