TVDB: better handling of first run
[nonametv.git] / tools / nonametv-import-download
blob0bf7b25786df4b1cacdd55517c266eb154ff53f6
1 #!/usr/bin/perl -w
3 use strict;
5 use NonameTV;
6 use NonameTV::DataStore;
7 use NonameTV::Config qw/ReadConfig/;
9 use HTTP::Cache::Transparent;
11 if( scalar( @ARGV ) != 2 )
13 print << 'EODOC';
14 nonametv-import-download <importer> <batch-id>
16 Download the data for a batch and put it in the "new"-section in the
17 override directory as batchid.org.
19 The override directory is currently hardcoded as
21 var/local/nonametv/override
23 To override the input for a batch:
25 nonametv-import-download TV4 plus.tv4.se_2004-11-10
26 cd /var/local/nonametv/override/new
27 cp plus.tv4.se_2004-11-10.org plus.tv4.se_2004-11-10
28 emacs plus.tv4.se_2004-11-10
29 nonametv-import TV4
31 The plus.tv4.se_2004-11-10 will be moved from new/ to data/
32 by nonametv-import. The .org-file will never be touched or processed.
34 To update an override, do the same as for a new override.
36 To remove an override, move the file in data/ to delete/. This forces
37 the importer to process data from the original site.
39 EODOC
41 exit 1;
44 # Read configuration
45 my $conf = ReadConfig();
47 # Create Datastore
48 my $ds = NonameTV::DataStore->new( $conf->{DataStore} );
50 # Initialize cache
51 HTTP::Cache::Transparent::init( $conf->{Cache} );
53 my( $imp_name, $batch_id ) = @ARGV;
55 # Create the right importer
56 my $imp_data = $conf->{Importers}->{$imp_name};
57 my $imp_type = $imp_data->{Type};
59 my $imp = eval "use NonameTV::Importer::$imp_type;
60 NonameTV::Importer::${imp_type}->new( \$imp_data );"
61 or die $@;
63 my( $xmltvid ) = ($batch_id =~ /(.*)_/);
65 my $data = $ds->sa->Lookup( 'channels', { xmltvid => $xmltvid } );
67 my $file = "/var/local/nonametv/override/new/$batch_id.org";
69 open OUT, "> $file" or die "Failed to write to $file";
70 print OUT $imp->FetchDataFromSite( $batch_id, $data );
71 close OUT;