meeb / bandcampsync

Downloads your Bandcamp purchases automatically
BSD 3-Clause "New" or "Revised" License
142 stars 7 forks source link

Invalid download links #2

Closed Gondolindrim closed 1 year ago

Gondolindrim commented 1 year ago

It would seem that some download links come invalid.

When accessing the URL it turns to a Bandcamp page saying

"Sorry, that download link isn't valid. Please alert the person that sent you the link. If it was the artist, use the "Contact artist" link on the artist's page, or look for the music there."

Maybe related but the script keeps refreshing and stops after exhibiting this error:

Traceback (most recent call last):
  File "/usr/local/bin/bandcampsync-service", line 61, in <module>
    do_sync(cookies_path, cookies, dir_path, media_format_env)
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/__init__.py", line 30, in do_sync
    download_url = bandcamp.load_download_url(purchase, encoding=media_format)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/bandcamp.py", line 210, in load_download_url
    band_name = item['band_name']
                ^^^^
NameError: name 'item' is not defined. Did you mean: 'iter'?
meeb commented 1 year ago

Thanks, the NameError should be fixed in the latest release. As for the invalid links that sounds like an authentication or cookie problem, are you checking the links in a browser that's logged into Bandcamp?

Gondolindrim commented 1 year ago

I understand that the latest release might not be the one in the docker image? That is what I am using

meeb commented 1 year ago

The docker image is/was rebuilding as of 3 minutes ago. Give it 15 mins and pull :latest down again.

Gondolindrim commented 1 year ago

Updated and getting new error:

  File "/usr/local/bin/bandcampsync-service", line 67, in <module>
    do_sync(cookies_path, cookies, dir_path, media_format_env)
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/__init__.py", line 59, in do_sync
    copy_file(temp_file_path, file_dest)
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/download.py", line 90, in copy_file
    return shutil.copyfile(src, dst)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/shutil.py", line 258, in copyfile
    with open(dst, 'wb') as fdst:

FileNotFoundError: [Errno 2] No such file or directory: '/downloads/Mechina/Blessings Upon The Field Where Blades Will Flood/blessings-upon-the-field-where-blades-will-flood.flac'
meeb commented 1 year ago

Interesting, what's in the logs above that error?

Gondolindrim commented 1 year ago

I have redacted a couple things because I am not sure what is safe to share, so tell me if you need any info

2023-09-19 03:22:31,950 sync [INFO] New media item, downloading: Mechina / Blessings Upon The Field Where Blades Will Flood (id:[some_id}) in "flac" 2023-09-19 03:22:32,464 sync [INFO] Downloading item Mechina / Blessings Upon The Field Where Blades Will Flood (id:2857123865) from https://popplers5.bandcamp.com/download/track?enc=flac&id=[some_value]&sig=[some_value]&sitem_id=[some_value] to /var/tmp/tmp_jxanp7e

The file is successfully downloaded and this follows:

2023-09-19 03:22:39,548 sync [INFO] Downloaded file is not a single track: /var/tmp/tmp_jxanp7e 2023-09-19 03:22:39,548 sync [INFO] Copying single file: "/var/tmp/tmp_jxanp7e" to "/downloads/Mechina/Blessings Upon The Field Where Blades Will Flood/blessings-upon-the-field-where-blades-will-flood.flac"

And then the python error.

meeb commented 1 year ago

I had missed a mkdir out after a refactor. Latest image in 10 mins or so should have that fixed.

Gondolindrim commented 1 year ago

Got it! Another error:

2023-09-19 03:37:41,664 sync [INFO] Decompressing downloaded zip /var/tmp/tmpwj4ox5qq to /var/tmp/tmpgm5p0kqg
2023-09-19 03:37:44,349 sync [INFO] Moving extracted file: "/var/tmp/tmpgm5p0kqg/STÖMB- - Massive Disturbed Meta Art - 07 An Absence of Sun.flac" to "/downloads/[STÖMB]/Massive Disturbed Meta Art/STÖMB- - Massive Disturbed Meta Art - 07 An Absence of Sun.flac"
Traceback (most recent call last):
  File "/usr/lib/python3.11/shutil.py", line 825, in move
    os.rename(src, real_dst)
FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/tmpgm5p0kqg/STÖMB- - Massive Disturbed Meta Art - 07 An Absence of Sun.flac' -> '/downloads/[STÖMB]/Massive Disturbed Meta Art/STÖMB- - Massive Disturbed Meta Art - 07 An Absence of Sun.flac'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/bandcampsync-service", line 67, in <module>
    do_sync(cookies_path, cookies, dir_path, media_format_env)
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/__init__.py", line 52, in do_sync
    move_file(file_path, file_dest)
  File "/usr/local/lib/python3.11/dist-packages/bandcampsync/download.py", line 85, in move_file
    return shutil.move(src, dst)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/shutil.py", line 845, in move
    copy_function(src, real_dst)
  File "/usr/lib/python3.11/shutil.py", line 436, in copy2
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/usr/lib/python3.11/shutil.py", line 258, in copyfile
    with open(dst, 'wb') as fdst:
         ^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '/downloads/[STÖMB]/Massive Disturbed Meta Art/STÖMB- - Massive Disturbed Meta Art - 07 An Absence of Sun.flac'
meeb commented 1 year ago

does the directory /downloads/[STÖMB]/ exist on disk? This may be an encoding normalisation issue with the [ Ö and ] on the filesystem.

Gondolindrim commented 1 year ago

I mkdir'd the /downloads/[STÖMB]/ folder and the links that were previously working are now broken:

2023-09-19T02:44:25.030578689Z 2023-09-19 03:44:25,030 sync [ERROR] Download attempt returned an unexpected Content-Type (Invalid content type: text/html), skipping

Gondolindrim commented 1 year ago

Interestingly, another album is downloaded:

2023-09-19T02:46:03.940947520Z 2023-09-19 03:46:03,940 sync [INFO] Decompressing downloaded zip /var/tmp/tmpxup555bb to /var/tmp/tmpsx3eax1y
2023-09-19T02:46:04.149153011Z 2023-09-19 03:46:04,148 sync [INFO] Moving extracted file: "/var/tmp/tmpsx3eax1y/Plini - Impulse Voices (Remix EP) - 01 I'll Tell You Someday - Dayce Remix.flac" to "/downloads/Plini/Impulse Voices (Remix EP)/Plini - Impulse Voices (Remix EP) - 01 I'll Tell You Someday - Dayce Remix.flac"
2023-09-19T02:46:04.162711909Z Traceback (most recent call last):
2023-09-19T02:46:04.162894552Z   File "/usr/lib/python3.11/shutil.py", line 825, in move
2023-09-19T02:46:04.163959110Z     os.rename(src, real_dst)
2023-09-19T02:46:04.164652196Z FileNotFoundError: [Errno 2] No such file or directory: "/var/tmp/tmpsx3eax1y/Plini - Impulse Voices (Remix EP) - 01 I'll Tell You Someday - Dayce Remix.flac" -> "/downloads/Plini/Impulse Voices (Remix EP)/Plini - Impulse Voices (Remix EP) - 01 I'll Tell You Someday - Dayce Remix.flac"
2023-09-19T02:46:04.164693478Z 
2023-09-19T02:46:04.164705902Z During handling of the above exception, another exception occurred:
2023-09-19T02:46:04.164708875Z 
2023-09-19T02:46:04.164711436Z Traceback (most recent call last):
2023-09-19T02:46:04.164714028Z   File "/usr/local/bin/bandcampsync-service", line 67, in <module>
2023-09-19T02:46:04.164856261Z     do_sync(cookies_path, cookies, dir_path, media_format_env)
2023-09-19T02:46:04.164864838Z   File "/usr/local/lib/python3.11/dist-packages/bandcampsync/__init__.py", line 52, in do_sync
2023-09-19T02:46:04.164956220Z     move_file(file_path, file_dest)
2023-09-19T02:46:04.164960808Z   File "/usr/local/lib/python3.11/dist-packages/bandcampsync/download.py", line 85, in move_file
2023-09-19T02:46:04.165099601Z     return shutil.move(src, dst)
2023-09-19T02:46:04.165103365Z            ^^^^^^^^^^^^^^^^^^^^^
2023-09-19T02:46:04.165106133Z   File "/usr/lib/python3.11/shutil.py", line 845, in move
2023-09-19T02:46:04.165274331Z     copy_function(src, real_dst)
2023-09-19T02:46:04.165277832Z   File "/usr/lib/python3.11/shutil.py", line 436, in copy2
2023-09-19T02:46:04.165370851Z     copyfile(src, dst, follow_symlinks=follow_symlinks)
2023-09-19T02:46:04.165374325Z   File "/usr/lib/python3.11/shutil.py", line 258, in copyfile
2023-09-19T02:46:04.165432051Z     with open(dst, 'wb') as fdst:
2023-09-19T02:46:04.165435176Z          ^^^^^^^^^^^^^^^
2023-09-19T02:46:04.165490871Z FileNotFoundError: [Errno 2] No such file or directory: "/downloads/Plini/Impulse Voices (Remix EP)/Plini - Impulse Voices (Remix EP) - 01 I'll Tell You Someday - Dayce Remix.flac"

