forked from Killerkiwi2005/lemontv-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nzfilm.py
84 lines (69 loc) · 2.44 KB
/
nzfilm.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import json
import util
import urllib
# SHIFT API Documentation
# http://indiereign.github.io/shift72-docs/
DATA_URL = 'https://ondemand.nzfilm.co.nz/services/meta/v4/featured/8'
FILM_DETAILS_TEMPLATE = "https://ondemand.nzfilm.co.nz/services/meta/v2{0}/show_multiple"
PRICE_TEMPLATE = "https://ondemand.nzfilm.co.nz/services/pricing/v2/prices/show_multiple?items={0}&location=nz"
URI_TEMPLATE = "https://ondemand.nzfilm.co.nz/#!/browse{0}/{1}"
TV_SEASON_TEMPLATE = "https://ondemand.nzfilm.co.nz/services/meta/v2/tv/season/show_multiple?items={0}"
def get_movie(slug):
# find movie
data = util.get_url_json(FILM_DETAILS_TEMPLATE.format(slug))[0]
price_data = util.get_url_json(PRICE_TEMPLATE.format(slug))
show = {}
show["title"] = data["title"]
show["type"] = "movie"
show["image"] = data["image_urls"]["portrait"]
show["year"] = data["release_date"][:4]
# lowest price
price = ""
if price_data["prices"]:
if price_data["prices"][0]["rent"]["hd"]:
price = price_data["prices"][0]["rent"]["hd"]
else:
price = price_data["prices"][0]["buy"]["hd"]
# every show has an episode even movies
show["episodes"] = [{"show" : data["title"], "uri" : URI_TEMPLATE.format(slug, urllib.parse.quote_plus(data["title"])), "s" : 0, "e" : 0, "price" : price}]
return show
def get_tv(slug):
# find seasons
data = util.get_url_json(TV_SEASON_TEMPLATE.format(slug))["seasons"][0]
price_data = util.get_url_json(PRICE_TEMPLATE.format(slug))
show = {}
show["title"] = data["show_info"]["title"]
show["type"] = "tv"
show["image"] = data["image_urls"]["portrait"]
show["year"] = data["show_info"]["release_date"][:4]
# Price is per season. No prices per episode
# lowest price
price = ""
if price_data["prices"]:
price = price_data["prices"][0]["rent"]["hd"]
print ("TV Price: " + price)
show["episodes"] = []
for e in data["episodes"]:
episode = {}
episode["title"] = e["title"]
episode["uri"] = URI_TEMPLATE.format(slug, urllib.parse.quote_plus(data["show_info"]["title"]))
episode["s"] = data["season_num"]
episode["e"] = e["episode_number"]
episode["price"] = price
show["episodes"].append(episode)
return show
def get_listings():
shows = []
data = util.get_url_json(DATA_URL)
all = []
for slug in data["items"]:
if "/film/" in slug:
shows.append(get_movie(slug))
else:
shows.append(get_tv(slug))
return shows
if __name__ == "__main__":
# Test works
f = open("nzfilm.js", "w")
f.write(json.dumps(get_listings()))
f.close()