Exemple #1
0
def download_spotify_playlist_and_queue_and_zip(playlist_name, playlist_id,
                                                add_to_playlist, create_zip):
    songs = get_songs_from_spotify_website(playlist_id)
    songs_absolute_location = []
    print(f"We got {len(songs)} songs from the Spotify playlist")
    for i, song_of_playlist in enumerate(songs):
        report_progress(i, len(songs))
        # song_of_playlist: string (artist - song)
        try:
            track_id = deezer_search(
                song_of_playlist,
                TYPE_TRACK)[0]['id']  #[0] can throw IndexError
            song = get_song_infos_from_deezer_website(TYPE_TRACK, track_id)
            absolute_filename = download_song_and_get_absolute_filename(
                TYPE_PLAYLIST, song, playlist_name)
            songs_absolute_location.append(absolute_filename)
        except (IndexError, Deezer403Exception, Deezer404Exception) as msg:
            print(msg)
            print(
                f"Could not find Spotify song ({song_of_playlist}) on Deezer?")
            # return
    update_mpd_db(songs_absolute_location, add_to_playlist)
    songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
    if create_zip:
        return [create_zip_file(songs_with_m3u8_file)]
    return make_song_paths_relative_to_mpd_root(songs_absolute_location)
def download_deezer_album_and_queue_and_zip(album_id, add_to_playlist,
                                            create_zip):
    songs = get_song_infos_from_deezer_website(TYPE_ALBUM, album_id)
    songs_absolute_location = []
    for i, song in enumerate(songs):
        report_progress(i, len(songs))
        assert type(song) == dict
        absolute_filename = get_absolute_filename(TYPE_ALBUM, song)
        songs_absolute_location.append(absolute_filename)
    update_mpd_db(songs_absolute_location, add_to_playlist)
    if create_zip:
        return [create_zip_file(songs_absolute_location)]
    return make_song_paths_relative_to_mpd_root(songs_absolute_location)
Exemple #3
0
def download_deezer_playlist_and_queue_and_zip(playlist_id, add_to_playlist,
                                               create_zip):
    playlist_name, songs = parse_deezer_playlist(playlist_id)
    songs_absolute_location = []
    for i, song in enumerate(songs):
        report_progress(i, len(songs))
        absolute_filename = download_song_and_get_absolute_filename(
            TYPE_PLAYLIST, song, playlist_name)
        songs_absolute_location.append(absolute_filename)
    update_mpd_db(songs_absolute_location, add_to_playlist)
    songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
    if create_zip:
        return [create_zip_file(songs_with_m3u8_file)]
    return make_song_paths_relative_to_mpd_root(songs_absolute_location)
Exemple #4
0
def download_deezer_favorites(user_id: str, add_to_playlist: bool,
                              create_zip: bool):
    songs_absolute_location = []
    output_directory = f"favorites_{user_id}"
    favorite_songs = get_deezer_favorites(user_id)
    for i, fav_song in enumerate(favorite_songs):
        report_progress(i, len(favorite_songs))
        try:
            song = get_song_infos_from_deezer_website(TYPE_TRACK, fav_song)
            absolute_filename = download_song_and_get_absolute_filename(
                TYPE_PLAYLIST, song, output_directory)
            songs_absolute_location.append(absolute_filename)
        except (IndexError, Deezer403Exception, Deezer404Exception) as msg:
            print(msg)
            print(f"Could not find song ({fav_song}) on Deezer?")
    update_mpd_db(songs_absolute_location, add_to_playlist)
    songs_with_m3u8_file = create_m3u8_file(songs_absolute_location)
    if create_zip:
        return [create_zip_file(songs_with_m3u8_file)]
    return make_song_paths_relative_to_mpd_root(songs_absolute_location)