mirror of
https://github.com/markbeep/AudioBookRequest.git
synced 2026-01-06 05:30:14 -06:00
Merge pull request #49 from markbeep/45-auto-download-keyerror-infourl
make infourl optional and add logging for failed sources from prowlarr
This commit is contained in:
@@ -133,7 +133,7 @@ class BaseSource(BaseModel):
|
||||
title: str
|
||||
size: int # in bytes
|
||||
publish_date: datetime
|
||||
info_url: str
|
||||
info_url: Optional[str]
|
||||
indexer_flags: list[str]
|
||||
download_url: Optional[str] = None
|
||||
magnet_url: Optional[str] = None
|
||||
|
||||
@@ -169,44 +169,51 @@ async def query_prowlarr(
|
||||
|
||||
sources: list[ProwlarrSource] = []
|
||||
for result in search_results:
|
||||
if result["protocol"] not in ["torrent", "usenet"]:
|
||||
print("Skipping source with unknown protocol", result["protocol"])
|
||||
continue
|
||||
if result["protocol"] == "torrent":
|
||||
sources.append(
|
||||
TorrentSource(
|
||||
protocol="torrent",
|
||||
guid=result["guid"],
|
||||
indexer_id=result["indexerId"],
|
||||
indexer=result["indexer"],
|
||||
title=result["title"],
|
||||
seeders=result.get("seeders", 0),
|
||||
leechers=result.get("leechers", 0),
|
||||
size=result.get("size", 0),
|
||||
info_url=result["infoUrl"],
|
||||
indexer_flags=[x.lower() for x in result.get("indexerFlags", [])],
|
||||
download_url=result.get("downloadUrl"),
|
||||
magnet_url=result.get("magnetUrl"),
|
||||
publish_date=datetime.fromisoformat(result["publishDate"]),
|
||||
try:
|
||||
if result["protocol"] not in ["torrent", "usenet"]:
|
||||
print("Skipping source with unknown protocol", result["protocol"])
|
||||
continue
|
||||
if result["protocol"] == "torrent":
|
||||
sources.append(
|
||||
TorrentSource(
|
||||
protocol="torrent",
|
||||
guid=result["guid"],
|
||||
indexer_id=result["indexerId"],
|
||||
indexer=result["indexer"],
|
||||
title=result["title"],
|
||||
seeders=result.get("seeders", 0),
|
||||
leechers=result.get("leechers", 0),
|
||||
size=result.get("size", 0),
|
||||
info_url=result.get("infoUrl"),
|
||||
indexer_flags=[
|
||||
x.lower() for x in result.get("indexerFlags", [])
|
||||
],
|
||||
download_url=result.get("downloadUrl"),
|
||||
magnet_url=result.get("magnetUrl"),
|
||||
publish_date=datetime.fromisoformat(result["publishDate"]),
|
||||
)
|
||||
)
|
||||
)
|
||||
else:
|
||||
sources.append(
|
||||
UsenetSource(
|
||||
protocol="usenet",
|
||||
guid=result["guid"],
|
||||
indexer_id=result["indexerId"],
|
||||
indexer=result["indexer"],
|
||||
title=result["title"],
|
||||
grabs=result.get("grabs"),
|
||||
size=result.get("size", 0),
|
||||
info_url=result["infoUrl"],
|
||||
indexer_flags=[x.lower() for x in result.get("indexerFlags", [])],
|
||||
download_url=result.get("downloadUrl"),
|
||||
magnet_url=result.get("magnetUrl"),
|
||||
publish_date=datetime.fromisoformat(result["publishDate"]),
|
||||
else:
|
||||
sources.append(
|
||||
UsenetSource(
|
||||
protocol="usenet",
|
||||
guid=result["guid"],
|
||||
indexer_id=result["indexerId"],
|
||||
indexer=result["indexer"],
|
||||
title=result["title"],
|
||||
grabs=result.get("grabs"),
|
||||
size=result.get("size", 0),
|
||||
info_url=result.get("infoUrl"),
|
||||
indexer_flags=[
|
||||
x.lower() for x in result.get("indexerFlags", [])
|
||||
],
|
||||
download_url=result.get("downloadUrl"),
|
||||
magnet_url=result.get("magnetUrl"),
|
||||
publish_date=datetime.fromisoformat(result["publishDate"]),
|
||||
)
|
||||
)
|
||||
)
|
||||
except KeyError as e:
|
||||
logger.error("Failed to parse source: %s. KeyError: %s", result, e)
|
||||
|
||||
prowlarr_source_cache.set(sources, query)
|
||||
|
||||
|
||||
@@ -44,7 +44,9 @@
|
||||
<th>{{ loop.index }}</th>
|
||||
|
||||
<td>
|
||||
<a href="{{ source.info_url }}" class="link">{{ source.title }}</a>
|
||||
{% if source.info_url %}<a href="{{ source.info_url }}" class="link"
|
||||
>{{ source.title }}</a
|
||||
>{% else %}{{ source.title }}{% endif %}
|
||||
</td>
|
||||
<td>{{ source.indexer }}</td>
|
||||
<td>{{ source.indexer_flags|join(', ') }}</td>
|
||||
|
||||
Reference in New Issue
Block a user