示例#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)
示例#2
0
 def test_deezer_search_song_valid(self):
     songs = deezer_search("Großstadtgeflüster diadem", TYPE_TRACK)
     self.assertIsInstance(songs, list)
     s = songs[0]
     self.assertSetEqual(set(s.keys()), {'id', 'title', 'album', 'artist'})
     self.assertTrue(s['id'], '730393272')
     self.assertTrue(s['title'], 'Diadem')
     self.assertTrue(s['artist'], 'Grossstadtgeflüster')
     self.assertTrue(s['album'], 'Tips & Tricks')
示例#3
0
    def test_deezer_search_album_valid(self):
        albums = deezer_search("Coldplay", TYPE_ALBUM)
        self.assertIsInstance(albums, list)
        for album in albums:
            self.assertSetEqual(set(album.keys()), {'id', 'id_type', 'album', 'album_id', 'img_url', 'artist', 'title', 'preview_url'})

        found_album_names = [x['album'] for x in albums]
        known_album_names = ['Parachutes', 'X&Y', 'A Head Full of Dreams']
        for known_album_name in known_album_names:
            self.assertIn(known_album_name, found_album_names)
示例#4
0
def search():
    """
    searches for available music in the Deezer library
    para:
        type: track|album|album_track
        query: search query
    return:
        json: [ { artist, id, (title|album) } ]
    """
    user_input = request.get_json(force=True)
    results = deezer_search(user_input['query'], user_input['type'])
    return jsonify(results)
示例#5
0
 def test_deezer_search_song_valid(self):
     songs = deezer_search("Großstadtgeflüster diadem", TYPE_TRACK)
     self.assertIsInstance(songs, list)
     s = songs[0]
     self.assertSetEqual(set(s.keys()), {'preview_url', 'artist', 'id', 'id_type', 'album_id', 'title', 'img_url', 'album'})
     self.assertTrue(s['id'], '730393272')
     self.assertTrue(s['title'], 'Diadem')
     self.assertTrue(s['artist'], 'Grossstadtgeflüster')
     self.assertTrue(s['album'], 'Tips & Tricks')
     self.assertTrue(s['preview_url'], 'https://cdns-preview-6.dzcdn.net/stream/c-6abdd540dd7e7f02d2c4d21537709c23-3.mp3')
     self.assertTrue(s['album_id'], '107261872')
     self.assertTrue(s['id_type'], 'track')
示例#6
0
 def test_download_song_valid(self):
     song_infos = deezer_search("faber tausendfrankenlang", TYPE_TRACK)[0]
     song = get_song_infos_from_deezer_website(TYPE_TRACK, song_infos['id'])
     try:
         os.remove(test_song)
     except FileNotFoundError:
         # if we remove a file that does not exist
         pass
     download_song(song, test_song)
     file_exists = os.path.exists(test_song)
     self.assertEqual(file_exists, True)
     file_type = magic.from_file(test_song)
     self.assertEqual(file_type, "Audio file with ID3 version 2.3.0, contains:MPEG ADTS, layer III, v1, 320 kbps, 44.1 kHz, Stereo")
     os.remove(test_song)
示例#7
0
 def test_download_song_valid_flac(self):
     config['deezer']['flac_quality'] = "True"
     song_infos = deezer_search("faber tausendfrankenlang", TYPE_TRACK)[0]
     song = get_song_infos_from_deezer_website(TYPE_TRACK, song_infos['id'])
     try:
         os.remove(test_song)
     except FileNotFoundError:
         # if we remove a file that does not exist
         pass
     download_song(song, test_song)
     file_exists = os.path.exists(test_song)
     self.assertEqual(file_exists, True)
     file_type = magic.from_file(test_song)
     self.assertEqual(file_type, 'Audio file with ID3 version 2.3.0, contains:FLAC audio bitstream data, 16 bit, stereo, 44.1 kHz, 10062444 samples')
     os.remove(test_song)
示例#8
0
 def test_deezer_search_album_invalid_no_song_found(self):
     songs = deezer_search("8f49834zf934fdshfkhejw", TYPE_ALBUM)
     self.assertIsInstance(songs, list)
     self.assertListEqual(songs, [])
示例#9
0
 def test_deezer_search_invalid_search_typ(self):
     songs = deezer_search("Coldplay", "this is a wrong search type")
     self.assertIsInstance(songs, list)
     self.assertListEqual(songs, [])