ºÇ¿· RSS

horiday blog

2011/06/24

¢£ [diary] ¥Õ¥§¥ê¡¼¤Ë¾è¤Ã¤Æ²¬»³Âç³Ø¤Ø

ËÜÆü¤Ï¥¹¥¿¥Ã¥Õ¤Î¥¿¥Ä¥«¥ï·¯¤¬²¬»³Âç³Ø¤Î¥Ù¥ó¥Á¥ã¡¼¸¦µæ²ñ¤Ë¹Ô¤¯¤È¤¤¤¦¤Î¤Ç¡¤·ù¡¹¤Ê¤¬¤é¤Î¥Ë¥·¥â¥ê·¯¤òÏ¢¤ì¤Æ¡¤¤ß¤ó¤Ê¤Ç¥Õ¥§¥ê¡¼¤Ë¾è¤Ã¤Æ¹Ô¤Ã¤Æ¤­¤Þ¤·¤¿¡¥

¥Õ¥§¥ê¡¼¤ÎÃæ¤Ç¤µ¤Ã¤µ¤ÈÂǤÁ¹ç¤ï¤»¤òºÑ¤Þ¤»¤Æ¡¤³§¤Ç¥Õ¥§¥ê¡¼¤Î¾å¤Ø¹Ô¤­¤Þ¤·¤¿¡¥¥Ë¥·¥â¥ê·¯¤ÏÁ¥Æ⤦¤É¤ó¤òÁ¥³°¤Ç¿©¤Ù¤ë¤È¸À¤Ã¤Æ¡¤¤¦¤É¤ó¤ò³°¤Ø»ý¤Á½Ð¤·¤Æ¤¤¤Þ¤·¤¿¡¥

¿¾¯Ì¤¤¤Ê¤¬¤é¤â¡¤Ìµ»ö¶µ¼¼¤ØÅþÃ夷¡¤¤ß¤ó¤Ê¤ÇÇ®¤¤µÄÏÀ¤ò¤·¤Þ¤·¤¿¡¥

¥®¥ã¥×¥é¥¤¥º¤È¤¤¤¦²ñ¼Ò¤Î¼ÒŤ¬¡¤¾¦Éʤò¤É¤¦ PR ¤¹¤ë¤«¤È¤¤¤¦Ïäò¤·¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡¤¤½¤Î¤¢¤È¤Ç¥¿¥Ä¥«¥ï·¯¤¬²¼µ­¤Î¤è¤¦¤Ê¤³¤È¤ò¸À¤Ã¤Æ¤¤¤Þ¤·¤¿¡¥

¤¢¤¦¤¤¤¦¼«¿®¤ËËþ¤Á¤¿Ïääơ¤µ»½Ñ¼Ô¤Î¤Ò¤È¤Ï¶ì¼ê¤Ç¤¹¤è¤Í¡©

µ»½Ñ¼Ô¤ä¸¦µæ¼Ô¤Ï¡¤¤Ê¤ó¤é¤«¤ÎÊýË¡¤òÁȤ߾夲¤Æ¤¤¤¯¤Ò¤È¤À¤È»×¤¦¤Î¤Ç¤¹¤¬¡¤½ÐÍè¤ë¤³¤È¤È½ÐÍè¤Ê¤¤¤³¤È¤¬±Ä¶È¤ä¥Þ¥Í¥¸¥á¥ó¥È¤ò¤·¤Æ¤¤¤ë¤Ò¤È¤è¤ê¤âÀµ³Î¤Ëʬ¤«¤Ã¤Æ¤¤¤ë¤Î¤Ç¸ØÄ¥¤·¤¿¤è¤¦¤Ê¤³¤È¤¬¤Ê¤«¤Ê¤«¸À¤¨¤Ê¤¤¤ó¤¸¤ã¤Ê¤¤¤«¤Ê¤È»×¤¤¤Þ¤·¤¿¡¥

ÂçÀª¤ÎÁ°¤Ç PR ¤¹¤ë¤è¤¦¤Êµ¡²ñ¤Ç¤Ï¡¤Ãæ¿È¤è¤ê¤âȯɽ¤¹¤ë¿Í¤Î¥×¥ì¥¼¥ó¥¹¤ÎÊý¤¬Âç»ö¤À¤Ã¤¿¤ê¤¹¤ë¤Î¤Ç¡¤¤½¤¦¤¤¤¦ÅÀ¤Ï»²¹Í¤Ë¤·¤¿Êý¤¬Îɤ¤¤Ê¤È»×¤¤¤Þ¤·¤¿¡¥¼ÒĹ¤È¤«±Ä¶È¤Çµ»½Ñ¼Ô¤¬¾¯¤Ê¤¤¤Î¤Ï¤½¤¦¤¤¤¦Íýͳ¤Ê¤Î¤«¤Ê¡¥

