Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Streamrip ERROR exception on reading artwork header #714

Open
samuelmarinsoto opened this issue Jul 11, 2024 · 10 comments
Open

[BUG] Streamrip ERROR exception on reading artwork header #714

samuelmarinsoto opened this issue Jul 11, 2024 · 10 comments
Labels
bug Something isn't working

Comments

@samuelmarinsoto
Copy link
Contributor

Describe the bug

Streamrip errors on downloading artwork for artists on deezer and qobuz (haven't tested others), and throws an exception about the header being wrong

Command Used

rip url https://play.qobuz.com/artist/403888

Debug Traceback

https://bin.dembased.xyz/4tisrcjm.txt (its about 6500 lines with -vvv, exceeds max body length)

Config File

[downloads]
# Folder where tracks are downloaded to
folder = "/mnt/nas/media/musica/dl"
# Put Qobuz albums in a 'Qobuz' folder, Tidal albums in 'Tidal' etc.
source_subdirectories = true
# Put tracks in an album with 2 or more discs into a subfolder named `Disc N` 
disc_subdirectories = true
# Download (and convert) tracks all at once, instead of sequentially. 
# If you are converting the tracks, or have fast internet, this will 
# substantially improve processing speed.
concurrency = true
# The maximum number of tracks to download at once
# If you have very fast internet, you will benefit from a higher value,
# A value that is too high for your bandwidth may cause slowdowns
# Set to -1 for no limit
max_connections = 6
# Max number of API requests per source to handle per minute
# Set to -1 for no limit
requests_per_minute = -1

[qobuz]
# 1: 320kbps MP3, 2: 16/44.1, 3: 24/<=96, 4: 24/>=96
quality = 4
# This will download booklet pdfs that are included with some albums
download_booklets = true

# Authenticate to Qobuz using auth token? Value can be true/false only
use_auth_token = true
# Enter your userid if the above use_auth_token is set to true, else enter your email
email_or_userid = "[REDACTED]"
# Enter your auth token if the above use_auth_token is set to true, else enter the md5 hash of your plaintext password
password_or_token = "[REDACTED]"
# Do not change
app_id = "[REDACTED]"
# Do not change
secrets = [REDACTED]

[tidal]
# 0: 256kbps AAC, 1: 320kbps AAC, 2: 16/44.1 "HiFi" FLAC, 3: 24/44.1 "MQA" FLAC
quality = 3
# This will download videos included in Video Albums.
download_videos = true

# Do not change any of the fields below
user_id = ""
country_code = ""
access_token = ""
refresh_token = ""
# Tokens last 1 week after refresh. This is the Unix timestamp of the expiration
# time. If you haven't used streamrip in more than a week, you may have to log
# in again using `rip config --tidal`
token_expiry = ""

[deezer]
# 0, 1, or 2
# This only applies to paid Deezer subscriptions. Those using deezloader
# are automatically limited to quality = 1
quality = 2
# An authentication cookie that allows streamrip to use your Deezer account
# See https://github.com/nathom/streamrip/wiki/Finding-Your-Deezer-ARL-Cookie
# for instructions on how to find this
arl = "[REDACTED]"
# This allows for free 320kbps MP3 downloads from Deezer
# If an arl is provided, deezloader is never used
use_deezloader = true
# This warns you when the paid deezer account is not logged in and rip falls
# back to deezloader, which is unreliable
deezloader_warnings = true

[soundcloud]
# Only 0 is available for now
quality = 0
# This changes periodically, so it needs to be updated
client_id = ""
app_version = ""

[youtube]
# Only 0 is available for now
quality = 0
# Download the video along with the audio
download_videos = true
# The path to download the videos to
video_downloads_folder = "/mnt/nas/media/musica/dl/youtube"

[database]
# Create a database that contains all the track IDs downloaded so far
# Any time a track logged in the database is requested, it is skipped
# This can be disabled temporarily with the --no-db flag
downloads_enabled = true
# Path to the downloads database 
downloads_path = "/home/[REDACTED]/.config/streamrip/downloads.db"
# If a download fails, the item ID is stored here. Then, `rip repair` can be
# called to retry the downloads
failed_downloads_enabled = true
failed_downloads_path = "/home/[REDACTED]/.config/streamrip/failed_downloads.db"

# Convert tracks to a codec after downloading them.
[conversion]
enabled = false
# FLAC, ALAC, OPUS, MP3, VORBIS, or AAC
codec = "ALAC"
# In Hz. Tracks are downsampled if their sampling rate is greater than this. 
# Value of 48000 is recommended to maximize quality and minimize space
sampling_rate = 48000
# Only 16 and 24 are available. It is only applied when the bit depth is higher
# than this value.
bit_depth = 24
# Only applicable for lossy codecs
lossy_bitrate = 320

# Filter a Qobuz artist's discography. Set to 'true' to turn on a filter.
# This will also be applied to other sources, but is not guaranteed to work correctly
[qobuz_filters]
# Remove Collectors Editions, live recordings, etc.
extras = false
# Picks the highest quality out of albums with identical titles.
repeats = false
# Remove EPs and Singles
non_albums = false
# Remove albums whose artist is not the one requested
features = false
# Skip non studio albums
non_studio_albums = false
# Only download remastered albums
non_remaster = false

[artwork]
# Write the image to the audio file
embed = false
# The size of the artwork to embed. Options: thumbnail, small, large, original.
# "original" images can be up to 30MB, and may fail embedding. 
# Using "large" is recommended.
embed_size = "large"
# If this is set to a value > 0, max(width, height) of the embedded art will be set to this value in pixels
# Proportions of the image will remain the same
embed_max_width = -1
# Save the cover image at the highest quality as a seperate jpg file
save_artwork = true
# If this is set to a value > 0, max(width, height) of the saved art will be set to this value in pixels
# Proportions of the image will remain the same
saved_max_width = -1


[metadata]
# Sets the value of the 'ALBUM' field in the metadata to the playlist's name. 
# This is useful if your music library software organizes tracks based on album name.
set_playlist_to_album = true
# If part of a playlist, sets the `tracknumber` field in the metadata to the track's 
# position in the playlist instead of its position in its album
renumber_playlist_tracks = true
# The following metadata tags won't be applied
# See https://github.com/nathom/streamrip/wiki/Metadata-Tag-Names for more info
exclude = []

# Changes the folder and file names generated by streamrip.
[filepaths]
# Create folders for single tracks within the downloads directory using the folder_format
# template
add_singles_to_folder = false
# Available keys: "albumartist", "title", "year", "bit_depth", "sampling_rate",
# "id", and "albumcomposer"
folder_format = "{albumartist} - {title} ({year}) [{container} {bit_depth}bit {sampling_rate}kHz]"
# Available keys: "tracknumber", "artist", "albumartist", "composer", "title",
# and "albumcomposer", "explicit"
track_format = "{tracknumber:02} - {title}{explicit}"
# Only allow printable ASCII characters in filenames.
restrict_characters = false
# Truncate the filename if it is greater than this number of characters
# Setting this to false may cause downloads to fail on some systems
truncate_to = 120

# Last.fm playlists are downloaded by searching for the titles of the tracks
[lastfm]
# The source on which to search for the tracks.
source = "qobuz"
# If no results were found with the primary source, the item is searched for 
# on this one.
fallback_source = "deezer"

[cli]
# Print "Downloading {Album name}" etc. to screen
text_output = true
# Show resolve, download progress bars
progress_bars = true
# The maximum number of search results to show in the interactive menu
max_search_results = 100

[misc]
# Metadata to identify this config file. Do not change.
version = "2.0.6"
# Print a message if a new version of streamrip is available 
check_for_updates = true

Operating System

Linux, Nobara: Linux nobara-pc 6.8.12-200.fsync.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC TKG Sat Jun 1 23:00:12 UTC 2024 x86_64 GNU/Linux

streamrip version

2.0.5 (i'm on the dev branch however)

Screenshots and recordings

No response

Additional context

Tried using streamrip on deezer and qobuz. At first I used the release version on pypi, then i applied this pull request. Was able to download like 5 full artist links on each service, until on both services it gave me an error about the header of the artwork being the wrong type, and then a read error in the exception that you might know more about. Happens on the release and dev versions (with and without the PR I mentioned applied).

@samuelmarinsoto samuelmarinsoto added the bug Something isn't working label Jul 11, 2024
@mortalis13
Copy link
Contributor

mortalis13 commented Jul 13, 2024

I find this part weird:
download_path='/mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/0'+24,

This should be the audio file path I understand. Though maybe it's some debug format but I'm not sure what it means.
If you're on the dev branch, could you modify the streamrip/media/track.py file, in the method _set_download_path add this at the end logger.info(f'self.download_path: {self.download_path}'), and run the script whitout debug mode.
See what paths it prints.

I'd say cheking with only that album, but maybe it's behaving differently on artist and album level, so I'd suggest checking these 2 options and compare.

@samuelmarinsoto
Copy link
Contributor Author

samuelmarinsoto commented Jul 15, 2024

for the album:
command:
rip url https://play.qobuz.com/album/0887828031795
output:

⠙ Resolving URLs...[16:33:49] ERROR    Error downloading artwork: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not <class 'tomlkit.items.String'>       artwork.py:100
[16:33:50] INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/01 - Do I Wanna Know.flac                                 track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/11 - Knee Socks.flac                                      track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/07 - Mad Sounds.flac                                      track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/12 - I Wanna Be Yours.flac                                track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/05 - I Want It All.flac                                   track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/02 - R U Mine.flac                                        track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/08 - Fireside.flac                                        track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/09 - Why'd You Only Call Me When You're High.flac         track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/10 - Snap Out Of It.flac                                  track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/03 - One For The Road.flac                                track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/06 - No. 1 Party Anthem.flac                              track.py:111
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/04 - Arabella.flac                                        track.py:111
[16:33:51] ERROR    Error downloading track 'Do I Wanna Know?', retrying: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not <class       track.py:52
                    'tomlkit.items.String'>                                                                                                                                                  
           ERROR    Persistent error downloading track 'Do I Wanna Know?', skipping: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not   track.py:68
                    <class 'tomlkit.items.String'>                                                                                                                                           
─────────────────────────────────────────────────────────────────────────────────────── Downloading  ────────────────────────────────────────────────────────────────────────────────────────
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/sms/.local/bin/rip:8 in <module>                                                           │
│                                                                                                  │
│   5 from streamrip.rip import rip                                                                │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(rip())                                                                          │
│   9                                                                                              │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/click/core.py:1130 in __call__                                 │
│                                                                                                  │
│                                     ... 22 frames hidden ...                                     │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/mutagen/flac.py:911 in __check_header                          │
│                                                                                                  │
│   908 │   │   """                                                                                │
│   909 │   │                                                                                      │
│   910 │   │   size = 4                                                                           │
│ ❱ 911 │   │   header = fileobj.read(4)                                                           │
│   912 │   │   if header != b"fLaC":                                                              │
│   913 │   │   │   size = None                                                                    │
│   914 │   │   │   if header[:3] == b"ID3":                                                       │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/mutagen/flac.py:68 in read                                     │
│                                                                                                  │
│    65 │   def read(self, size=-1):                                                               │
│    66 │   │   data = self._fileobj.read(size)                                                    │
│    67 │   │   if size >= 0 and len(data) != size:                                                │
│ ❱  68 │   │   │   raise error("file said %d bytes, read %d bytes" % (                            │
│    69 │   │   │   │   │   │   size, len(data)))                                                  │
│    70 │   │   return data                                                                        │
│    71                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
error: file said 4 bytes, read 0 bytes

for the artist:
command:
rip url https://play.qobuz.com/artist/403888
output:

[16:36:19] ERROR    Error downloading artwork: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not <class 'tomlkit.items.String'>       artwork.py:100
           INFO     self.download_path: /mnt/nas/media/musica/dl/Qobuz/Arctic Monkeys - AM (2013) [FLAC 24bit 44.1kHz]/01 - Do I Wanna Know.flac                                 track.py:111
           ERROR    Error downloading track 'Do I Wanna Know?', retrying: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not <class       track.py:52
                    'tomlkit.items.String'>                                                                                                                                                  
           ERROR    Persistent error downloading track 'Do I Wanna Know?', skipping: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not   track.py:68
                    <class 'tomlkit.items.String'>                                                                                                                                           
─────────────────────────────────────────────────────────────────────────────────────── Downloading  ────────────────────────────────────────────────────────────────────────────────────────
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ /home/sms/.local/bin/rip:8 in <module>                                                           │
│                                                                                                  │
│   5 from streamrip.rip import rip                                                                │
│   6 if __name__ == '__main__':                                                                   │
│   7 │   sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])                         │
│ ❱ 8 │   sys.exit(rip())                                                                          │
│   9                                                                                              │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/click/core.py:1130 in __call__                                 │
│                                                                                                  │
│                                     ... 26 frames hidden ...                                     │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/mutagen/flac.py:911 in __check_header                          │
│                                                                                                  │
│   908 │   │   """                                                                                │
│   909 │   │                                                                                      │
│   910 │   │   size = 4                                                                           │
│ ❱ 911 │   │   header = fileobj.read(4)                                                           │
│   912 │   │   if header != b"fLaC":                                                              │
│   913 │   │   │   size = None                                                                    │
│   914 │   │   │   if header[:3] == b"ID3":                                                       │
│                                                                                                  │
│ /usr/lib/python3.12/site-packages/mutagen/flac.py:68 in read                                     │
│                                                                                                  │
│    65 │   def read(self, size=-1):                                                               │
│    66 │   │   data = self._fileobj.read(size)                                                    │
│    67 │   │   if size >= 0 and len(data) != size:                                                │
│ ❱  68 │   │   │   raise error("file said %d bytes, read %d bytes" % (                            │
│    69 │   │   │   │   │   │   size, len(data)))                                                  │
│    70 │   │   return data                                                                        │
│    71                                                                                            │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
error: file said 4 bytes, read 0 bytes
sys:1: RuntimeWarning: coroutine 'Artist._download_async.<locals>._rip' was never awaited

same config, with only said edits applied

EDIT: it seems to be okay on deezer for now, qobuz consistently continues to fail

@mortalis13
Copy link
Contributor

Could you reupload the full debug log? (you can upload it here directly FYI, so it should be more permanent than external services i think)
I'll try to check where it's reaching.

@samuelmarinsoto
Copy link
Contributor Author

output.txt
Here it is as a file (its too long to paste here). This is the original one, I can provide a new one with the modification you need if you want.

@mortalis13
Copy link
Contributor

hm, i guess this is the main reason:
Error downloading track 'Do I Wanna Know?', retrying: Header part ('950096963') from {'X-App-Id': '950096963'} must be of type str or bytes, not <class 'tomlkit.items.String'>

And I think the header X-App-Id is set in qobuz.py login() method.
So I'd check the exact value it assigning there with a logger line.
And also in the track.py downloa() where "Error downloading track" is printed, just in case, logging the self.downloadable.session.headers I guess.

But I tried to download that album myself and it worked in Windows and Ubuntu, though not sure if it's OS related.
A simlier thing maybe would be to install the tool in clean environment, a new venv and removing/renaming the config folder, so it creates a fresh config and then insert the login details.

@mortalis13
Copy link
Contributor

OK, I checked also the type of the header value, really it's <class 'tomlkit.items.String'>, but I don't have an explanation why it's working in my environment, maybe something to do with the handling of some types in your Python instance...

An option could be checking with different Python versions, 3.10+.
And on the code level, I'd set explicitly the str type to that header, if it's the only problem of that nature.
Just where it assigns the X-App-Id header value, do str(c.app_id) and see if it's enough.

@samuelmarinsoto
Copy link
Contributor Author

samuelmarinsoto commented Jul 17, 2024

Ok, I have tried resetting the config, and i found out that if you remove the app_id and secrets fields from the config file and let streamrip generate them, it will download just fine. after calling it again with the fields already filled, it throws the error. Only a problem on qobuz it seems

@samuelmarinsoto
Copy link
Contributor Author

Applied the edits you suggested with str(c.app_id), seems to have resolved the issue!

@samuelmarinsoto
Copy link
Contributor Author

Should i send you a patch or a PR or how should we go about this

@mortalis13
Copy link
Contributor

I'm glad it helped. I think a PR would be perfect, when the owner approves will be 1 issue less )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants