Ticket #2661: patch

File patch, 3.4 KB (added by Rich.West@…, 14 years ago)

patch to animaps.pl

  • /usr/share/mythtv/mythweather/scripts/animaps.pl

    old new  
    11#!/usr/bin/perl -w
     2#
     3# animaps.pl
     4#
     5# This script grabs the source image(s) and provides an animated version of the
     6# still images back to Myth.
     7#
     8# This script uses the maps.xml file as the list of available sources. Please
     9# take a look at that file for examples of how to format particular sources.
     10#
     11################################################################################
    212use strict;
    313use Getopt::Std;
    414use LWP::Simple;
     
    717use Data::Dumper;
    818our ($opt_v, $opt_t, $opt_T, $opt_l, $opt_u, $opt_d);
    919
    10 my $name = 'Animated-Map-Download';
    11 my $version = 0.1;
     20###
     21#
     22# These defines are required by the MythWeather modules.  What is defined here
     23# will be displayed in the GUI.
     24#
     25###
     26my $name = 'Animated_Regional_Map';
     27my $version = 0.21;
    1228my $author = 'Lucien Dunning';
    1329my $email = 'ldunning@gmail.com';
     30
     31##
     32# Some defaults.
     33##
    1434my $updateTimeout = 10*60;
    1535my $retrieveTimeout = 30;
    1636my @types = ('amdesc', 'updatetime', 'animatedimage');
     37##
     38# Our xml file is local to the directory that the script is run in.
     39##
    1740my $dir = "./";
    1841
     42##
     43# Get and parse the command line arguments
     44##
    1945getopts('Tvtlu:d:');
    2046
    2147if (defined $opt_v) {
     
    5076    die "Invalid usage";
    5177}
    5278
    53 #should only get one location result since its by url, assuming things is fun :)
     79##
     80# If we got to here, then we have all of the right arguments.  We should
     81# only get one location via the command line options.
     82#
     83# First, we need to search through the XML file for the specified location
     84# and get all of the necessary attributes of that location.
     85##
    5486MapSearch::AddAniSearch($loc);
    5587my $results = MapSearch::doSearch();
    5688my $base = $results->[0]->{animation};
     
    5991my $file = $desc;
    6092$file =~ s/[^a-zA-Z0-9]//g;
    6193my $path = "$dir/$file-";
    62 my $i = 0;
     94my $image_count = 0;
     95my $i=0;
    6396foreach my $image (sort @{$results->[0]->{images}}) {
    64     getstore("$base/$image", $path . "$i");
    65     ++$i;
     97    ++$image_count;
     98}
     99##
     100# Because Myth does not support animated GIFs, we have to do a little
     101# hacking if the source is an animated GIF.
     102#
     103# Hack to check if there is only one image listed as the source for the
     104# animated images.  If it is, then we assume it is an animated GIF (it better
     105# be, darn it!) and we split it in to its individual frames.
     106##
     107if (($image_count == 1) && (@{$results->[0]->{images}}[0] =~ /.gif$/))
     108{
     109    # Get the Animated GIF
     110    getstore("$base/" . @{$results->[0]->{images}}[0], $path . "anim.gif");
     111    # Split it in to its individual parts
     112    system("/usr/bin/convert +adjoin -coalesce " . $path . "anim.gif " . $path . "%01d");
     113    # Now, count up all of the individual pieces.
     114system ("echo \"ls -l $path\" > /tmp/test.log");
     115    open (LS, "ls -l $path\* |");
     116    while (<LS>)
     117    {
     118       ++$i if ((/$path/) && !(/anim.gif/));
     119    }
     120    close (LS);
     121}
     122else
     123{
     124   foreach my $image (sort @{$results->[0]->{images}}) {
     125       getstore("$base/$image", $path . "$i");
     126       ++$i;
     127   }
    66128}
    67129# assume all the same size, so just check first
    68130if (!$size) {
     
    71133    $size = "${x}x$y" if ($x && $y);
    72134}
    73135
    74 
    75136print "amdesc::$desc\n";
    76137printf "animatedimage::${path}%%1-$i%s\n", ($size && "-$size" || '');
    77138print "updatetime::Last Updated on " . UnixDate("now", "%b %d, %I:%M %p %Z") . "\n";