summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-05-25 15:00:13 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-05-25 15:00:13 (GMT)
commitc715c106f08dbf612180aafd5b331a5eb378eb66 (patch)
treef37ae84d628d7ef2f5e72f5c370b4119562037c7
parent2fbd4bc628b28c88a45026a1ec4a324ca2bda417 (diff)
added audioboom inspector
-rw-r--r--rhautoimport.pm8
-rwxr-xr-xtest/audioboom-inspect95
2 files changed, 102 insertions, 1 deletions
diff --git a/rhautoimport.pm b/rhautoimport.pm
index 4ea0808..83bf17b 100644
--- a/rhautoimport.pm
+++ b/rhautoimport.pm
@@ -59,7 +59,7 @@ sub get_dropboxes
sub fetch_parse_rss
{
- my ($url, $ua_str) = @_;
+ my ($url, $ua_str, $headers) = @_;
my $uri = URI->new($url);
$ua_str = "Radio Helsinki - Automatic Import" unless $ua_str;
@@ -67,6 +67,12 @@ sub fetch_parse_rss
my $ua = LWP::UserAgent->new;
$ua->agent($ua_str);
$ua->env_proxy;
+ if (defined $headers) {
+ while(my ($field, $value) = each %{$headers}) {
+ $ua->default_header($field, $value);
+ }
+ }
+
my $res = URI::Fetch->fetch($uri, UserAgent => $ua);
return (0, URI::Fetch->errstr) unless $res;
return (0, "This feed has been permanently removed") if $res->status == URI::Fetch::URI_GONE();
diff --git a/test/audioboom-inspect b/test/audioboom-inspect
new file mode 100755
index 0000000..6120a85
--- /dev/null
+++ b/test/audioboom-inspect
@@ -0,0 +1,95 @@
+#!/usr/bin/perl -w
+#
+#
+# rhautoimport
+#
+# Copyright (C) 2009-2016 Christian Pointner <equinox@helsinki.at>
+#
+# This file is part of rhautoimport.
+#
+# rhautoimport is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# any later version.
+#
+# rhautoimport is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with rhautoimport. If not, see <http://www.gnu.org/licenses/>.
+#
+
+use strict;
+use attributes;
+use Date::Calc;
+use URI::URL;
+use HTML::Entities;
+
+use lib '../../rhrdlibs/lib/';
+use lib '../';
+use rhautoimport;
+
+use Data::Dumper::Simple;
+
+if($#ARGV != 0) {
+ print "Usage: audioboom-inspect <user-id>\n";
+ exit 1;
+}
+my $API_URL = "https://api.audioboom.com/users/" . $ARGV[0] . "/audio_clips";
+
+binmode(STDIN, ":utf8");
+binmode(STDOUT, ":utf8");
+binmode(STDERR, ":utf8");
+
+my %h = ( 'Accept' => 'application/json; version=1' );
+my ($result, $data) = RHRD::utils::fetch_parse_json($API_URL, "Radio Helsinki - Automatic Import", \%h);
+unless ($result) {
+ print "Error fetching data: $data\n";
+ exit 1;
+}
+
+my @clips = @{$data->{'body'}{'audio_clips'}};
+
+my $uri = "";
+my $file = "";
+my $sum_title = "";
+my $sum_text = "";
+
+my $i = 0;
+for my $clip (@clips) {
+ $i++;
+ print $i . ": " . $clip->{title} . "\n";
+
+ # next unless $entry->enclosure;
+
+ # $sum_title = decode_entities($entry->title);
+ # $sum_text = decode_entities($entry->content->body);
+ # my $guid = $entry->{'entry'}{'guid'};
+ # $guid = '<unset>' unless (defined $guid);
+
+ # print $sum_title . ":\n";
+ # print " Issued: " . $entry->issued . "\n";
+ # print " guid: " . $guid. "\n";
+ # print " Files:\n";
+
+ # my $j = 0;
+ # for my $enclosure($entry->enclosure) {
+ # $j++;
+ # if($enclosure->type eq "audio/mpeg" || $enclosure->type eq "audio/ogg") {
+ # my $orig_uri = $enclosure->url;
+ # if($orig_uri =~ /^(.*)_cut(\.[^\.]+)$/) {
+ # $orig_uri = $1 . $2;
+ # }
+ # $uri = new URI::URL($orig_uri);
+ # my @path = $uri->path_components;
+ # $file = $path[-1];
+
+ # print " $j: (" . $enclosure->type . ", " . $enclosure->length . ") " . $file . "\n";
+ # }
+ # }
+ # print "\n";
+}
+
+exit 0;