diff options
author | Christian Pointner <equinox@helsinki.at> | 2016-07-19 21:44:38 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@helsinki.at> | 2016-07-19 21:44:38 (GMT) |
commit | c10b740439ddcdeb4fd475e113cc439f374fc96b (patch) | |
tree | abe7ab50005c8a86bf25314667795e33325a678a /rhautoimport.pm | |
parent | 4fdc9672f1cdc3b8d541fd62fea196140937e6f8 (diff) |
make usage of fetch_parse_(rss|json) easier
Diffstat (limited to 'rhautoimport.pm')
-rw-r--r-- | rhautoimport.pm | 51 |
1 files changed, 49 insertions, 2 deletions
diff --git a/rhautoimport.pm b/rhautoimport.pm index 83bf17b..a2b4c50 100644 --- a/rhautoimport.pm +++ b/rhautoimport.pm @@ -34,6 +34,7 @@ use LWP::Simple; use XML::Feed; use RHRD::rddb; use JSON::MaybeXS; +use URI::QueryParam; use constant { @@ -59,11 +60,16 @@ sub get_dropboxes sub fetch_parse_rss { - my ($url, $ua_str, $headers) = @_; + my ($url, $ua_str, $headers, $queries) = @_; my $uri = URI->new($url); - $ua_str = "Radio Helsinki - Automatic Import" unless $ua_str; + if (defined $queries) { + while(my ($name, $value) = each %{$queries}) { + $uri->query_param($name => $value); + } + } + $ua_str = "Radio Helsinki - Automatic Import" unless $ua_str; my $ua = LWP::UserAgent->new; $ua->agent($ua_str); $ua->env_proxy; @@ -82,6 +88,41 @@ sub fetch_parse_rss return (1, XML::Feed->parse(\$xml)); } +sub fetch_parse_rss_cba +{ + my ($url, $ua_str, $headers, $queries) = @_; + + my $api_key = 'Kfs2IoV2Wmd'; # TODO: read this from config!!! + if (defined $api_key) { + if (defined $queries) { + $queries->{'c'} = $api_key; + } else { + $queries = { 'c' => $api_key }; + } + } + return fetch_parse_rss($url, $ua_str, $headers, $queries); +} + +sub fetch_parse_json +{ + my ($url, $ua_str, $headers, $queries) = @_; + + $ua_str = "Radio Helsinki - Automatic Import" unless $ua_str; + return RHRD::utils::fetch_parse_json($url, $ua_str, $headers, $queries); +} + +sub fetch_parse_json_audioboom +{ + my ($url, $ua_str, $headers, $queries) = @_; + + if (defined $headers) { + $headers->{'Accept'} = 'application/json; version=1'; + } else { + $headers = { 'Accept' => 'application/json; version=1' }; + } + return fetch_parse_json($url, $ua_str, $headers, $queries); +} + sub check_file_extension { my ($file) = @_; @@ -95,6 +136,9 @@ sub check_file_extension return 0; } +######################################### +## rhimportd - watchDir Control Interface + sub parse_result { my ($donefile) = @_; @@ -201,6 +245,9 @@ sub import_uri return $ret, $log . $tmplog, $keptfile_uri; } +######################################### +## PV + sub pv_add_note { my ( $title, $text, $id, $date, $type, $index ) = @_; |