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 http.cookiejar import CookieJar
from typing import List, Optional from typing import List, Optional
from collections.abc import Generator
import click import click
import jwt import jwt
from langcodes import Language from langcodes import Language
@ -365,43 +366,54 @@ class KNPY(Service):
r.raise_for_status() r.raise_for_status()
return r.content return r.content
# def search(self) -> List[SearchResult]: def search(self) -> Generator[SearchResult, None, None]:
# if not hasattr(self, 'search_query'): if not hasattr(self, 'search_query') or not self.search_query:
# self.log.error("Search query not set. Cannot search.") self.log.error("Search query not set. Cannot search.")
# return [] return
# self.log.info(f"Searching for '{self.search_query}'...") 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()
# results = [] # Ensure we have a domain ID (Library ID) before searching
# for item in search_data.get("list", []): if not self._domain_id:
# item_type = item.get("type") self._fetch_user_details()
# if item_type not in ["playlist", "video"]:
# continue
# video_id = item.get("videoId") params = {
# title = item.get("title", "No Title") "query": self.search_query,
# label = "Series" if item_type == "playlist" else "Movie" "sort": "relevance",
"domainId": self._domain_id,
"isKids": "false",
"page": 0,
"perPage": 40
}
# results.append( r = self.session.get(self.config["endpoints"]["search"], params=params)
# SearchResult( r.raise_for_status()
# id_=str(video_id), search_data = r.json()
# title=title,
# description="", # The API returns results in a "list" key
# label=label, results_list = search_data.get("list", [])
# url=f"https://www.kanopy.com/watch/{video_id}"
# ) if not results_list:
# ) self.log.warning(f"No results found for '{self.search_query}'")
# return results 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")
# 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: def get_chapters(self, title: Title_T) -> list:
return [] 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 - 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 - Search functionality not available yet
8. KNPY: 8. KNPY:
- Need to fix the search function - HLS downloading is not working
9. VRT: 9. VRT:
- Search functionality - Search functionality
- Fixing few hickups - Fixing few hickups