python-plexapi icon indicating copy to clipboard operation
python-plexapi copied to clipboard

download() on a file with multiple Media options clobbers itself

Open MikeBishop opened this issue 2 years ago • 1 comments

Describe the Bug

When a downloadable item (e.g. Episode) is available in multiple quality/encoding options, calling download() is supposed to download all of them. However, if keep_original_filenames=False (the default), each Media item gets downloaded to the same friendly name, with subsequent downloads overwriting the previous ones. All the data is transferred, but only one remains on the file system after the function returns.

If keep_original_filenames=True, all files are downloaded because the target filenames are (likely to be) different.

Code Snippets

episode = series.onDeck()
files = episode.download()
assert len(files) == len(episode.media)

Expected Behavior

One or both of:

  • Only one media is downloaded, and I can select which one it is
    • Maybe by passing arguments into .download()?
    • Maybe by using episode.media[0].download(), which doesn't currently exist?
  • All media options are downloaded with different names.

Additional Context

Appending something like "[4K-20Mbps]" or "[1080p-8Mbps]" to the friendly name when a discriminator is needed would be a nice touch, but even "-0", "-1", etc. would keep the overwrite from happening.

Operating System and Version

Ubuntu 22.04 on WSL

Plex Media Server Version

1.31.2.6783

Python Version

3.10.6

PlexAPI Version

4.15.0

MikeBishop avatar Aug 06 '23 02:08 MikeBishop

My ideas since the current download method just loops over all parts.

  1. Move the logic in the download() method to MediaPart to allow downloading a single part.
  2. Add a download() method to Media that calls the method in MediaPart to downloads all parts in that media. Add part discriminators (maybe -ptX to follow Plex's convention?) where necessary.
  3. Update the base download() method that calls the method in Media to download all parts in all media. Add media discriminators (maybe resolution and bitrate to match Plex's version dialogue?) where necessary (this would need to work in conjuntion with the part discriminator).

JonnyWong16 avatar Aug 06 '23 18:08 JonnyWong16