Skip to content

Commit

Permalink
Fix broken download functionality
Browse files Browse the repository at this point in the history
tries to fix this #66. Removes the ability to download flac files
  • Loading branch information
kmille committed Nov 26, 2021
1 parent 5123c02 commit 172f5c6
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 30 deletions.
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
Expand Down
7 changes: 0 additions & 7 deletions app/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@
print(f"ERROR: youtube-dl not found at {config['youtubedl']['command']}")
sys.exit(1)

if "DEEZER_FLAC_QUALITY" in os.environ.keys():
config["deezer"]["flac_quality"] = os.environ["DEEZER_FLAC_QUALITY"]

if "flac_quality" not in config['deezer'] or config['deezer'].getboolean('flac_quality') not in (True, False):
print("ERROR: flac_quality muste be set (True or False)")
sys.exit(1)

if "DEEZER_COOKIE_ARL" in os.environ.keys():
config["deezer"]["cookie_arl"] = os.environ["DEEZER_COOKIE_ARL"]

Expand Down
5 changes: 2 additions & 3 deletions app/deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,8 @@ def download_song(song, output_file):
assert type(song) == dict, "song must be a dict"
assert type(output_file) == str, "output_file must be a str"

song_quality = 9 if song.get("FILESIZE_FLAC") and config['deezer'].getboolean('flac_quality') else \
3 if song.get("FILESIZE_MP3_320") else \
5 if song.get("FILESIZE_MP3_256") else \
song_quality = 3 if song.get("FILESIZE_MP3_320") and song.get("FILESIZE_MP3_320") != '0' else \
5 if song.get("FILESIZE_MP3_256") and song.get("FILESIZE_MP3_256") != '0' else \
1

urlkey = genurlkey(song["SNG_ID"], song["MD5_ORIGIN"], song["MEDIA_VERSION"], song_quality)
Expand Down
3 changes: 0 additions & 3 deletions app/settings.ini.example
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ workers = 4
; login manually using your web browser and take the arl ookie
cookie_arl = [a-f0-9]{192}

; download flac files (if False mp3 is used)
flac_quality = False

; run a query on deezer every N minutes to keep the session alive
keepalive = 60

Expand Down
18 changes: 1 addition & 17 deletions app/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,7 @@ def test_download_song_valid_mp3(self):
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)

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')
self.assertEqual(file_type, "Audio file with ID3 version 2.3.0, contains:MPEG ADTS, layer III, v1, 128 kbps, 44.1 kHz, Stereo")
os.remove(test_song)

def test_download_song_invalid_song_type(self):
Expand Down

0 comments on commit 172f5c6

Please sign in to comment.