Added Search on KNPY

This commit is contained in:
FairTrade 2026-03-04 21:54:41 +01:00
parent 1d39cf68e5
commit 6509198610
2 changed files with 46 additions and 34 deletions

View File

@ -5,6 +5,7 @@ from datetime import datetime, timezone
from http.cookiejar import CookieJar
from typing import List, Optional
from collections.abc import Generator
import click
import jwt
from langcodes import Language
@ -365,43 +366,54 @@ class KNPY(Service):
r.raise_for_status()
return r.content
# def search(self) -> List[SearchResult]:
# if not hasattr(self, 'search_query'):
# self.log.error("Search query not set. Cannot search.")
# return []
def search(self) -> Generator[SearchResult, None, None]:
if not hasattr(self, 'search_query') or not self.search_query:
self.log.error("Search query not set. Cannot search.")
return
# self.log.info(f"Searching for '{self.search_query}'...")
# params = {
# "query": self.search_query,
# "sort": "relevance",
# "domainId": self._domain_id,
# "page": 0,
# "perPage": 20
# }
# r = self.session.get(self.config["endpoints"]["search"], params=params)
# r.raise_for_status()
# search_data = r.json()
self.log.info(f"Searching for '{self.search_query}'...")
# Ensure we have a domain ID (Library ID) before searching
if not self._domain_id:
self._fetch_user_details()
# results = []
# for item in search_data.get("list", []):
# item_type = item.get("type")
# if item_type not in ["playlist", "video"]:
# continue
params = {
"query": self.search_query,
"sort": "relevance",
"domainId": self._domain_id,
"isKids": "false",
"page": 0,
"perPage": 40
}
# video_id = item.get("videoId")
# title = item.get("title", "No Title")
# label = "Series" if item_type == "playlist" else "Movie"
r = self.session.get(self.config["endpoints"]["search"], params=params)
r.raise_for_status()
search_data = r.json()
# The API returns results in a "list" key
results_list = search_data.get("list", [])
if not results_list:
self.log.warning(f"No results found for '{self.search_query}'")
return
for item in results_list:
# Kanopy search results use 'videoId' as the unique identifier
video_id = item.get("videoId")
if not video_id:
continue
title = item.get("title", "Unknown Title")
# results.append(
# SearchResult(
# id_=str(video_id),
# title=title,
# description="",
# label=label,
# url=f"https://www.kanopy.com/watch/{video_id}"
# )
# )
# return results
# Since the search API doesn't explicitly return "type",
# we provide a generic label or try to guess.
# In your get_titles logic, you handle both, so we point to the watch URL.
yield SearchResult(
id_=str(video_id),
title=title,
label="VIDEO/SERIES",
url=f"https://www.kanopy.com/video/{video_id}"
)
def get_chapters(self, title: Title_T) -> list:
return []

View File

@ -26,7 +26,7 @@
- Subtitle has little quirk of having javanese and sundanese language labeled on the HLS one but not the DASH one
- Search functionality not available yet
8. KNPY:
- Need to fix the search function
- HLS downloading is not working
9. VRT:
- Search functionality
- Fixing few hickups