Browse Source

Fix broken download functionality

tries to fix this #66. Removes the ability to download flac files
pull/62/merge
kmille 2 months ago
parent
commit
172f5c6100
  1. 1
      .github/workflows/tests.yaml
  2. 7
      app/configuration.py
  3. 5
      app/deezer.py
  4. 3
      app/settings.ini.example
  5. 18
      app/tests.py

1
.github/workflows/tests.yaml

@ -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 }}

7
app/configuration.py

@ -24,13 +24,6 @@ if not os.path.exists(config['youtubedl']['command']):
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"]

5
app/deezer.py

@ -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)

3
app/settings.ini.example

@ -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

18
app/tests.py

@ -209,23 +209,7 @@ class TestDeezerMethods(unittest.TestCase):
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):

Loading…
Cancel
Save