1
0
mirror of https://github.com/spaam/svtplay-dl.git synced 2024-11-27 13:44:14 +01:00

tv4play: new way to find episodes and clips related to the show

fixes: 1327
This commit is contained in:
Johan Andersson 2021-02-23 23:45:05 +01:00
parent 145c81c7fc
commit e423c1cd35

View File

@ -92,14 +92,27 @@ class Tv4play(Service, OpenGraphThumbMixin):
match = self._getjson()
jansson = json.loads(match.group(1))
janson2 = jansson["props"]["pageProps"]["initialApolloState"]
for i in janson2:
if "VideoAsset:" in i:
if janson2[i]["clip"] and config.get("include_clips"):
show = janson2[i]["program_nid"]
items.append(janson2[i]["id"])
elif janson2[i]["clip"] is False:
show = janson2[i]["program_nid"]
items.append(janson2[i]["id"])
show = jansson["query"]["nid"]
program = janson2["Program:{}".format(show)]
episodes_panel = []
clips_panel = []
for panel in program["panels"]:
if panel["assetType"] == "EPISODE":
params = json.loads(panel["loadMoreParams"])
if "tags" in params:
for tag in params["tags"].split(","):
episodes_panel.append(tag)
if config.get("include_clips") and panel["assetType"] == "CLIP":
params = json.loads(panel["loadMoreParams"])
if "tags" in params:
for tag in params["tags"].split(","):
clips_panel.append(tag)
if episodes_panel:
items.extend(self._graphql(show, episodes_panel, "EPISODE"))
if clips_panel:
items.extend(self._graphql(show, clips_panel, "CLIP"))
items = sorted(items)
for item in items:
@ -109,6 +122,56 @@ class Tv4play(Service, OpenGraphThumbMixin):
return episodes[-config.get("all_last") :]
return episodes
def _graphql(self, show, panels, panel_type):
items = []
for panel in panels:
offset = 0
total = 9999
moreData = True
while moreData:
gql = {
"variables": {
"offset": offset,
"limit": 50,
"serializedParams": '{"tags":"'
+ panel
+ '","tags_mode":"any","sort_order":"asc","type":"'
+ panel_type.lower()
+ '","is_live":false,"node_nids_mode":"any","nodes_mode":"any"}',
"query": show,
},
"query": "query SearchVideoAsset($query: String, $limit: Int, $offset: Int, $serializedParams: String)"
" {\n videoAssetSearch(q: $query, offset: $offset, type: "
+ panel_type
+ ", limit: $limit, serializedParams: $serializedParams) {\n __typename\n totalHits\n "
"videoAssets {\n __typename\n ...VideoAssetField\n }\n }\n}fragment VideoAssetField "
"on VideoAsset {\n __typename\n id\n title\n tags\n description\n image\n live\n clip\n "
"season\n episode\n hideAds\n categories\n publishedDateTime\n humanPublishedDateTime\n "
"broadcastDateTime\n humanBroadcastDateTime\n humanDaysLeftInService\n humanBroadcastShortDateTime\n "
"expireDateTime\n productGroups\n productGroupNids\n duration\n humanDuration\n drmProtected\n "
"freemium\n geoRestricted\n startOver\n progress {\n __typename\n ...ProgressField\n }\n "
"program {\n __typename\n ...ProgramField\n }\n nextEpisode {\n __typename\n id\n "
"title\n publishedDateTime\n humanPublishedDateTime\n duration\n image\n }\n}"
"fragment ProgressField on Progress {\n __typename\n percentage\n position\n}"
"fragment ProgramField on Program {\n __typename\n nid\n name\n description\n geoRestricted\n "
"carouselImage\n image\n displayCategory\n genres\n logo\n type\n webview2 {\n __typename\n "
"id\n url\n name\n }\n label {\n __typename\n label\n cdpText\n }\n actors\n "
"directors\n upcoming {\n __typename\n id\n image\n episode\n humanBroadcastDateWithWeekday\n "
"title\n }\n images {\n __typename\n main4x3\n main16x9\n main16x7\n main16x9Annotated\n }\n "
"favorite\n keepWatchingIgnored\n cmoreInfo {\n __typename\n text\n link\n }\n trailers "
"{\n __typename\n mp4\n }\n trackingData {\n __typename\n burt {\n __typename\n"
" vmanId\n category\n tags\n }\n }\n}",
}
res = self.http.post("https://graphql.tv4play.se/graphql", json=gql)
total = res.json()["data"]["videoAssetSearch"]["totalHits"]
for asset in res.json()["data"]["videoAssetSearch"]["videoAssets"]:
items.append(asset["id"])
offset += len(res.json()["data"]["videoAssetSearch"]["videoAssets"])
if offset >= total:
moreData = False
return items
class Tv4(Service, OpenGraphThumbMixin):
supported_domains = ["tv4.se"]