forked from Killerkiwi2005/lemontv-scrapers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathezyflix.py
125 lines (99 loc) · 2.84 KB
/
ezyflix.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import lxml.html as lh
from urllib.request import urlopen
import json
from lxml import etree
import re
DATA_URL = 'http://ezyflix.tv/watch-movies?dir=desc&order=created_at&p=%s'
DATA_URL_TV = 'http://ezyflix.tv/watch-tv?dir=desc&order=created_at&p=%s'
EPISODE_DATA = 'http://ezyflix.tv/tvseries/episode/product/id/%s'
def get_episodes(id, series, url):
response = urlopen(EPISODE_DATA % str(id));
data = json.loads(response.read().decode())
episodes = []
print(url)
for obj in data:
e = 0
name = obj["name"]
matches = re.search(r"^Episode ([\d]+) : ", name.strip())
if matches:
e = matches.group(1)
name = name[len(matches.group(0)):]
price = float(re.search(r"[\d\.]+", obj["price"]).group(0))
episode = {}
episode["show"] = name
episode["title"] = name
episode["uri"] = url
episode["s"] = series
episode["e"] = e
episode["price"] = price
is_new = True
for x in episodes:
if x["e"] == e:
is_new = False
if x["price"] > price:
x["price"] = price
break
if is_new:
print(series, e, name, price)
episodes.append(episode)
return episodes
def get_listings():
page = 1
totalPages = 1
shows = []
while page <= totalPages:
response = urlopen(DATA_URL % str(page));
data = json.loads(response.read().decode())
totalPages = data["totalPages"]
for product in data["data"]:
show = {}
show["title"] = product["name"]
show["image"] = product["imageUrl"]
show["type"] = "movie"
print(show["title"],product["prodUrl"])
# get price from data url
try:
doc = lh.parse(urlopen( product["prodUrl"]))
prices = doc.xpath(".//span[contains(@class, 'price')]")
if len(prices) > 0:
price = prices[0].text.strip()[1:]
print(price)
show["episodes"] = [{"show" : product["name"], "uri" : product["prodUrl"], "s" : 0, "e" : 0, "price" : price}]
shows.append(show)
except:
pass
page = page + 1
page = 1
totalPages = 1
while page <= totalPages:
response = urlopen(DATA_URL_TV % str(page));
data = json.loads(response.read().decode())
totalPages = data["totalPages"]
for product in data["data"]:
show = {}
id = product["id"]
series = 0
title = re.sub( r' (Series|Season) \d+[a-zA-Z]?\b', '', product["name"].strip() )
matches = re.search(r"\d+[a-zA-Z]?\b", product["name"].strip())
if matches:
series = matches.group(0)
episodes = get_episodes(id, series, product["prodUrl"])
for x in shows:
# merge seasons
if x["title"] == title:
x["episodes"] = x["episodes"] + episodes
break
else:
# new show
show = {}
show["title"] = title
show["type"] = "tv"
show["episodes"] = episodes
show["image"] = product["imageUrl"]
shows.append(show)
page = page + 1
return shows
if __name__ == "__main__":
f = open("ezyflix.js", "w")
f.write(json.dumps(get_listings()))
f.close()