Electronic-Mango / simple-justwatch-python-api

A simple (and unofficial) JustWatch Python API.
https://electronic-mango.github.io/simple-justwatch-python-api/
GNU General Public License v3.0
30 stars 6 forks source link

Add support for getting the length of a film #2

Closed abudden closed 8 months ago

abudden commented 8 months ago

I think this is as simple as the following (which seems to work), but I expect there are other things to update like tests / readmes etc.

There might be other things needed I guess to cope with TV Series or whatever (I don't know how consistent the runtime thing is - I only tested it on a couple of films).

diff --git a/src/simplejustwatchapi/query.py b/src/simplejustwatchapi/query.py
index b506a89..e71fbbe 100644
--- a/src/simplejustwatchapi/query.py
+++ b/src/simplejustwatchapi/query.py
@@ -55,6 +55,7 @@ fragment SearchTitleGraphql on PopularTitlesEdge {
         __typename
       }
       posterUrl(profile: $profile, format: $formatPoster)
+      runtime
       backdrops(profile: $backdropProfile, format: $formatPoster) {
         backdropUrl
         __typename
@@ -117,6 +118,7 @@ class MediaEntry(NamedTuple):
     genres: list[str]
     imdb_id: str | None
     poster: str | None
+    runtime_mins: int
     backdrops: list[str]
     offers: list[Offer]

@@ -185,6 +187,7 @@ def _parse_entry(json: any) -> MediaEntry:
     imdb_id = external_ids.get("imdbId") if external_ids else None
     poster_url_field = content.get("posterUrl")
     poster = _IMAGES_URL + poster_url_field if poster_url_field else None
+    runtime_mins = content.get("runtime")
     backdrops = [_IMAGES_URL + bd.get("backdropUrl") for bd in content.get("backdrops", []) if bd]
     offers = [_parse_offer(offer) for offer in json.get("offers", []) if offer]
     return MediaEntry(
@@ -198,6 +201,7 @@ def _parse_entry(json: any) -> MediaEntry:
         genres,
         imdb_id,
         poster,
+        runtime_mins,
         backdrops,
         offers,
     )
Electronic-Mango commented 8 months ago

I've added runtime in 0.12 as runtime_minutes in MediaEntry. I'm not sure what exactly is runtime for TV shows, but on JustWatch website it does show runtime for them. So value of runtime_minutes will be the same as on the website.