meeb / bandcampsync

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

wrong file name and folder name if only one track is purchased from the album #8

Closed AlexSleepy closed 1 year ago

AlexSleepy commented 1 year ago

Hi. I have a few tracks that I bought separately from the albums in my collection, and noticed that instead of Artist Name/Album Name/Track Name.flac they are saved to Artist Name/Track Name/Album Name.flac and they don't have album art in the folder (not sure that it should be there in this case, just a note). Otherwise the script works just great, thanks a lot! :)

meeb commented 1 year ago

Hi! I don't think single tracks supply the album name they're from when they're downloaded. The script does attempt to use the album name for the directory if it's available, but I'll double-check that.

meeb commented 1 year ago

I've had a poke about and unfortunately I don't have any single tracks purchased from albums in my collection to replicate this at the moment. Can you paste any logs for the single item being downloaded? Internally bandcampsync uses this to create the downloaded media path:

self.media_dir / self._clean_path(item.band_name) / self._clean_path(item.item_title)

I don't see how this would save a single track as Artist Name/Track Name/Album Name.flac unless something was weird with the metadata for the track where item_title was somehow the album name and band_name was set to the track name?

Obviously in the interim you can manually organise the media once it's been downloaded, just make sure the Artist Name/Album Name/bandcamp_item_id.txt file exists and contains the Bandcamp album ID. You can create the file manually if needed as well, it just marks the album as already downloaded so the script will behave when run in the future.

AlexSleepy commented 1 year ago

This happens for all the single tracks that I have in my library, so I guess the chances that all of them have weird metadata is pretty low. Here's the example log for 2 items. Both of the examples are from the compilation albums, but the same thing happens to the tracks I got from a regular albums.

2023-10-23 19:54:59,750 sync [INFO] New media item, will download: "Arbitrage / HON" (id:4043006023) in "flac"
2023-10-23 19:55:00,776 sync [INFO] Downloading item "Arbitrage / HON" (id:4043006023) from https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286 to /var/folders/sg/rktjmdnx4cn5n4gw21gkb1xw0000gn/T/tmpjso_u0ki
2023-10-23 19:55:02,734 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 10%
2023-10-23 19:55:03,458 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 20%
2023-10-23 19:55:03,839 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 30%
2023-10-23 19:55:04,466 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 40%
2023-10-23 19:55:04,949 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 50%
2023-10-23 19:55:05,442 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 60%
2023-10-23 19:55:05,963 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 70%
2023-10-23 19:55:06,492 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 80%
2023-10-23 19:55:06,942 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 90%
2023-10-23 19:55:07,413 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=4043006023&sig=[masked]&sitem_id=261968286: 100%
2023-10-23 19:55:07,415 sync [INFO] Copying single track: "/var/folders/sg/rktjmdnx4cn5n4gw21gkb1xw0000gn/T/tmpjso_u0ki" to "/Users/oleksiy/Downloads/bc/Arbitrage/HON/stream-state-selected-mixed-by-inland-counter014.flac"
2023-10-23 19:55:07,482 media [INFO] Writing bandcamp item id:4043006023 to: /Users/oleksiy/Downloads/bc/Arbitrage/HON/bandcamp_item_id.txt
2023-10-23 19:55:07,489 sync [INFO] New media item, will download: "Noisynth / Rave in the Jungle" (id:3153119059) in "flac"
2023-10-23 19:55:08,307 sync [INFO] Downloading item "Noisynth / Rave in the Jungle" (id:3153119059) from https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073 to /var/folders/sg/rktjmdnx4cn5n4gw21gkb1xw0000gn/T/tmphv5idljm
2023-10-23 19:55:10,573 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 10%
2023-10-23 19:55:11,450 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 20%
2023-10-23 19:55:12,344 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 30%
2023-10-23 19:55:13,165 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 40%
2023-10-23 19:55:13,952 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 50%
2023-10-23 19:55:14,778 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 60%
2023-10-23 19:55:15,672 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 70%
2023-10-23 19:55:16,667 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 80%
2023-10-23 19:55:17,693 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 90%
2023-10-23 19:55:18,651 download [INFO] Downloading https://popplers5.bandcamp.com/download/track?enc=flac&id=3153119059&sig=[masked]&sitem_id=261968073: 100%
2023-10-23 19:55:18,654 sync [INFO] Copying single track: "/var/folders/sg/rktjmdnx4cn5n4gw21gkb1xw0000gn/T/tmphv5idljm" to "/Users/oleksiy/Downloads/bc/Noisynth/Rave in the Jungle/global-modular-traffic-3-3.flac"

Thanks anyway. I'll probably just end up renaming single tracks manually. Your script helps a lot even without this stuff :)

meeb commented 1 year ago

Thanks for the logs. I think I've found what this is. With single tracks the item_title in the metadata defaults to the album and not the track name and the item name is technically the track name, which is why this is backwards.

Just to really clarify with this before I start debugging metadata:

Noisynth/Rave in the Jungle/global-modular-traffic-3-3.flac

Should be:

Artist = Noisynth Album = Global Modular Traffic 3 3 Track name = Rave in the Jungle

Right?

AlexSleepy commented 1 year ago

Artist = Noisynth Album = Global Modular Traffic 3 3 Track name = Rave in the Jungle

Yes, that's correct.

btw, are IDs tied to just one track or the full album in this case? Wouldn't it be a problem if several tracks are bought from the same album and bandcamp_item_id.txt already exists in the folder but for the different item? It's not like I have this in my collection, just thinking out loud

meeb commented 1 year ago

Thanks. And yes, the Bandcamp release ID is tied to the album release not the track so at the moment even when this path issue is fixed if you buy one track from an album, then sync it, then buy another track off the same album at at later date the new track wouldn't download as the "album" is marked as already synced.

I'm not sure how much effort this is worth putting in to fix though, it seems quite niche and you would have to probably change the bandcamp_item_id.txt file to be a JSON file that stored every media item ID inside of the release instead while maintaining backwards compatibility. It's certainly possible, just a fair bit of work.

AlexSleepy commented 1 year ago

no worries, that's very niche for sure :) thanks a lot for your work!

meeb commented 1 year ago

I'll close this for now, but feel free to open another issue if you find anything else.