New importer, Nat. Geo. Wild.
[nonametv.git] / tools / nonametv-icon-update
blob6515ff34287d272b8432190890f806dbc9171e82
1 #!/usr/bin/perl -w
3 # Update the channels-table with information about which channels
4 # have an icon.
6 use strict;
8 use FindBin;
9 use lib "$FindBin::Bin/../lib";
11 use NonameTV;
12 use NonameTV::DataStore;
13 use NonameTV::Config qw/ReadConfig/;
14 use NonameTV::Factory qw/CreateDataStore/;
16 use LWP::Simple;
17 use Getopt::Long;
19 my $opt = {
20 verbose => 0,
21 quiet => 0,
22 unattended => 0,
25 my $res = GetOptions( $opt, qw/verbose quiet unattended/ );
27 # Read configuration
28 my $conf = ReadConfig();
30 # Create Datastore
31 my $ds = CreateDataStore();
33 my $iconroot = $conf->{Exporters}->{Xmltv}->{IconRootUrl};
35 my $sth = $ds->sa->Iterate( 'channels' );
37 while( my $entry = $sth->fetchrow_hashref() ) {
38 my $xmltvid = $entry->{xmltvid};
39 my $logo = $entry->{logo};
41 print "Processing $xmltvid\n" if $opt->{verbose};
43 my $url = "$iconroot$xmltvid.png";
44 if( head( $url ) ) {
45 if( not $logo ) {
46 $ds->sa->Update( 'channels', { xmltvid => $xmltvid }, { logo => 1 } );
47 print "Added icon for $xmltvid\n" if not $opt->{quiet};
50 else
52 if( $logo ) {
53 if( $opt->{unattended} ) {
54 print "Icon for $xmltvid has disappeared.\n";
56 else {
57 $ds->sa->Update( 'channels', { xmltvid => $xmltvid }, { logo => 0 } );
58 print "Removed icon for $xmltvid\n" if not $opt->{quiet};
64 $sth->finish();