Á°¤Ë·ÄØæ¤Î²¬Åĸ¬°ìÀèÀ¸¤¬Âç³Ø¤¬»Ï¤á¤¿¥Ó¥¸¥Í¥¹¤Ã¤Æ¤¤¤¦¤Î¤Ï¥À¥µ¤¤¤È¸À¤Ã¤Æ¤¤¤Þ¤·¤¿¤¬¡¤¤É¤¦¤â²Ê³ØŪ¤Ë¹Í¤¨¤Æ¤¤¤ë¤Ò¤È¤Ï PR ¤Ï¶ì¼ê¤À¤Ã¤¿¤ê¤¹¤ë¤ó¤Ç¤·¤ç¤¦¤«¤Í¡¥

µ¢¤ê¤â¥Õ¥§¥ê¡¼¤À¤Ã¤¿¤Î¤Ç¤¹¤¬¡¤³§Èè¤ì¤Æ¤¤¤Æ¡¤¤º¤Ã¤È̵¸À¤Ç¤·¤¿...

´ØÏ¢¥ê¥ó¥¯


2011/06/02

¢£ [perl] perl ¤Ç youtube ¤Î¸¡º÷

youtube ¤ÎÆ°²è¤ò¸¡º÷¤¹¤ë¤Ë¤Ï¤É¤¦¤·¤¿¤éÎɤ¤¤Î¤«¤Èʹ¤«¤ì¤¿¤Î¤Ç¡¤¥µ¥ó¥×¥ë¥³¡¼¥É¤òºî¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥API ¤Ç¸¡º÷¤ò¤¹¤ë¤Ë¤Ï¡¤Ç§¾Ú¤Ê¤É¤¬ÉÔÍפʤ褦¤Ç¤¹¡¥

¥ê¥Õ¥¡¥ì¥ó¥¹ ¥¬¥¤¥É: Data API ¥×¥í¥È¥³¥ë¤ò¸«¤ë¤È¡¤

Æ°²è¤ò¸¡º÷¤¹¤ë¤Ë¤Ï¡¢¼¡¤Î URL ¤Ë¥ê¥¯¥¨¥¹¥È¤Ë¹ç¤ï¤»¤Æ¥¯¥¨¥ê ¥Ñ¥é¥á¡¼¥¿¤òÉղä·¡¢HTTP GET ¥ê¥¯¥¨¥¹¥È¤òÁ÷¿®¤·¤Þ¤¹¡£

http://gdata.youtube.com/feeds/api/videos

¤¿¤È¤¨¤Ð¼¡¤Î URL ¤Ø¤Î¥ê¥¯¥¨¥¹¥È¤Ç¤Ï¡¢¸¡º÷¥­¡¼¥ï¡¼¥É¡Öfootball¡×¤Ë°ìÃפ·¡¢¥­¡¼¥ï¡¼¥É¡Ösoccer¡×¤Ë¤Ï°ìÃפ·¤Ê¤¤ºÇ¶á¥¢¥Ã¥×¥í¡¼¥É¤µ¤ì¤¿Æ°²è¤Î 10 Ëܤº¤Ä¤Î¥»¥Ã¥È¤Î 2 ÈÖÌܤΥ»¥Ã¥È¤ò¸¡º÷¤·¤Þ¤¹¡£

http://gdata.youtube.com/feeds/api/videos?
    vq=football+-soccer
    &orderby=published
    &start-index=11
    &max-results=10

¤È¤¤¤¦¤³¤È¤Ç¥µ¥ó¥×¥ë¥³¡¼¥É¤Ï²¼µ­¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤·¤¿¡¥atom ¤Ç¼èÆÀ¤·¤è¤¦¤È¤·¤¿¤Î¤Ç¤¹¤¬¡¤°·¤¤Êý¤¬Îɤ¯¤ï¤«¤é¤Ê¤«¤Ã¤¿¤Î¤Ç¡¤rss ¤Ë¤·¤Þ¤·¤¿¡¥

#!/usr/bin/env perl
# search-youtube.pl
use strict;
use Data::Dumper;
use URI;
use XML::Simple;
use LWP::Simple;
use Unicode::RecursiveDowngrade;
use Unicode::Japanese;
use Jcode;

