-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpull_trailers.py
85 lines (60 loc) · 2.61 KB
/
pull_trailers.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
#This file is part of the Kivy Cinema Kiosk Demo.
# Copyright (C) 2010 by
# Thomas Hansen <[email protected]>
# Mathieu Virbel <[email protected]>
#
# The Kivy Cinema Kiosk Demo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# The Kivy Cinema Kiosk Demo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with The Kivy Cinema Kiosk Demo. If not, see <http://www.gnu.org/licenses/>.
import feedparser
import subprocess
import urllib
import shelve
from movie import Movie
import json, pprint
def download_trailer(url):
#first lets just open URL using fake user agent, to see if
# resource exists
class QuickTimeURLopener(urllib.FancyURLopener):
version = "Quicktime"
urllib._urlopener = QuickTimeURLopener()
if urllib.urlopen(url).getcode() != 200:
return False # no usch file...just ignore it
#ok, have wget download it in teh background (unless already there)
#wget_args = ['wget', '-q', '-N', '-U', 'QuickTime', url]
#subprocess.Popen(wget_args, cwd='content/trailers')
return True
def get_movie_data():
#movie_shelve = shelve.open('movie.shelve')
data = {}
apple_rss = "http://trailers.apple.com/trailers/home/rss/newtrailers.rss"
feed = feedparser.parse(apple_rss)
for e in feed.entries:
#check if its a trailer
if not e.title.endswith('Trailer'):
continue
#hack url for actual trailer video file
url = e.link.replace('apple.com/trailers', 'apple.com/movies')
key = str(url.split('/')[-2])
filename = key+'-tlr1_h480p.mov'
if download_trailer(url+filename):
title = e.title.rsplit('-',1)[0].strip() # only want movie title
#movie = Movie(title, e.summary, 'content/trailers/'+filename)
#movie_shelve[key] = movie
data = {'title':title, 'summary':e.summary, 'trailer':'content/movies/'+key+"/"+filename, 'rating':'PG-13', 'related':['dumbstruck','dumbstruck','dumbstruck']}
print key
print json.dumps(data)
print
#movie_shelve.close()
if __name__ == "__main__":
print "Pulling newest trailer feed from apple.com..."
get_movie_data()