EDIT: maybe another formatting or encoding error due to the apostrophe?

meeb commented 1 year ago

That "HTML returned" error is more that Bandcamp haven't prepared the download yet. Wait 30 mins and try again (see #1). And yes possibly another normalisation issue. I was hoping I could just let pathlib handle it but I may have to strip anything not a-zA-Z0-9 from directory and file names for now.

Gondolindrim commented 1 year ago

Ok I'll leave the script running through the night and see what happens. I'll update tomorrow.

As for the naming, I'll try to see if I can contribute

meeb commented 1 year ago

Thanks. For reference here is where the local directory path is created:

https://github.com/meeb/bandcampsync/blob/main/bandcampsync/media.py#L56

Gondolindrim commented 1 year ago

Small update: getting issues creating folders that don't have special characters in their names

2023-09-19T02:51:47.814422891Z FileNotFoundError: [Errno 2] No such file or directory: '/var/tmp/tmp8qfvqa6g/Plini - Handmade Cities - 05 Pastures.flac' -> '/downloads/Plini/Handmade Cities/Plini - Handmade Cities - 05 Pastures.flac'
2023-09-19T02:51:47.814433534Z 
2023-09-19T02:51:47.814436867Z During handling of the above exception, another exception occurred:
2023-09-19T02:51:47.814439840Z 
2023-09-19T02:51:47.814442606Z Traceback (most recent call last):
2023-09-19T02:51:47.814446216Z   File "/usr/local/bin/bandcampsync-service", line 67, in <module>
2023-09-19T02:51:47.814590370Z     do_sync(cookies_path, cookies, dir_path, media_format_env)
2023-09-19T02:51:47.814594931Z   File "/usr/local/lib/python3.11/dist-packages/bandcampsync/__init__.py", line 52, in do_sync
2023-09-19T02:51:47.814709062Z     move_file(file_path, file_dest)
2023-09-19T02:51:47.814713000Z   File "/usr/local/lib/python3.11/dist-packages/bandcampsync/download.py", line 85, in move_file
2023-09-19T02:51:47.814919243Z     return shutil.move(src, dst)
2023-09-19T02:51:47.814923291Z            ^^^^^^^^^^^^^^^^^^^^^
2023-09-19T02:51:47.814926130Z   File "/usr/lib/python3.11/shutil.py", line 845, in move
2023-09-19T02:51:47.815095917Z     copy_function(src, real_dst)
2023-09-19T02:51:47.815157518Z   File "/usr/lib/python3.11/shutil.py", line 436, in copy2
2023-09-19T02:51:47.815248839Z     copyfile(src, dst, follow_symlinks=follow_symlinks)
2023-09-19T02:51:47.815290973Z   File "/usr/lib/python3.11/shutil.py", line 258, in copyfile
2023-09-19T02:51:47.815390209Z     with open(dst, 'wb') as fdst:
2023-09-19T02:51:47.815393446Z          ^^^^^^^^^^^^^^^
2023-09-19T02:51:47.815396141Z FileNotFoundError: [Errno 2] No such file or directory: '/downloads/Plini/Handmade Cities/Plini - Handmade Cities - 05 Pastures.flac'
meeb commented 1 year ago

Weird, does the directory /downloads/Plini/Handmade Cities/ exist?

Gondolindrim commented 1 year ago

It does not. Not even the folder /downloads/Plini/

meeb commented 1 year ago

Give it 10 mins then try :latest (0.2.4).

Gondolindrim commented 1 year ago

I am using v0.3.0 and so far downloads are going smoothly. Since my collection is considerable, it will take some time. I will wait for errors and if I receive none I will close this.

meeb commented 1 year ago

How are you getting on?

meeb commented 1 year ago

I'll close this for now, feel free to re-open it if you need to.