-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmklist-cinemovies
executable file
·170 lines (159 loc) · 4.95 KB
/
mklist-cinemovies
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Fetch list of movies listed on CineMovies. It should only include
public domain movies.
More information on the site (since renamed from Moovies), is
available from
http://caferoxy.blogspot.no/2010/06/free-moovies-online.html.
"""
import argparse
import json
import lxml.html
import movielib
import re
import urllib2
def got_movie(l, ref):
if ref in l:
return True
else:
for e in l.keys():
if ref == l[e]['freenessurl']:
return True
return False
def process_genre_page(args, l, root):
for m in root.cssselect("article.movies"):
entryurl = m.cssselect("a[href]")[0].attrib['href']
if got_movie(l, entryurl):
return
title = m.cssselect('img[src]')[0].attrib['alt']
title = title.replace(u'’', "'")
title = title.replace(u'‘', "'")
title = title.replace(u'–', "-")
title = title.replace(u'è', "e")
year = None
for mspan in m.cssselect('div.metadata span'):
m = re.search("(\d{4})", mspan.text_content())
if m:
year = int(m.group(1))
print title, year, entryurl
info = {
'status' : 'free',
'freenessurl' : entryurl,
'title' : title,
'year' : year,
}
ref = entryurl
if args.imdblookup:
imdb = movielib.imdb_find_one(title, year)
if imdb:
ref = imdb
info['imdblookup'] = '%s %d' % (title, year)
l[ref] = info
def fetch_movie_genre(args, l, url):
try:
root = lxml.html.fromstring(movielib.http_get_read(url))
except urllib2.HTTPError as e:
return None
process_genre_page(args, l, root)
maxpage = None
p = root.cssselect('div.pagination span')
if p:
m = re.search("Page \d+ of (\d+)", p[0].text_content())
if m:
maxpage = int(m.group(1))
if 1 < maxpage:
for page in range(2, maxpage+1):
pageurl = url + "/page/%d/" % page
print pageurl
try:
root = lxml.html.fromstring(movielib.http_get_read(pageurl))
except urllib2.HTTPError as e:
return None
process_genre_page(args, l, root)
return l
def fetch_json_list(args, l):
#term = '09' a-z
terms = ['09']
terms.extend(map(chr, xrange(ord('a'), ord('z'))))
for term in terms:
for type in ['movies', 'tvshows']:
url = 'https://www.cinemovies.video/wp-json/dooplay/glossary/?term=%s&nonce=834d14234c&type=%s' % (term, type)
#print url
s = movielib.http_get_read(url)
j = json.loads(s)
if u'error' in j:
continue
#print j
for id in j.keys():
if got_movie(l, j[id]['url']):
continue
title = j[id]['title']
info = {
'title' : title,
'status' : 'free',
'freenessurl' : j[id]['url'],
}
if 'year' in j[id]:
# try/except as workaround for year == '02-1'
try:
year = int(j[id]['year'])
info['year'] = year
except ValueError:
year = None
else:
year = None
ref = j[id]['url']
if args.imdblookup:
imdb = movielib.imdb_find_one(title, year)
if imdb:
ref = imdb
info['imdblookup'] = '%s %d' % (title, year)
l[ref] = info
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--imdblookup', action='store_true', default=False,
help='also find title IDs by searching for title/year in IMDB')
args = parser.parse_args()
# First fetch what can be fetched using a JSON source
l = {}
fetch_json_list(args, l)
# Next, scrape the rest using the genre pages
genres = [
"action",
"action-adventure",
"animated-feature",
"animation",
"comedy",
"crime",
"documentary",
"drama",
"family",
"fantasy",
"foreign",
"history",
"horror",
"kids",
"martial-arts",
"music",
"mystery",
"religious",
"romance",
"science-fiction",
"serial",
"short",
"silent",
"thriller",
"tv-movie",
"tv-series",
"war",
"western",
"xmas",
]
for g in genres:
genreurl = "https://www.cinemovies.video/genre/%s/" % g
print genreurl
l = fetch_movie_genre(args, l, genreurl)
movielib.savelist(l, name='free-movies-cinemovies.json')
if __name__ == '__main__':
main()