Created
April 13, 2020 00:43
-
-
Save nitrag/895606096d4a4012cc311da8047b29ae to your computer and use it in GitHub Desktop.
Plex SD to Radarr for Quality Upgrade
This file contains hidden or 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
# Scans your plex movies, if a movie has only SD quality, it will send it to Radarr | |
# pip install plexapi | |
# python 3.6+ | |
# | |
from plexapi.server import PlexServer | |
import re | |
import requests | |
plex_url = 'http://192.168.1.100:32400' | |
plex_token = 'abc123' | |
radarr_host = '192.168.1.100' | |
radarr_port = 7878 | |
radarr_api_key = 'abc123' | |
radarr_quality_profile = 6 # Use Chrome Developer tools to discover the ID. For me, this is my "1080/720p" profile | |
radarr_movie_path = '/movies/' | |
def radarr_search_movie(imdb_id: str): | |
url = f'http://{radarr_host}:{radarr_port}/api/movie/lookup/imdb?imdbId={imdb_id}&apikey={radarr_api_key}' | |
response = requests.get(url) | |
if response.status_code == 200: | |
return response.json() | |
else: | |
return None | |
def radarr_add_movie(payload: dict): | |
return requests.post(f'http://{radarr_host}:{radarr_port}/api/movie?apikey={radarr_api_key}', json=payload) | |
def main(): | |
plex = PlexServer(plex_url, plex_token) | |
movies = plex.library.section('Movies') | |
for movie in movies.search(): | |
if movie.media and len(movie.media) == 1 and movie.media[0].videoResolution == 'sd': | |
try: | |
imdb_id = re.search('(tt[0-9]+)', movie.guid)[0] | |
except Exception: | |
print(f"Can't find IMDB ID for {movie.title}") | |
continue | |
rs = radarr_search_movie(imdb_id) | |
if rs: | |
payload = { | |
'title': rs['title'], | |
'titleSlug': rs['titleSlug'], | |
'images': rs['images'], | |
'tmdbId': rs['tmdbId'], | |
'profileId': rs['profileId'], | |
'year': rs['year'], | |
'qualityProfileId': radarr_quality_profile, | |
'rootFolderPath': radarr_movie_path, | |
'monitored': True, | |
'addOptions': { | |
'searchForMovie': True | |
} | |
} | |
submit = radarr_add_movie(payload) | |
if submit.status_code == 201: | |
print(f'Movie added to Radarr: {movie.title}') | |
else: | |
print(f'{movie.title}: {submit.json()[0]["errorMessage"]}.') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment