Simpler and cross-platform added_on timestamp determination.
This commit is contained in:
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
import unicodedata
|
import unicodedata
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
@@ -11,9 +10,6 @@ from aiopathlib import AsyncPath
|
|||||||
# Default output folder name (created at common root of scanned paths)
|
# Default output folder name (created at common root of scanned paths)
|
||||||
DEFAULT_OUTPUT_FOLDER = ".mediahive"
|
DEFAULT_OUTPUT_FOLDER = ".mediahive"
|
||||||
|
|
||||||
# Threshold for considering atime "too close" to current time (1 hour)
|
|
||||||
_ATIME_FRESHNESS_THRESHOLD = 3600
|
|
||||||
|
|
||||||
# Resolution priority for quality sorting (higher = better)
|
# Resolution priority for quality sorting (higher = better)
|
||||||
RESOLUTION_PRIORITY = {
|
RESOLUTION_PRIORITY = {
|
||||||
"8K": 5,
|
"8K": 5,
|
||||||
@@ -108,10 +104,9 @@ def normalize_resolution_label(value: str | None) -> str | None:
|
|||||||
async def get_added_timestamp(path: Path) -> int | None:
|
async def get_added_timestamp(path: Path) -> int | None:
|
||||||
"""Get the timestamp when a torrent was added to the collection.
|
"""Get the timestamp when a torrent was added to the collection.
|
||||||
|
|
||||||
Heuristic:
|
Best-effort rule:
|
||||||
- For directories: use ctime (most accurate for torrent folder creation)
|
- On Windows: use ctime (creation-time semantics)
|
||||||
- For files: use atime unless it's too close to current time (suggesting
|
- On other OSes: use mtime (ctime is metadata-change time on Unix)
|
||||||
the filesystem updates atime on reads), otherwise use max(mtime, ctime)
|
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Unix timestamp as int, or None if path doesn't exist
|
Unix timestamp as int, or None if path doesn't exist
|
||||||
@@ -122,17 +117,9 @@ async def get_added_timestamp(path: Path) -> int | None:
|
|||||||
stat_info = await ap.stat()
|
stat_info = await ap.stat()
|
||||||
except OSError, PermissionError:
|
except OSError, PermissionError:
|
||||||
return None
|
return None
|
||||||
|
if os.name == "nt":
|
||||||
if await ap.is_dir():
|
|
||||||
return int(stat_info.st_ctime)
|
return int(stat_info.st_ctime)
|
||||||
|
return int(stat_info.st_mtime)
|
||||||
now = time.time()
|
|
||||||
atime = stat_info.st_atime
|
|
||||||
|
|
||||||
if now - atime < _ATIME_FRESHNESS_THRESHOLD:
|
|
||||||
return int(max(stat_info.st_mtime, stat_info.st_ctime))
|
|
||||||
|
|
||||||
return int(atime)
|
|
||||||
|
|
||||||
|
|
||||||
def get_directory_size(path: Path) -> int:
|
def get_directory_size(path: Path) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user