def get_song_from_title(self, full_title): youtube = Youtube() song = youtube.get_youtube_video(full_title) if not (song): logger.info('No Match in Youtube. Searching Soundcloud') soundcloud = Soundcloud() song = soundcloud.get_soundcloud_song(full_title) return song
def get_song_list(self, tracks, gmusic=None, strict=False, collect_skipped=False): song_list = [] for tracks in tracks['items']: track = tracks['track'] artist = self.html_parser.unescape(track['artists'][0]['name']) title = self.html_parser.unescape(track['name']) popularity = track['popularity'] song = Song(artist=artist, title=title, spotify_popularity=popularity) if gmusic: first_result = None try: first_result = gmusic.search_song(song, strict) if first_result is None: raise ValueError('No result from Google Music') except Exception as e: logger.debug('Exception: {}'.format(e)) logger.info( u'Skipped {}. Added to to Watch Playlist'.format( song.full_title)) if collect_skipped: youtube = Youtube(secure=False) if song.youtube_id is None: youtube_video = youtube.get_youtube_video( full_title=song.full_title) if youtube_video: song.youtube_id = youtube_video.youtube_id song.video_link = "http://www.youtube.com/watch?v={}".format( youtube_video.youtube_id) if song.youtube_id: if youtube.to_watch_playlist is None: youtube.to_watch_playlist = youtube.get_playlist( 'https://www.youtube.com/playlist?list={}'. format(Config.YOUTUBE_TO_WATCH_PLAYLIST)) existing_ids = youtube.to_watch_playlist.song_df.youtube_id.values if song.youtube_id not in existing_ids: ToDoist.ToDoist().add_item( item=song.video_link, project_name=Config. TODOIST_YOUTUBE_COLLECT_PROJECT) song.google_music_store_id = gmusic.get_store_id(first_result) song.google_music_rating = gmusic.get_google_rating( first_result) song_list.append(song) return song_list