-
Notifications
You must be signed in to change notification settings - Fork 0
/
script
157 lines (131 loc) · 5.75 KB
/
script
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import requests
import json
import re
import logging
import sqlite3
from datetime import datetime, timedelta
# Sample config
#RADARR_URL = "http://your-radarr-url:7878/api/v3"
#RADARR_API_KEY = "your-radarr-api-key"
#HAWKE_API_URL = "https://hawke.uno/api"
#HAWKE_API_KEY = "your-hawke-api-key"
CACHE_DB = 'cache.db'
CACHE_EXPIRY_DAYS = 7
# Setup logging
logging.basicConfig(filename='error_log.txt', level=logging.ERROR)
class Cache:
def __init__(self, db_path):
self.db_path = db_path
self.init_db()
def init_db(self):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS hawke_cache (
imdb_id TEXT PRIMARY KEY,
data TEXT,
last_checked TIMESTAMP
)''')
conn.commit()
def get(self, imdb_id):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''SELECT data, last_checked FROM hawke_cache WHERE imdb_id=?''', (imdb_id,))
row = cursor.fetchone()
if row:
data, last_checked = row
if datetime.strptime(last_checked, '%Y-%m-%d %H:%M:%S') >= datetime.now() - timedelta(days=CACHE_EXPIRY_DAYS):
return json.loads(data)
return None
def set(self, imdb_id, data):
with sqlite3.connect(self.db_path) as conn:
cursor = conn.cursor()
cursor.execute('''INSERT OR REPLACE INTO hawke_cache (imdb_id, data, last_checked)
VALUES (?, ?, ?)''', (imdb_id, json.dumps(data), datetime.now().strftime('%Y-%m-%d %H:%M:%S')))
conn.commit()
def get_radarr_movies():
print("Fetching movies from Radarr...")
url = f"{RADARR_URL}/movie"
headers = {"X-Api-Key": RADARR_API_KEY}
response = requests.get(url, headers=headers)
response.raise_for_status()
movies = response.json()
print(f"Found {len(movies)} movies in Radarr.")
return movies
def search_hawke(imdb_id, cache):
data = cache.get(imdb_id)
if data:
print(f" Using cached result for IMDB ID: {imdb_id}")
return data
print(f" Fetching new result from Hawke.one for IMDB ID: {imdb_id}")
url = f"{HAWKE_API_URL}/torrents?api_token={HAWKE_API_KEY}&imdb={imdb_id}&resolution_id=2"
response = requests.get(url)
response.raise_for_status()
data = response.json()
cache.set(imdb_id, data)
return data
def extract_release_group(file_name):
match = re.search(r'-(\w+)(?:\.mkv|\.mp4|\.avi)?$', file_name)
return match.group(1) if match else None
def is_2160p_quality(file_info):
return file_info['quality']['quality']['resolution'] == 2160
def is_valid_release_group(local_release_group):
return local_release_group and local_release_group.lower() in ['bhdstudio', 'hallowed']
def check_movies(cache):
radarr_movies = get_radarr_movies()
movies_not_found_list = []
total_movies = len(radarr_movies)
movies_checked = 0
movies_not_found = 0
for movie in radarr_movies:
movies_checked += 1
print(f"Checking movie {movies_checked}/{total_movies}: {movie['title']} ({movie['year']})")
if not movie['hasFile']:
print(" No file available for this movie. Skipping.")
continue
file_info = movie['movieFile']
if not is_2160p_quality(file_info):
print(" Not a 2160p release. Skipping.")
continue
local_release_group = extract_release_group(file_info['relativePath'])
if not is_valid_release_group(local_release_group):
print(f" Release group is not BHDStudio or Hallowed (found {local_release_group}). Skipping.")
continue
imdb_id = movie['imdbId']
try:
hawke_results = search_hawke(imdb_id, cache)
if not hawke_results.get('data'):
print(f" Not found on Hawke.one: {movie['title']} ({movie['year']}) - {local_release_group}")
movies_not_found_list.append(f"{movie['title']} ({movie['year']}) - {local_release_group}")
movies_not_found += 1
else:
found = any(
torrent.get('resolution') == '2160p' and
any(group in torrent.get('releaseName', '').lower() for group in ['bhdstudio', 'hallowed'])
for torrent in hawke_results['data']
)
if not found:
print(f" No matching 2160p release found on Hawke.one: {movie['title']} ({movie['year']}) - {local_release_group}")
movies_not_found_list.append(f"{movie['title']} ({movie['year']}) - {local_release_group}")
movies_not_found += 1
except Exception as e:
logging.error(f"Error processing movie {movie['title']} ({movie['year']}): {str(e)}")
print(f" Error occurred, logged to error_log.txt")
print(f"\nSummary:")
print(f"Checked {movies_checked} movies")
print(f"Movies not found on Hawke.one: {movies_not_found}")
return sorted(movies_not_found_list)
def save_to_txt(movies_list, filename="movies_not_found.txt"):
with open(filename, 'w') as file:
for movie in movies_list:
file.write(f"{movie}\n")
print(f"\nResults saved to {filename}")
# Main execution
if __name__ == "__main__":
print("Starting Radarr to Hawke.one checker...")
cache = Cache(CACHE_DB)
movies_not_found_list = check_movies(cache)
if movies_not_found_list:
save_to_txt(movies_not_found_list)
else:
print("All movies with BHDStudio or Hallowed 2160p releases are found on Hawke.one.")
print("Check complete.")