summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--framed.py94
-rwxr-xr-xzx2c4support/thumblisting.py36
-rwxr-xr-xzx2c4support/upload.sh1
3 files changed, 93 insertions, 38 deletions
diff --git a/framed.py b/framed.py
index 41447fe..0e8acdf 100644
--- a/framed.py
+++ b/framed.py
@@ -28,46 +28,64 @@ class Title(db.Model):
code = db.StringProperty(required=True)
actors = db.StringListProperty()
characters = db.StringListProperty()
+ lastThumb = db.IntegerProperty()
class LoadNewTitles(webapp.RequestHandler):
- def get(self):
- api = AnyClipAPI("CAD58B9E-F045-492F-81B9-22CFE6B00604")
- index = 0
- 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>")
- while True:
- response = api.request("titles", ("recent", index, 20))
- index += 20
- for item in response["Items"]:
- if Title.all().filter('code = ', item["Code"]).count() == 0:
- self.response.out.write("Adding %s<br>" % item["Name"])
- newTitle = Title(title=item["Name"], code=item["Code"])
-
- imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % item["ImdbID"])
- i = 0
- while imdbList.status_code != 200:
- i += 1
- if i == 5:
- break
- sleep(3)
- imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % item["ImdbID"])
- if imdbList.status_code != 200:
- self.response.out.write("Could not add cast of %s<br>" % item["Name"])
- continue
- i = 0
- for match in imdbPattern.finditer(imdbList.content):
- newTitle.actors.append(match.group(1))
- character = match.group(2)
- if character == None:
- character = match.group(3)
- newTitle.characters.append(character)
- i += 1
- if i == 10:
- break
- newTitle.put()
- else:
- index = response["TotalItemCount"]
- break
- if index >= response["TotalItemCount"]:
+ 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)
+ i = 0
+ while imdbList.status_code != 200:
+ i += 1
+ if i == 5:
+ break
+ sleep(3)
+ imdbList = fetch("http://www.imdb.com/title/tt%s/fullcredits" % imdbCode)
+ if imdbList.status_code != 200:
+ return None
+ 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)
+ characters.append(character)
+ i += 1
+ if i == 10:
break
+ return (actors, characters)
+
+ def get(self):
+ thumbListing = fetch("http://anyclip.zx2c4.com/thumblisting.py")
+ if thumbListing.status_code != 200:
+ self.response.out.write("error")
+ return
+ movies = thumbListing.content.split("\n")
+ for movie in movies:
+ codeThumb = movie.split(" ")
+ if len(codeThumb) != 2:
+ continue
+ code = codeThumb[0]
+ lastThumb = int(codeThumb[1])
+ if Title.all().filter('code = ', code).count() == 0:
+ item = self.api.request("title", (code,))
+ if len(item) == 2 and item[0] == '1005':
+ self.response.out.write("Could not add invalid code %s<br>" % code)
+ continue
+ self.response.out.write("Adding %s<br>" % item["Name"])
+ newTitle = Title(title=item["Name"], code=item["Code"])
+ newTitle.lastThumb = lastThumb
+ cast = self.getCast(item["ImdbID"])
+ if cast == None:
+ self.response.out.write("Could not add cast of %s<br>" % item["Name"])
+ continue
+ newTitle.actors = cast[0]
+ newTitle.characters = cast[1]
+ newTitle.put()
application = webapp.WSGIApplication(
diff --git a/zx2c4support/thumblisting.py b/zx2c4support/thumblisting.py
new file mode 100755
index 0000000..7524e9c
--- /dev/null
+++ b/zx2c4support/thumblisting.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+# -*- coding: iso-8859-1 -*-
+
+from ftplib import FTP
+import os
+import os.path
+
+print "Content-Type: text/plain"
+print
+
+if not os.path.exists("framedcache"):
+ os.mkdir("framedcache")
+ftp = FTP("ftp2.edgecastcdn.net")
+ftp.login("chris@anyclip.com", "ChrisEdge1234")
+for movie in ftp.nlst("thumbnails"):
+ movieCode = movie[movie.find("/") + 1:]
+ if os.path.exists("framedcache/%s" % movieCode):
+ cache = open("framedcache/%s" % movieCode, "r")
+ print movieCode,
+ print cache.read()
+ cache.close()
+ continue
+ biggest = -1
+ for thumb in ftp.nlst(movie):
+ try:
+ timeCode = int(thumb[thumb.find("_") + 1:thumb.rfind("_")])
+ except:
+ timeCode = -1
+ if timeCode > biggest:
+ biggest = timeCode
+ if biggest > -1:
+ cache = open("framedcache/%s" % movieCode, "w")
+ cache.write(str(biggest))
+ cache.close()
+ print movieCode,
+ print biggest \ No newline at end of file
diff --git a/zx2c4support/upload.sh b/zx2c4support/upload.sh
new file mode 100755
index 0000000..734d02e
--- /dev/null
+++ b/zx2c4support/upload.sh
@@ -0,0 +1 @@
+scp *.py zx2c4.com:/home/zx2c4/anyclip.zx2c4.com/