Add search
method to main class
This commit is contained in:
parent
4adc30eaab
commit
fca079587d
@ -110,3 +110,22 @@ class MatteBOX:
|
|||||||
variants = m3u8.load(main_playlist_uri)
|
variants = m3u8.load(main_playlist_uri)
|
||||||
playlist = variants.playlists[0]
|
playlist = variants.playlists[0]
|
||||||
return playlist.uri
|
return playlist.uri
|
||||||
|
|
||||||
|
def search(
|
||||||
|
self, query: str, over_18: bool = True, results_count: int = 200
|
||||||
|
) -> List[Program]:
|
||||||
|
res = self.__get("/sws/subscription/search/search.json", params={
|
||||||
|
"audience": "OVER_18" if over_18 else "", # TODO
|
||||||
|
"entityCount": results_count,
|
||||||
|
"firstEntityOffset": 0,
|
||||||
|
"deviceType": "STB",
|
||||||
|
"facetAll": "true",
|
||||||
|
"isp": "1",
|
||||||
|
"language": "eng",
|
||||||
|
"tariff": "FERO Middleware",
|
||||||
|
"search": query,
|
||||||
|
})
|
||||||
|
|
||||||
|
filtered_results = [e for e in res["entities"] if e["type"] == "EPG"]
|
||||||
|
programs = [Program.from_search_result(p) for p in filtered_results]
|
||||||
|
return programs
|
||||||
|
@ -4,8 +4,8 @@ from __future__ import annotations
|
|||||||
class Program:
|
class Program:
|
||||||
"""Class for single TV program or recording with basic information about it.
|
"""Class for single TV program or recording with basic information about it.
|
||||||
|
|
||||||
Methods `from_channel_program` and `from_recording` returns class object
|
Methods `from_channel_program`, `from_recording` and `from_search_result` returns
|
||||||
from data received from API."""
|
class object from data received from API."""
|
||||||
|
|
||||||
name: str
|
name: str
|
||||||
channel: str
|
channel: str
|
||||||
@ -45,5 +45,20 @@ class Program:
|
|||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def from_search_result(cls, data: dict) -> Program:
|
||||||
|
obj = cls()
|
||||||
|
obj.__dict__ = {
|
||||||
|
"name": data["name"],
|
||||||
|
"channel": data["channelKey"],
|
||||||
|
"epg_id": data["id"],
|
||||||
|
"content_id": data["id"],
|
||||||
|
"description": data["description"],
|
||||||
|
"ts_start": data["startTimestamp"],
|
||||||
|
"ts_stop": data["endTimestamp"],
|
||||||
|
"type": "program"
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return f"{self.__class__.__name__}({self.__dict__})"
|
return f"{self.__class__.__name__}({self.__dict__})"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user