blob: 0c7f3832e27b17d98048e02e3bb558ebe1bc0054 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
import requests
def add_content(
content_info: dict,
service: str,
host: str,
headers: str,
folder_path: str,
profile_id: str,
):
"""
Add content to Sonarr or Radarr
Args:
content_info (dict): The content information
service (str): The service to add the content to
host (str): The host URL
headers (str): The headers for the request
folder_path (str): The folder path to download the content to
profile_id (str): The profile ID to download the content in
Returns:
str: The ID of the content or False
"""
# Get the content data based on ID
data = requests.get(
url=(
f"{host}/api/v3/movie/lookup/tmdb?tmdbId={content_info['contentId']}"
if service == "radarr"
else f"{host}/api/v3/series/lookup?term=tvdb:{content_info['contentId']}"
),
headers=headers,
).json()
data["monitored"] = True
data["qualityProfileId"] = profile_id
data["rootFolderPath"] = folder_path
# Search for the content on add
data["addOptions"] = {
(
"searchForMovie"
if service == "radarr"
else "searchForMissingEpisodes"
): True
}
# Send the request to add the content
response = requests.post(
f"{host}/api/v3/{'movie' if service == 'radarr' else 'series'}",
headers=headers,
json=data,
)
if response.status_code == 201:
return response.json()["id"]
else:
return False
|