Repository navigation
Expand file tree
/
Copy pathImdb.py
More file actions
57 lines (47 loc) · 2.42 KB
/
Copy pathImdb.py
File metadata and controls
57 lines (47 loc) · 2.42 KB
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
from Episode import Episode
from RatingSite import RatingSite
import WebUtils
class Imdb(RatingSite):
season_prefix = "http://www.imdb.com"
season_postfix = "episodes?season="
episode_prefix = "https://www.imdb.com"
episode_postfix = ""
search_prefix = "http://www.imdb.com/find?ref_=nv_sr_fn&q="
search_postfix = "&s=all"
ratingTag = "star__rating\">"
titleTag = "title=\""
def resolveTitle(self, title):
searchUrl = Imdb.search_prefix + title.strip().replace(" ", "%20") + Imdb.search_postfix
content = WebUtils.getContent(searchUrl)
resultsStart = content[content.find("result_text"):]
idStart = resultsStart[resultsStart.find("/title/"):]
id = idStart[:idStart.find('"')] # this used to be '?ref' but that broke?
trueTitle = idStart[idStart.find(">") + 1:idStart.find("<")]
return (id[:100], trueTitle[:100])
def getEpisodes(self, id):
episodesUrl = Imdb.season_prefix + id + Imdb.season_postfix
episodes = []
season = 1
foundSomething = True
while foundSomething:
i = 0
content = WebUtils.getContent(episodesUrl + str(season))
foundSomething = False
workingContent = content[content.find("numberofEpisodes"):]
while "episodeNumber" in workingContent:
workingContent = workingContent[workingContent.find("a href=\"/title/") + 8:]
episode = workingContent[:workingContent.find('"')] # this used to be '?ref' but that broke?
workingContent = workingContent[workingContent.find('"'):] # this used to be '?ref' but that broke?
if episode not in map(lambda e: e.id, episodes):
# get title:
workingContent = workingContent[workingContent.find(Imdb.titleTag) + len(Imdb.titleTag):]
title = workingContent[:workingContent.find("\"")]
#get rating:
workingContent = workingContent[workingContent.find(Imdb.ratingTag) + len(Imdb.ratingTag):]
rating = float(workingContent[:workingContent.find("<")])
#append to list:
episodes.append(Episode(episode, title, season, i, rating))
foundSomething = True
i += 1
season += 1
return episodes