fix: dat
This commit is contained in:
+17
-7
@@ -264,12 +264,17 @@ class RadarrClient:
|
|||||||
url = urljoin(self.base_url, path.lstrip("?").lstrip("/"))
|
url = urljoin(self.base_url, path.lstrip("?").lstrip("/"))
|
||||||
if params:
|
if params:
|
||||||
url = url + ("&" if "?" in url else "?") + urlencode(params)
|
url = url + ("&" if "?" in url else "?") + urlencode(params)
|
||||||
|
|
||||||
|
_log("DEBUG", f"Radarr API Request: {url}")
|
||||||
req = UrlRequest(url, headers={"Accept": "application/json"})
|
req = UrlRequest(url, headers={"Accept": "application/json"})
|
||||||
with urlopen(req, timeout=self.timeout) as resp:
|
with urlopen(req, timeout=self.timeout) as resp:
|
||||||
data = resp.read().decode("utf-8")
|
data = resp.read().decode("utf-8")
|
||||||
return json.loads(data)
|
result = json.loads(data)
|
||||||
|
_log("DEBUG", f"Radarr API Response: {json.dumps(result, indent=2) if isinstance(result, (dict, list)) else result}")
|
||||||
|
return result
|
||||||
except (URLError, HTTPError, json.JSONDecodeError) as e:
|
except (URLError, HTTPError, json.JSONDecodeError) as e:
|
||||||
last_err = e
|
last_err = e
|
||||||
|
_log("DEBUG", f"Radarr API attempt {attempt + 1} failed: {e}")
|
||||||
time.sleep(min(2 ** attempt, 5))
|
time.sleep(min(2 ** attempt, 5))
|
||||||
attempt += 1
|
attempt += 1
|
||||||
_log("WARNING", f"Radarr GET {path} failed after retries: {last_err}")
|
_log("WARNING", f"Radarr GET {path} failed after retries: {last_err}")
|
||||||
@@ -893,19 +898,24 @@ def set_movie_file_mtime(movie_dir: Path, dateadded_iso: str):
|
|||||||
return
|
return
|
||||||
try:
|
try:
|
||||||
ts = datetime.fromisoformat(dateadded_iso.replace("Z", "+00:00")).timestamp()
|
ts = datetime.fromisoformat(dateadded_iso.replace("Z", "+00:00")).timestamp()
|
||||||
video_exts = (".mkv", ".mp4", ".avi", ".mov", ".m4v")
|
|
||||||
|
# Update ALL files in the directory to the correct timestamp
|
||||||
|
files_updated = 0
|
||||||
for f in movie_dir.iterdir():
|
for f in movie_dir.iterdir():
|
||||||
if f.is_file() and f.suffix.lower() in video_exts:
|
if f.is_file():
|
||||||
try:
|
try:
|
||||||
os.utime(f, (ts, ts), follow_symlinks=False)
|
os.utime(f, (ts, ts), follow_symlinks=False)
|
||||||
_log("DEBUG", f"Updated movie file mtime: {f} -> {dateadded_iso}")
|
files_updated += 1
|
||||||
|
_log("DEBUG", f"Updated file mtime: {f.name} -> {dateadded_iso}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_log("WARNING", f"Failed to update mtime on {f}: {e}")
|
_log("WARNING", f"Failed to update mtime on {f.name}: {e}")
|
||||||
|
|
||||||
|
# Update directory timestamp
|
||||||
try:
|
try:
|
||||||
os.utime(movie_dir, (ts, ts), follow_symlinks=False)
|
os.utime(movie_dir, (ts, ts), follow_symlinks=False)
|
||||||
_log("DEBUG", f"Updated movie dir mtime: {movie_dir} -> {dateadded_iso}")
|
_log("INFO", f"Updated {files_updated} files and directory mtime: {movie_dir.name} -> {dateadded_iso}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_log("WARNING", f"Failed to update mtime on {movie_dir}: {e}")
|
_log("WARNING", f"Failed to update mtime on directory {movie_dir}: {e}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
_log("WARNING", f"Bad timestamp for movie mtimes: {dateadded_iso}: {e}")
|
_log("WARNING", f"Bad timestamp for movie mtimes: {dateadded_iso}: {e}")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user