sane-bt-search: more precisely specify the --tracker argument options
This commit is contained in:
@@ -78,6 +78,7 @@ def parse_time(t: str) -> datetime:
|
|||||||
|
|
||||||
@dataclass(eq=True, order=True, unsafe_hash=True)
|
@dataclass(eq=True, order=True, unsafe_hash=True)
|
||||||
class Tracker:
|
class Tracker:
|
||||||
|
id_: str
|
||||||
name: str
|
name: str
|
||||||
# preference: major, minor.
|
# preference: major, minor.
|
||||||
# lower value = more preferable.
|
# lower value = more preferable.
|
||||||
@@ -86,14 +87,14 @@ class Tracker:
|
|||||||
order: int
|
order: int
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def by_name(name: str) -> 'Tracker':
|
def by_id(id_: str) -> 'Tracker':
|
||||||
if name in KNOWN_TRACKERS:
|
if id_ in KNOWN_TRACKERS:
|
||||||
return KNOWN_TRACKERS[name]
|
return KNOWN_TRACKERS[id_]
|
||||||
logger.warning(f"unknown tracker: {name!r}")
|
logger.warning(f"unknown tracker: {id_!r}")
|
||||||
return Tracker(name, TrackerQuality.Unknown, len(KNOWN_TRACKERS))
|
return Tracker(id_, TrackerQuality.Unknown, len(KNOWN_TRACKERS))
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return self.name
|
return self.id_
|
||||||
|
|
||||||
def _KNOWN_TRACKERS() -> dict[str, Tracker]:
|
def _KNOWN_TRACKERS() -> dict[str, Tracker]:
|
||||||
trackers = {}
|
trackers = {}
|
||||||
@@ -103,28 +104,28 @@ def _KNOWN_TRACKERS() -> dict[str, Tracker]:
|
|||||||
nonlocal order
|
nonlocal order
|
||||||
t = Tracker(*args, order)
|
t = Tracker(*args, order)
|
||||||
order += 1
|
order += 1
|
||||||
trackers[t.name] = t
|
trackers[t.id_] = t
|
||||||
|
|
||||||
# the order of this list (even withint sections) is significant:
|
# the order of this list (even withint sections) is significant:
|
||||||
# most preferred -> least preferred
|
# most preferred -> least preferred
|
||||||
add_tracker('BitMagnet (Local DHT)', TrackerQuality.Authoritative)
|
add_tracker('bitmagnet', 'BitMagnet (Local DHT)', TrackerQuality.Authoritative)
|
||||||
|
|
||||||
add_tracker('BakaBT', TrackerQuality.Trustworthy)
|
add_tracker('bakabt', 'BakaBT', TrackerQuality.Trustworthy)
|
||||||
add_tracker('SubsPlease', TrackerQuality.Trustworthy)
|
add_tracker('subsplease', 'SubsPlease', TrackerQuality.Trustworthy)
|
||||||
add_tracker('Nyaa.si', TrackerQuality.Trustworthy)
|
add_tracker('nyaasi', 'Nyaa.si', TrackerQuality.Trustworthy)
|
||||||
add_tracker('sukebei.nyaa.si', TrackerQuality.Trustworthy)
|
add_tracker('sukebeinyaasi', 'sukebei.nyaa.si', TrackerQuality.Trustworthy)
|
||||||
|
|
||||||
add_tracker('YTS', TrackerQuality.Good)
|
add_tracker('yts', 'YTS', TrackerQuality.Good)
|
||||||
add_tracker('Tokyo Toshokan', TrackerQuality.Good)
|
add_tracker('tokyotosho', 'Tokyo Toshokan', TrackerQuality.Good)
|
||||||
|
|
||||||
add_tracker('Internet Archive', TrackerQuality.Mediocre)
|
add_tracker('internetarchive', 'Internet Archive', TrackerQuality.Mediocre)
|
||||||
add_tracker('The Pirate Bay', TrackerQuality.Mediocre)
|
add_tracker('thepiratebay', 'The Pirate Bay', TrackerQuality.Mediocre)
|
||||||
add_tracker('MioBT', TrackerQuality.Mediocre)
|
add_tracker('miobt', 'MioBT', TrackerQuality.Mediocre)
|
||||||
add_tracker('Bengumi Moe', TrackerQuality.Mediocre)
|
add_tracker('bangumi-moe', 'Bangumi Moe', TrackerQuality.Mediocre)
|
||||||
add_tracker('Torlock', TrackerQuality.Mediocre)
|
add_tracker('torlock', 'Torlock', TrackerQuality.Mediocre)
|
||||||
|
|
||||||
add_tracker('1337x', TrackerQuality.Bad)
|
# add_tracker(UNKNOWN_ID, '1337x', TrackerQuality.Bad)
|
||||||
add_tracker('kickasstorrents.to', TrackerQuality.Bad)
|
# add_tracker(UNKNOWN_ID, 'kickasstorrents.to', TrackerQuality.Bad)
|
||||||
|
|
||||||
return trackers
|
return trackers
|
||||||
|
|
||||||
@@ -237,14 +238,14 @@ class Torrent:
|
|||||||
"Seeders",
|
"Seeders",
|
||||||
"Size",
|
"Size",
|
||||||
"Title",
|
"Title",
|
||||||
"Tracker",
|
"TrackerId",
|
||||||
) and v != None and v != "" and v != [] and v != {}:
|
) and v != None and v != "" and v != [] and v != {}:
|
||||||
logger.debug(f" {k} = {v}")
|
logger.debug(f" {k} = {v}")
|
||||||
|
|
||||||
seeders = d.get("Seeders")
|
seeders = d.get("Seeders")
|
||||||
pub_date = d.get("PublishDate")
|
pub_date = d.get("PublishDate")
|
||||||
size = d.get("Size")
|
size = d.get("Size")
|
||||||
tracker = d.get("Tracker")
|
tracker_id = d.get("TrackerId")
|
||||||
title = d.get("Title")
|
title = d.get("Title")
|
||||||
info_hash = d.get("InfoHash")
|
info_hash = d.get("InfoHash")
|
||||||
magnet = d.get("MagnetUri") or d.get("Guid")
|
magnet = d.get("MagnetUri") or d.get("Guid")
|
||||||
@@ -278,7 +279,7 @@ class Torrent:
|
|||||||
seeders=seeders,
|
seeders=seeders,
|
||||||
pub_date=pub_date,
|
pub_date=pub_date,
|
||||||
size=size,
|
size=size,
|
||||||
tracker=Tracker.by_name(tracker),
|
tracker=Tracker.by_id(tracker_id),
|
||||||
title=title,
|
title=title,
|
||||||
info_hash=info_hash,
|
info_hash=info_hash,
|
||||||
magnet=magnet,
|
magnet=magnet,
|
||||||
@@ -361,9 +362,7 @@ def main(args: list[str]):
|
|||||||
parser.add_argument('--top', help=f'how many results to show (default: {DEFAULT_RESULT_COUNT})')
|
parser.add_argument('--top', help=f'how many results to show (default: {DEFAULT_RESULT_COUNT})')
|
||||||
parser.add_argument('--sort-by', default=SortMethod.Balanced, type=SortMethod, help='how to rank matches (seeders, tracker)')
|
parser.add_argument('--sort-by', default=SortMethod.Balanced, type=SortMethod, help='how to rank matches (seeders, tracker)')
|
||||||
parser.add_argument('--json', action='store_true', help='output results in json')
|
parser.add_argument('--json', action='store_true', help='output results in json')
|
||||||
# TODO: add `choices`, populated from the API name of each KNOWN_TRACKERS.
|
parser.add_argument('--tracker', type=str, action='append', help='query only this tracker(s)', choices=KNOWN_TRACKERS.keys())
|
||||||
# (i.e. 'TrackerId' instead of 'Tracker' field)
|
|
||||||
parser.add_argument('--tracker', type=str, action='append', help='query only this tracker(s) e.g. "bitmagnet" or "bakabt"')
|
|
||||||
parser.add_argument('--verbose', action='store_true')
|
parser.add_argument('--verbose', action='store_true')
|
||||||
parser.add_argument('--book', action='store_true', help='show only book (ebook or audiobook) results')
|
parser.add_argument('--book', action='store_true', help='show only book (ebook or audiobook) results')
|
||||||
parser.add_argument('--h265', action='store_true', help='show only H.265/HEVC results (might cause false negatives)')
|
parser.add_argument('--h265', action='store_true', help='show only H.265/HEVC results (might cause false negatives)')
|
||||||
|
Reference in New Issue
Block a user