示例#1
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)
示例#2
0
 def test_get_deezer_favorites_userid_valid(self):
     user_id = "705965861"
     songs = get_deezer_favorites(user_id)
     self.assertIsInstance(songs, list)
     for song in songs:
         self.assertIsInstance(song, int)
示例#3
0
 def test_get_deezer_favorites_userid_api_error(self):
     user_id = "0"
     with self.assertRaises(Exception):
         get_deezer_favorites(user_id)
示例#4
0
 def test_get_deezer_favorites_userid_not_numeric(self):
     user_id = "123notnumeric"
     with self.assertRaises(Exception):
         get_deezer_favorites(user_id)