Skip to content

Instantly share code, notes, and snippets.

@matsuu
Created February 7, 2009 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matsuu/59801 to your computer and use it in GitHub Desktop.
Save matsuu/59801 to your computer and use it in GitHub Desktop.
From 41dbefc074262aa711cc19d49e610eafbf071ffa Mon Sep 17 00:00:00 2001
From: MATSUU Takuto <matsuu@gentoo.org>
Date: Sat, 7 Feb 2009 15:47:26 +0900
Subject: [PATCH] added video.google.co.jp
---
root/plugins/video.google.co.jp/discovery.pl | 45 ++++++++++++++++++++++++++
1 files changed, 45 insertions(+), 0 deletions(-)
create mode 100644 root/plugins/video.google.co.jp/discovery.pl
diff --git a/root/plugins/video.google.co.jp/discovery.pl b/root/plugins/video.google.co.jp/discovery.pl
new file mode 100644
index 0000000..b5fbb98
--- /dev/null
+++ b/root/plugins/video.google.co.jp/discovery.pl
@@ -0,0 +1,45 @@
+use Encode qw(decode);
+use XML::LibXML::Simple qw(XMLin);
+
+sub init {
+ my $self = shift;
+ $self->{handle} = '/videosearch\?';
+}
+
+sub handle {
+ my ($self, $plugin, $context, $args) = @_;
+
+ my $res = Plagger::UserAgent->new->fetch($args->{feed}->url);
+ unless ($res->is_success) {
+ $context->log(error => "GET " . $args->{feed}->url . ": " . $res->status_line);
+ return;
+ }
+
+ my $data = XMLin(decode('cp932', $res->content));
+
+ my @entries;
+ for my $movie (sort { $b->{pubDate} cmp $a->{pubDate} } @{$data->{channel}{item}}) {
+
+ push @entries, {
+ title => $movie->{title},
+ link => $self->_strip_wrapper($movie->{link}),
+ date => $movie->{pubDate},
+ body => $movie->{"media:group"}{"media:description"},
+ enclosure => $movie->{enclosure},
+ thumbnail => $movie->{"media:group"}{"media:thumbnail"},
+ };
+ }
+
+ return {
+ title => $data->{channel}{title},
+ link => $data->{channel}{link},
+ entry => \@entries,
+ };
+}
+
+sub _strip_wrapper {
+ my ($self, $url) = @_;
+ $url =~ s/^.*url\?q=([^&]*)&.*$/$1/;
+ $url =~ s/\%([0-9a-f]{2})/chr(hex($1))/egi;
+ return $url;
+}
--
1.6.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment