Created
July 16, 2017 00:33
-
-
Save JonnyWong16/8ede4aabce105217a70cc2386ce673f7 to your computer and use it in GitHub Desktop.
Saves artist.jpg to the Artist folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# | |
# Description: Saves artist.jpg to the Artist folder. | |
# Author: /u/SwiftPanda16 | |
# Requires: plexapi, requests | |
from plexapi.server import PlexServer | |
import os | |
import requests | |
### EDIT SETTINGS ### | |
PLEX_URL = "http://localhost:32400" | |
PLEX_TOKEN = "xxxxxxxxxx" | |
MUSIC_LIBRARY_NAME = "Music" | |
DISC_FOLDERS = ("Disc 1", "Disc 2", "Disc 01", "Disc 02") | |
## CODE BELOW ## | |
plex = PlexServer(PLEX_URL, PLEX_TOKEN) | |
headers = {"X-Plex-Token": PLEX_TOKEN} | |
for artist in plex.library.section(MUSIC_LIBRARY_NAME).all(): | |
album = artist.albums()[0] | |
track = album.tracks()[0] | |
media = track.media[0] | |
part = media.parts[0] | |
file = part.file | |
path = os.path.dirname(file) # Folder containing the track | |
if path.endswith(DISC_FOLDERS): # If it is a disc folder | |
path = os.path.dirname(path) # Go up one folder | |
path = os.path.dirname(path) # Go up one folder | |
r = requests.get(PLEX_URL + track.grandparentThumb, headers=headers, stream=True) | |
with open(os.path.join(path, "artist.jpg"), "wb") as f: | |
for chunk in r.iter_content(1024): | |
f.write(chunk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, thanks for the work and lovely script that will save a lot of time to have the poster, as local data. I was wondering how to have the condition if the poster.jpg already exist do not overwrite? Or pass some variable in this new condition under ### EDIT SETTINGS ### overwrite_poster (yes or no) or (true false) as boolean var. Thanks again!