summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2009-10-20 15:18:08 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2009-10-20 15:18:08 -0400
commit19059bb3b164b6baf3102ab5237e41b398a07a29 (patch)
treeb3f0f345a60048dd7a180bbdefa68d1d7f4697eb
parentFinished implementation. (diff)
downloadFramedPrototype-19059bb3b164b6baf3102ab5237e41b398a07a29.tar.xz
FramedPrototype-19059bb3b164b6baf3102ab5237e41b398a07a29.zip
Fixed IMDB cast loading mechanism by using the good old indexing technique of yesteryear.
-rw-r--r--framed.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/framed.py b/framed.py
index e36616d..75b3553 100644
--- a/framed.py
+++ b/framed.py
@@ -57,7 +57,6 @@ class AnswerQuestion(webapp.RequestHandler):
class LoadNewTitles(webapp.RequestHandler):
def __init__(self):
self.api = AnyClipAPI("CAD58B9E-F045-492F-81B9-22CFE6B00604")
- self.imdbPattern = re.compile("<td class=\"nm\"><a href=\"/name/nm[0-9]{7}/\" onclick=\"\\(new Image\\(\\)\\)\\.src='/rg/castlist/position-[0-9]{1,2}/images/b\\.gif\\?link=/name/nm[0-9]{7}/';\">([^><]+)</a></td><td class=\"ddd\"> \\.\\.\\. </td><td class=\"char\">(?:<a href=\"/character/ch[0-9]{7}/\">([^><]+)</a>[^><]*|([^><]*))</td>")
def getCast(self, imdbCode):
imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % imdbCode)
@@ -73,11 +72,20 @@ class LoadNewTitles(webapp.RequestHandler):
i = 0
actors = []
characters = []
- for match in self.imdbPattern.finditer(imdbList.content):
- actors.append(match.group(1))
- character = match.group(2)
- if character == None:
- character = match.group(3)
+ index = 0
+ htmlRemove = re.compile("<.*?>")
+ while True:
+ index = imdbList.content.find("<td class=\"nm\">", index) + 15
+ end = imdbList.content.find("</td>", index)
+ if index < 15 or end < 0:
+ break
+ actor = htmlRemove.sub("", imdbList.content[index:end])
+ index = imdbList.content.find("<td class=\"ddd\"> ... </td><td class=\"char\">", end) + 43
+ end = imdbList.content.find("</td>", index)
+ if index < 43 or end < 0:
+ break
+ character = htmlRemove.sub("", imdbList.content[index:end])
+ actors.append(actor)
characters.append(character)
i += 1
if i == 10: