SmallStyle


2008-03-07

_ Plagger::Plugin::Filter::FetchNicoVideo でニコニコ動画(SP1) 対応(2)

H.264動画対応に加えてニコニコムービーメーカで作成されたものにも対応させておく.

Index: FetchNicoVideo.pm
===================================================================
--- FetchNicoVideo.pm   (revision 7618)
+++ FetchNicoVideo.pm   (working copy)
@@ -73,8 +73,16 @@
     if ( $self->conf->{filename_encode} ) {
         Encode::from_to( $filename, "utf-8", $self->conf->{filename_encode} );
     }
-    my $path = File::Spec->catfile( $self->conf->{dir}, $filename . ".flv" );
 
+    $enclosure->url =~ m!^http://[^/]+(?:smilevideo|nicovideo)\.jp/smile\?(\w)=(?:[^.]+)\.\d+(?:low)?!;
+    my %video_type_of = (
+      v => 'flv',
+      m => 'mp4',
+      s => 'swf',
+    );
+    my $ext = exists( $video_type_of{$1} ) ? $video_type_of{$1} : "unknown";
+
+    my $path = File::Spec->catfile( $self->conf->{dir}, $filename . ".$ext" );
     unless ( -e $path ) {
        #access video page
        $ua->get("http://www.nicovideo.jp/watch/$video_id");
@@ -112,6 +120,7 @@
     if  ($res->header('Content-Length') ) {
         $enclosure->length( $res->header('Content-Length') );
     }
+    $enclosure->type( Plagger::Util::mime_type_of($path) );
     $entry->add_enclosure($enclosure);
 }

about me

いろいろと興味を持ったことを書いてます.ちょっとしたことは hb(@smallstyle) on Twitter で書いてます.

Archive

2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|12|