Hi Jason, all,
Here's the script which I've run into problems with kaa.xmlutils with.
As it stands with the patch I posted separately for xmlutils it works
and creates valid a fxd file which can be used in Freevo-1.x (at the
moment it doesn't look like freevo2 (or kaa.beacon) supports http
locations for files?).
If you run it without patching kaa.xmlutils you should get an invalid
fxd where the end tag for the url contains the mplayer-option attribute.
With the patch it seems to work perfectly for me.
John
#!/usr/bin/env python
#encoding:utf-8
#author:dbr/Ben
#project:appletrailers
#repository:http://github.com/dbr/appletrailers
#license:Creative Commons GNU GPL v2
# (http://creativecommons.org/licenses/GPL/2.0/)
import os, sys
import urllib
from BeautifulSoup import BeautifulSoup
import kaa.xmlutils
#from config import config
class _Trailer(dict):
def __init__(self, *args, **kwargs):
self.__dict__.update( kwargs )
def __repr__(self):
return "<Trailer \"%s\">" % (self.__dict__['info'].title)
class _TrailerInfo(dict):
def __init__(self, *args, **kwargs):
self.__dict__.update( kwargs )
def __repr__(self):
return "%s" % (self.__dict__)
class Trailers(list):
res_lookup = {
"default" : "http://www.apple.com/trailers/home/xml/current.xml",
"480" : "http://www.apple.com/trailers/home/xml/current_480p.xml",
"720" : "http://www.apple.com/trailers/home/xml/current_720p.xml",
}
def __init__(self, res = "720"):
self.config = {}
if res not in self.res_lookup:
raise ValueError("Invalid resolution \"%s\". Select from: %s" % (
res, ", ".join(self.res_lookup.keys())
))
self.config['trailer_xml_url'] = self.res_lookup[res]
# Trailers is a list, so extend it with all the trailers
self.extend(self.get_trailers())
def __repr__(self):
return "<Trailers instance containing %s trailers>" % (len(self))
def search(self, search_term):
return [trailer for
trailer in self
if str(trailer.info.title).lower().find(
str(search_term).lower()
) > -1
]
def _get_source_soup(self, url):
src = urllib.urlopen(url).read()
soup = BeautifulSoup(src)
return soup
def _parse_list(self, insoup):
ret = []
if insoup is None:
return ret
for cmem in insoup:
ret.append(cmem.string)
return ret
def _parse_dict(self, insoup):
ret = {}
for celement in insoup.findChildren():
ret[str(celement.name)] = celement.string
ti = _TrailerInfo(**ret)
return ti
def get_trailers(self):
soup = self._get_source_soup(self.config['trailer_xml_url'])
all_movies = []
for movie in soup.findAll("movieinfo"):
movie_info = {}
movie_info['cast'] = self._parse_list(movie.cast)
movie_info['info'] = self._parse_dict(movie.info)
movie_info['genre'] = self._parse_list(movie.genre)
movie_info['poster'] = self._parse_dict(movie.poster)
movie_info['preview'] = self._parse_dict(movie.preview)
t = _Trailer(**movie_info)
all_movies.append(t)
return all_movies
def main():
all_trailers = Trailers(res = "720")
fxd = kaa.xmlutils.create(root='freevo')
fxdfilename = "/tmp/apple3.fxd"
fxdname = "Trailers from apple.com"
mplayeropts = "-user-agent QuickTime7.6.2"
for trailer in all_trailers:
if trailer.preview.large:
fxd.title = fxdname
movie = fxd.add_child('movie', title=trailer.info.title)
video = movie.add_child('video')
file = video.add_child('url mplayer-options="%s"' % mplayeropts, trailer.preview.large)
# video.add_child('mplayer_options', mplayeropts)
info = movie.add_child('info', "Some info about the trailer")
genre = info.add_child('genre', trailer.genre)
if trailer.poster.location:
movie.add_child('cover-img', trailer.poster.location)
# trailer = trailer.preview.large
# image = trailer.poster.location
# title = trailer.info.title
# if fxdname:
# fxd.title = fxdname
# movie = fxd.add_child('movie', title=trailer.info.title)
# info = movie.add_child('info', "Some info about the trailer")
# movie.add_child('file', unicode(trailer.preview.large, 'utf-8'))
# movie.add_child('cover-img', unicode(trailer.poster.location, 'utf-8'))
# print "Title:", trailer.info.title
# print "Poster:", trailer.poster.location
# print "Actors:", ", ".join(trailer.cast)
# print "Trailer:", trailer.preview.large
# print "*"*24
fxd.save(filename=fxdfilename)
if __name__ == '__main__':
main()
#<?xml version="1.0" ?>
#<freevo>
# <movie title="My Movie Title">
# <cover-img source="http://url/to/cover/provider">MyMovie.jpg</cover-img>
# <video>
# <file id="f1">MyMovie.avi</file>
# </video>
# <info>
# <genre>Genre</genre>
# <runtime>123 minutes</runtime>
# <rating>8/10</rating>
# <tagline>The best movie ever!</tagline>
# <plot>Some long description</plot>
# </info>
# </movie>
#</freevo>
------------------------------------------------------------------------------
This SF.net email is sponsored by
Make an app they can't live without
Enter the BlackBerry Developer Challenge
http://p.sf.net/sfu/RIM-dev2dev
_______________________________________________
Freevo-devel mailing list
Freevo-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/freevo-devel