
derliebegott at gmail
Jun 26, 2008, 2:23 AM
Post #12 of 24
(1602 views)
Permalink
|
2008/6/26 Ma Begaj <derliebegott[at]gmail.com>: > 2008/6/24 James Sumners <james.sumners[at]gmail.com>: >> Ah, I see. There is a modification to the "Apple Trailers" plugin that >> replaces "h640w" in the file URL with "720p". >> >> On Tue, Jun 24, 2008 at 2:57 PM, John Payne <mythtv[at]payne.ch> wrote: >>> James Sumners wrote: >>> >>> Looks good. It looks like the script pulls the "large" trailer from >>> the site. Would it be just as easy to pull the 720p version? (I >>> haven't looked at Apple's site.) >>> >>> On Tue, Jun 24, 2008 at 2:34 PM, John Payne <mythtv[at]payne.ch> wrote: >>> >>> >>> I really liked the Myth Apple Trailers 'plugin' but I wanted to see >>> plot, cast, rating etc in the basic display, before I started the actual >>> trailer. Rather than try to write a real plugin I created an Apple >>> Trailer downloader that reads the list of current trailers and creates a >>> videometadata record in the DB with related cast & genre records, & >>> downloadsthe trailers in a subfolder of the video folder and the poster >>> in the standard posters directory. >>> >>> The trailers can then be viewed with Mythvideo >>> >>> At the moment the trailer & poster folders are hard coded so need to be >>> modified as required ($videoStore & $posterStore) and I don't seem to >>> get all the posters. I've set it up to run each night from mythtv's cron >>> and it uses the Apple id to check if the trailer's already been loaded - >>> I assume the id is unique. >>> >>> It uses LWP::Simple, XML::Simple, File::Basename, DBI & DBIx:Perlish, >>> which is simplifies DB access without the usual DBI overhead. >>> ToDo: >>> - get the video & poster directories from the DB >>> - automatically remove old trailers >>> - add 'new' to the new trailers (and remove it from existing >>> trailers)(or when they have been viewed) >>> - use a standard DB interface (perl bindings? where are they documented?) >>> - make a dedicated plugin similar to the existing plugin but showing the >>> additional details - is it possible to write a plugin/addon in perl? I'm >>> too old to start learning C++ >>> >>> Perhaps someone might find it useful, or have some ideas for improvement.... >>> >>> John >>> >>> Here it is >>> ------------------------------------------------------------------------------------- >>> #!/usr/bin/perl >>> >>> use strict; >>> use LWP::Simple; >>> use XML::Simple; >>> use File::Basename; >>> >>> use DBI; >>> use DBIx::Perlish; >>> >>> my $videoStore = "/storage500/videos/Trailers/"; >>> my $posterStore = "/storage500/posters/"; >>> my $logfile = "apple$$.log"; >>> open LOG, ">$logfile"; >>> >>> my $dbh = DBI->connect('dbi:mysql:mythconverg', "mythtv", "mythtv"); >>> DBIx::Perlish::init($dbh); >>> >>> my $list = get 'http://www.apple.com/trailers/home/xml/current.xml'; >>> #my $ref = XMLin($list, ForceArray => [ "name" ]); >>> my $ref = XMLin($list, ForceArray => [ "name" ]); >>> >>> my $message; >>> >>> my %Cast; >>> my %Movies; >>> foreach my $movie (keys %{$ref->{movieinfo}}){ >>> next if(db_fetch {videometadata->inetref eq $movie}); # already go >>> this one >>> print LOG "Checking $ref->{movieinfo}{$movie}{info}{title}\n"; >>> # fetch the trailer & images >>> print LOG "Adding...\n"; >>> my $trailer = $ref->{movieinfo}{$movie}{preview}{large}{content}; >>> my $trailersize = $ref->{movieinfo}{$movie}{preview}{large}{filesize}; >>> my $localTrailer = $videoStore . File::Basename::basename($trailer); >>> my $rv = getstore($trailer, $localTrailer); >>> my $poster = $ref->{movieinfo}{$movie}{poster}{location}; >>> my $localPoster = $posterStore . File::Basename::basename($poster); >>> $rv = getstore($poster, $localPoster); >>> >>> # main data to videometadata >>> # build the 'plot' >>> my $plot = $ref->{movieinfo}{$movie}{info}{description}; >>> $plot .= "\nRelease Date: " . >>> $ref->{movieinfo}{$movie}{info}{releasedate}; >>> $plot .= "\nStudio: " . $ref->{movieinfo}{$movie}{info}{studio}; >>> $plot .= "\n" . $ref->{movieinfo}{$movie}{info}{copyright}; >>> $ref->{movieinfo}{$movie}{info}{runtime} =~ /^(\d+):(\d+)/; >>> my $length = ($1 * 60) + $2; >>> my $year = substr($ref->{movieinfo}{$movie}{info}{releasedate}, 0, 4); >>> >>> # add the record >>> >>> db_insert 'videometadata', { >>> title => $ref->{movieinfo}{$movie}{info}{title}, >>> director => $ref->{movieinfo}{$movie}{info}{director}, >>> plot => $plot, >>> rating => $ref->{movieinfo}{$movie}{info}{rating}, >>> inetref => $movie, >>> year => $year, >>> showlevel => 1, >>> length => $length, >>> filename => $localTrailer, >>> coverfile => $localPoster, >>> }; >>> my $videoid = $dbh->{'mysql_insertid'}; >>> >>> foreach my $actor (@{$ref->{movieinfo}{$movie}{cast}{name}}){ >>> _addCast($actor, $videoid); >>> } >>> foreach my $genre (@{$ref->{movieinfo}{$movie}{genre}{name}}){ >>> _addGenre($genre, $videoid); >>> } >>> } >>> >>> # send me a mail >>> >>> #my $cmd = "/bin/mailx pinthenet\@payne.ch -s 'Appletrailers' $message"; >>> #system($cmd); >>> >>> sub _addCast{ >>> my($name, $idx) = @_; >>> my $castid; >>> >>> # if new cast name add record else use existing record >>> if(!($castid = db_fetch {return videocast->intid; videocast->cast eq >>> $name})){ >>> db_insert 'videocast', {cast => $name,}; >>> $castid = $dbh->{'mysql_insertid'}; >>> } >>> >>> # now add n:n record >>> >>> db_insert 'videometadatacast', {idvideo => $idx, idcast => $castid}; >>> >>> } >>> >>> sub _addGenre{ >>> my($name, $idx) = @_; >>> my $genreid; >>> >>> # if new cast name add record else use existing record >>> if(!($genreid = db_fetch {return videogenre->intid; >>> videogenre->genre eq $name})){ >>> db_insert 'videogenre', {genre => $name,}; >>> $genreid = $dbh->{'mysql_insertid'}; >>> } >>> >>> # now add n:n record >>> >>> db_insert 'videometadatagenre', {idvideo => $idx, idgenre => $genreid}; >>> >>> } >>> >>> >>> _______________________________________________ >>> mythtv-users mailing list >>> mythtv-users[at]mythtv.org >>> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users >>> >>> >>> >>> >>> >>> The list http://www.apple.com/trailers/home/xml/current.xml only includes >>> one preview - identified as <large>. I got the URL from the Apple Trailer >>> plugin - do you know of another? I seem to remember that there are 2 version >>> of the plugin - one downloads & the other just makes a list and I think they >>> use different URLs - I'll check again >>> >>> >>> >>> >>> _______________________________________________ >>> mythtv-users mailing list >>> mythtv-users[at]mythtv.org >>> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users >>> >>> >> >> >> >> -- >> James Sumners >> http://james.roomfullofmirrors.com/ >> >> "All governments suffer a recurring problem: Power attracts >> pathological personalities. It is not that power corrupts but that it >> is magnetic to the corruptible. Such people have a tendency to become >> drunk on violence, a condition to which they are quickly addicted." >> >> Missionaria Protectiva, Text QIV (decto) >> CH:D 59 >> _______________________________________________ >> mythtv-users mailing list >> mythtv-users[at]mythtv.org >> http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users >> > > Well, you could do it the same way in perl the same way. You are > already using LWP::Simple, so this should be enough: > > $ref->{movieinfo}{$movie}{preview}{large}{content} = s/_h640w\./_720\./g; > if (head($ref->{movieinfo}{$movie}{preview}{large}{content})) { > # new file exists, overwrite $trailer again > $trailer = $ref->{movieinfo}{$movie}{preview}{large}{content}; > } > > head() should be at least as fast as php's get_header() function. > but it would be maybe even much better if you could put the $trailer in DB for "filename" instead of $localTrailer, and let mplayer stream all *.mov files instead of downloading all before someone even knows whether s/he wants to watch it. mplayer or a shell script with mplayer command could cache trailers and save them for the further watching. but this is more complicated than your script and I even do not know whether "filename" can contain absolute paths. this would probably be a "misuse" of this field. _______________________________________________ mythtv-users mailing list mythtv-users[at]mythtv.org http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-users
|