sub main {
  my $kw = "¹áÀîÂç³Ø";
  my $h = search_youtube($kw);

  print Dumper $h;
}

sub search_youtube {
  my $kw = shift;
  my $h;

  my $proxy = 'http://gdata.youtube.com/feeds/api/videos';
  my $uri   = URI->new( $proxy );

  my $u_kw = Jcode::convert($kw , "utf8", "euc-jp" );

  $uri->query_form(
		   vq => $u_kw,
		   orderby => "relevance",
		   alt => 'rss'
		  );

  my $xml = get($uri->as_string);
  my $xs  = XML::Simple->new();
  my $ref = $xs->XMLin( $xml, forcearray => 1 );

  my $count = 0;
  foreach my $i (@{$ref->{channel}[0]{item}}) {
    $h->{$count}{title} = shift @{$i->{title}};
    $h->{$count}{link} = shift @{$i->{link}};
    $h->{$count}{description} = $i->{'description'}[0];
    $h->{$count}{keywords} = $i->{'media:group'}[0]{'media:keywords'};
    $h->{$count}{author} = $i->{author}[0];
    $h->{$count}{viewcount} = $i->{'yt:statistics'}[0]{viewCount};
    $h->{$count}{pubdate} = $i->{pubDate}[0];
    $h->{$count}{thumb} = $i->{'media:group'}[0]{'media:thumbnail'}[1];
    $count++;
  }

  my $rd = Unicode::RecursiveDowngrade->new;
  $rd->filter(sub {
                Unicode::Japanese->new(shift, 'utf8')->euc
                });
  $h = $rd->downgrade($h);

  return $h;
}

main;

¾åµ­¤Î¥³¡¼¥É¤ò search-youtube.pl ¤È¤·¤ÆÊݸ¤·¤Æ¡¤¼Â¹Ô¤¹¤ë¤È²¼µ­¤Î¤è¤¦¤Ë¤Ê¤ê¤Þ¤¹¡¥

% perl youtube-search.pl
$VAR1 = {
          '11' => {
                    'link' => 'http://www.youtube.com/watch?v=F_abi4096VQ&feature=youtube_gdata',
                    'viewcount' => '1697',
                    'pubdate' => 'Tue, 08 Feb 2011 17:51:56 +0000',
                    'author' => 'BBRarkaic3',
                    'description' => '¹áÀîÂç³ØÂè42²óÄê´ü±éÁÕ²ñ¡¢­·stage¥á¥¤¥ó¶Ê. ¤Ó¤Ó¤ëÂç¹¥¤­¥¹¥¤¡¼¥È¤Ê¥á¥í¥Ç¥£¤È¡¢¤­¤é¤Ó¤ä¤«¤Ê¥ê¥º¥à¡£ ÆüËÜ°ì¤Î¥Þ¥ó¥É¥ê¥ó¥¯¥é¥Ö¤È¼«É餷³¤±¤Þ¤¹¡£ ÁÇÀ²¤é¤·¤¤¡ª¡ª¡ª¡ª »Ø´ø¡§»Í¹ñ¤ÎÅÁÀâ¡¢ºÙÀî°ì¼ù»á(¹áÀºß½»㊟2011ǯ¸½ºß) ¢¨¹áÀîÂç³Ø±éÁդΥǥâCD¤Ê¤É¤Î¹ØÆþÅù¤ÎÌ䤤¹ç¤ï¤»¤Ï¡¢¹áÀîÂç³Ø¥Þ¥ó¥É¥ê¥ó¥¯¥é¥Ö¤Þ¤Ç¤Ó¤Ó¤ëÂç¹¥¤­',
                     'thumb' => {
                                 'width' => '120',
                                 'time' => '00:03:45.250',
                                 'url' => 'http://i.ytimg.com/vi/F_abi4096VQ/1.jpg',
                                 'height' => '90'
                               },
                    'keywords' => [
                                    '¥Þ¥ó¥É¥ê¥ó, ¹¾Æ¬'
                                  ],
                    'title' => '¡Ö±À¤Î¹ÔÊý¡× ¹áÀîÂç³ØÂ裴£²²óÄê´ü±éÁÕ²ñ 3-3final¥¹¥Æ¡¼¥¸ 2010ǯ12/18'
                 },
...
  • ¥­¥à¥ß¥®¥å(Kim Migyu)¤µ¤ó¤Î¤ªÏÃ


´ØÏ¢¥ê¥ó¥¯