#!/usr/bin/perl

use SOAP::Lite  on_action => sub {sprintf '%s/%s', @_}, ;

use Data::Dumper;
use XML::Simple;
my $meta_subset = &get_frikanalen_meta_subset('Id'); # Use 'Id' or 'MetaDataVideoId' as key




###### Functions ##############

sub get_frikanalen_meta_subset {
 # Build metadata structure with id as key
 my $returndata;
 $soap = new SOAP::Lite
 -> uri('http://localhost/CommunitySiteService')
 -> proxy('http://communitysite1.frikanalen.tv/CommunitySiteFacade/CommunitySiteService.asmx');

 # Request list of all available videos with all avalable metadata for each video
 # constructing the expected xml code for 
 # http://communitysite1.frikanalen.tv/CommunitySiteFacade/CommunitySiteService.asmx?op=SearchVideos
 # 'Take' is how many records to grab. Just crank it higher than the number of available records,
 # and it will return all. 

 my $obj = $soap->SearchVideos(
  SOAP::Data->name('searcher' => {
   'PredefinedSearchType' => 'Default',
   'Take' => 10000,
   }
  )
 );
 unless ($obj->fault) {
  my $res = $obj->result;
  my $key = $_[0];
  my $nuug_video_prefix = 'http://www.nuug.no/pub/video/frikanalen/';
  # print Dumper($res);
  foreach my $video (@{$res->{'Data'}->{'Video'}}) {
    print "$video->{'Id'}\;$video->{'MetaDataVideoId'}\n";
   }
 } else {
   print join ', ',
   $result->faultcode,
   $result->faultstring;
 }
}
