ºÇ¿· RSS

horiday blog

<Á°¤Î10·ï

2013/11/20

¢£ [cygwin] [perl] cygwin ´Ä¶­¤Ç¤Î WWW::Mechanize::Firefox

javascript ¤ò´Þ¤à¥Ú¡¼¥¸¤Î¥¹¥¯¥ì¥¤¥Ô¥ó¥°¤ò¤·¤è¤¦¤È»×¤¤ WWW::Mechanize::Firefox ¤ò»È¤ª¤¦¤È¤¹¤ë¤È²¼µ­¤Î¥¨¥é¡¼¤¬½Ð¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡¥

command timed-out at /usr/lib/perl5/site_perl/5.14/MozRepl/Client.pm line 186

¾åµ­¤Î /usr/lib/perl5/site_perl/5.14/MozRepl/Client.pm 186 ¹Ô¶áÊÕ¤ò¸«¤ë¤È¡¤

### adhoc
$command = join(" ", split(/\n/, $command)) if ($^O eq "cygwin");

¤È¤¤¤¦¥³¡¼¥É¤¬¤¢¤ê¡¤¤Ê¤¼¤« cygwin ¤Î¤È¤­¤À¤±ÆÃÊÌ°·¤¤¤Ê½èÍý¤¬¤¢¤ê¤Þ¤·¤¿¡¥¤³¤ì¤ò²¼µ­¤Î¤è¤¦¤Ë¥³¥á¥ó¥È¥¢¥¦¥È¤¹¤ë¤È̵»öÆ°¤«¤¹¤³¤È¤¬¤Ç¤­¤Þ¤·¤¿¡¥

# ½¤Àµ¸å
### adhoc
# $command = join(" ", split(/\n/, $command)) if ($^O eq "cygwin");

ref

2011/11/30

¢£ [perl] slideshare api ¤ò perl ¤«¤é»È¤¦

¿¦¾ì¤Ç slideshare ¤Ë¤¢¤ë¥×¥ì¥¼¥ó¥Õ¥¡¥¤¥ë¤ò¸¡º÷¡¤¼èÆÀ¤·¤¿¤¤¤È¤±¤É¤É¤¦¤¹¤ì¤ÐÎɤ¤¤Î¤«¤È¤¤¤¦ÏäˤʤäƤ¤¤¿¤Î¤Ç¡¤Ä´¤Ù¤Æ¤ß¤Þ¤·¤¿¡¥

¤Þ¤º SlideShare ¤ÎSlideShare API > Apply for API Key¤«¤é¿½ÀÁ¤ò¤·¤Æ¡¤api_key ¤È secret ¤ò¼èÆÀ¤·¤Þ¤¹¡¥

¤¢¤È¤Ï¤³¤³¤Ë½ñ¤¤¤Æ¤¢¤ë WebAPI ¤ò»È¤¦¤Î¤Ç¤¹¤¬¡¤perl ¤À¤ÈWWW::SlideShare¤¬ÊØÍø¤½¤¦¤À¤Ã¤¿¤Î¤Ç¤³¤ì¤ò»È¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥

²¼µ­¤Î¥³¡¼¥É¤Ï slideshare ¤Ë¤¢¤ë¥Ç¡¼¥¿¤ò¥×¥í¥°¥é¥ß¥ó¥°¤È¤¤¤¦¥­¡¼¥ï¡¼¥É¤Ç¸¡º÷¤·¤¿¤·¤¿·ë²Ì¤òɽ¼¨¤¹¤ë¤â¤Î¤Ç¤¹¡¥

#!/usr/bin/env perl
# ss-search.pl
use strict;
use warnings;
use Data::Dumper;
use WWW::SlideShare;
use Unicode::Japanese;
use Unicode::RecursiveDowngrade;

sub main {
  my $api_key = 'orzZzz';
  my $secret = 'mjgZzz';
  my $ss = WWW::SlideShare->new(
				'api_key' => $api_key, 
				'secret' => $secret);

  my $kw = "¥×¥í¥°¥é¥ß¥ó¥°";
  $kw = Unicode::Japanese->new($kw, "euc")->utf8;
  my $h = $ss->search_slideshows({'q' => $kw, page => '1'});

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

}

main;

²¼µ­¤Ï¼Â¹Ô·ë²Ì¡Ä

% perl ss-search.pl
$VAR1 = [
         bless( {
                  '_data' => {
                               'ID' => '4022379
 ',
                               'Slideshow' => '
 ',
                               'Status' => '2
 ',
                               'InContest' => '0
',
                               'ThumbnailSmallURL' => 'http://cdn.slidesharecdn.com/r-100508200327-phpapp02-thumbnail-2
 ',
                               'Format' => 'pdf
 ',
                               'Title' => 'ÉáÄÌ¤Î¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìR
 ',
                               'SlideshowType' => '0
 ',
                               'Username' => 'shuyo
 ',
                               'ThumbnailURL' => 'http://cdn.slidesharecdn.com/r-100508200327-phpapp02-thumbnail
 ',
                               'URL' => 'http://www.slideshare.net/shuyo/r-4022379
 ',
                               'Embed' => '<div style="width:425px" id="__ss_4022379"><strong style="display:block;margin:12px 0 4px"><a href="http://www.slideshare.net/shuyo/r-4022379" title="ÉáÄÌ¤Î¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìR">ÉáÄÌ¤Î¥×¥í¥°¥é¥ß¥ó¥°¸À¸ìR</a></strong><object id="__sse4022379" width="425" height="355"><param name="movie" value="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=r-100508200327-phpapp02&stripped_title=r-4022379&userName=shuyo" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><param name="wmode" value="transparent"/><embed name="__sse4022379" src="http://static.slidesharecdn.com/swf/ssplayer2.swf?doc=r-100508200327-phpapp02&stripped_title=r-4022379&userName=shuyo" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" wmode="transparent" width="425" height="355"></embed></object><div style="padding:5px 0 12px">View more <a href="http://www.slideshare.net/">presentations</a> from <a href="http://www.slideshare.net/shuyo">Shuyo Nakatani</a>.</div></div>
 ',
                               'Language' => 'ja
 ',
                               'Updated' => 'Mon May 10 10:11:23 -0500 2010
 ',
                               'Download' => '1
 ',
                               'DownloadUrl' => 'http://s3.amazonaws.com/ppt-download/r-100508200327-phpapp02.pdf?response-content-disposition=attachment&Signature=m8OizC9neJu82l41jZSX9C53F%2F4%3D&Expires=1322808380&AWSAccessKeyId=AKIAJLJT267DEGKZDHEQ
 ',
                               'Created' => 'Sat May 08 20:03:12 -0500 2010
 ',
                               'Description' => 'Tsukuba.R #7
 '
                             }
                }, 'WWW::SlideShare::Object' ),
...

¼èÆÀ¤·¤¿¥×¥ì¥¼¥ó¥Õ¥¡¥¤¥ë¤ò¸«¤Æ¤¤¤ë¤È¡¤¥­¥ì¥¤¤Ê¥ì¥¤¥¢¥¦¥È¤¬Â¿¤¯¤Æ¼«Ê¬¤Îºî¤ë¥É¥­¥å¥á¥ó¥È¤Ë¤â»²¹Í¤Ë¤Ê¤ê¤½¤¦¤Ê¤â¤Î¤¬Â¿¤½¤¦¤Ç¤¹¤Í¡¥

´ØÏ¢¥ê¥ó¥¯

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¥á¥¤¥ó¶Ê. ¤Ó¤Ó¤ëÂç¹¥¤­¥¹¥¤¡¼¥È¤Ê¥á¥í¥Ç¥£¤È¡¢¤­¤é¤Ó¤ä¤«¤Ê¥ê¥º¥à¡£ ÆüËÜ°ì¤Î¥Þ¥ó¥É¥ê¥ó¥¯¥é¥Ö¤È¼«É餷³¤±¤Þ¤¹¡£ ÁÇÀ²¤é¤·¤¤¡ª¡ª¡ª¡ª »Ø´ø¡§»Í¹ñ¤ÎÅÁÀâ¡¢ºÙÀî°ì¼ù»á(¹áÀºß½»&#12959;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)¤µ¤ó¤Î¤ªÏÃ


´ØÏ¢¥ê¥ó¥¯

2011/03/14

¢£ [perl] Windows ´Ä¶­¤Ë¤Æ¥³¥Þ¥ó¥É¤Ç²»Î̤ÎÄ´Àá¤ò¤¹¤ë

Windows ´Ä¶­¤Ë¤Æ¡¤¥³¥Þ¥ó¥É¤Ç²»Î̤ÎÄ´Àá¤ò¤·¤¿¤¤¤È»×¤Ã¤¿¤Î¤Ç¤¹¤¬¡¤Í­¸ú¤Ê¥³¥Þ¥ó¥É¤¬¤ï¤«¤ê¤Þ¤»¤ó¤Ç¤·¤¿¡¥

¤É¤¦¤·¤è¤¦¤«¤Ê¤È»×¤Ã¤¿¤¤¤¿¤é¡¤cpan ¤Ç Win32::Sound - cpan ¤È¤¤¤¦¥â¥¸¥å¡¼¥ë¤¬¤¢¤Ã¤¿¤Î¤Ç¤³¤ì¤ò»È¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥

¤µ¤Ã¤½¤¯¤³¤Î¥â¥¸¥å¡¼¥ë¤òÆþ¤ì¤Æ¡¤²¼µ­¤Î¥³¡¼¥É¤ò¼Â¹Ô¤·¤Æ¤ß¤ë¤È¡¤¤É¤¦¤âº¸±¦¤Î¥Ð¥é¥ó¥¹¤¬¥º¥ì¤ÆÀßÄꤵ¤ì¤ëÌÏÍÍ¡Ä¡¥

use Win32::Sound;
Win32::Sound::Volume('100%');

Ä´¤Ù¤Æ¤ß¤ë¤È¡¤Win32::Sound ¤Î 0.49 °ÊÁ°¤Ë¤Ï¥Ð¥°¤¬¤¢¤ë¤ß¤¿¤¤¤Ç¡¤²¼µ­¤Î¤è¤¦¤Ë¤·¤Ê¤¤¤Èº¸±¦¤Î²»Î̤ò¶ÑÅù¤ËÄ´Àá¤Ç¤­¤Þ¤»¤ó¤Ç¤·¤¿¡¥²¼µ­¤Î¥³¡¼¥É¤Ç

perl vol-set.pl 100

¤Ê¤É¤È¤¹¤ë¤È²»Î̤ò 100% ¤Ë¤·¤¿¤ê 0% ¤Ë¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤·¤¿¡¥

#!/usr/bin/env perl
# vol-set.pl: perl vol-set.pl 50
use strict;
use Win32::Sound;

my $vol = shift @ARGV || 0;
if ($vol > 100 || $vol < 0) {
  $vol = 50;
}
$vol .= "%";
print "vol set $vol\n";
win32_volume($vol);

sub win32_volume {
  my(@in) = @_;
  if (not scalar @in) {
    my $volume = Win32::Sound::_Volume();
     if (wantarray) {
      my $left  = ($volume >> 16) & 0x0000FFFF;
      my $right = ($volume      ) & 0x0000FFFF;
      return ($left, $right);
    }
    return $volume;
  }
  # Allows '0%'..'100%'   
  $in[0] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[0];
  $in[1] =~ s{ ([\d\.]+)%$ }{ int($1*65535/100) }ex if defined $in[1];
  $in[1] = $in[0] unless defined $in[1];
 
  my $volume = (($in[0] & 0x0000FFFF) << 16) | ($in[1] & 0x0000FFFF);

  return Win32::Sound::_Volume($volume, 0);
}

´ØÏ¢¥ê¥ó¥¯

2010/11/01

¢£ [perl] WWW::Mechanize ¤Ç¥¢¥¯¥»¥¹¤·¤¿¤È¤­¤Î¥¨¥é¡¼½èÍý

perl ¤«¤é WWW::Mechanize ¤ò»È¤Ã¤Æ¡¤Web ¥Ú¡¼¥¸¤ò²òÀϤ·¤Æ¤¤¤¿¤È¤­¤Ë¡¤¥Ú¡¼¥¸¤¬¼èÆÀ¤Ç¤­¤Ê¤«¤Ã¤¿¤È¤­¤Î¤³¤È¤ò¹Í¤¨¤º¤Ë¥³¡¼¥É¤ò½ñ¤¤¤Æ¤¤¤Þ¤·¤¿¡¥

¤·¤«¤·¼ÂºÝ¤Ï¥µ¡¼¥Ð¤«¤é Temporarily Unavailable ¤¬Ê֤äƤ¯¤ë¤È¥×¥í¥°¥é¥à¤´¤È½ªÎ»¤·¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡¥

¤½¤³¤Ç²¼µ­¤Î¤è¤¦¤Ë get ¤·¤¿¤¢¤È¤Ë·ë²Ì¤ò³Îǧ¤¹¤ë¤è¤¦¤Ë¤·¤¿¤Î¤Ç¤¹¤¬¡¤·ë¶É get ¤·¤¿»þÅÀ¤Ç¥¨¥é¡¼¤òÅǤ¤¤Æ½ª¤ï¤Ã¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡¥

my $mech = WWW::Mechanize->new();
$mech->get("http://whitebase.org/");
if ($mech->success()) {
  # code for page access
  print "ok\n";
} else {
  # code for not success
  print "not ok\n";
}

$mech->success() ¼«ÂλȤ¨¤Ê¤¤¤¸¤ã¤Ê¤¤¤«¤È»×¤¤¤Ê¤¬¤é¡¤WWW::Mechanize ¤Î»ÅÍͤò³Îǧ¤·¤Æ¤ß¤ë¤È¡¤²¼µ­¤Î¤è¤¦¤Ë½ñ¤¤¤Æ¤¢¤ê¡¤¥Ç¥Õ¥©¥ë¥È¤Ç¥¨¥é¡¼»þ¤Ë¤Ï CORE::die ¤¬¸Æ¤Ó½Ð¤µ¤ì¤Æ¤¤¤ë¤È¤¤¤¦¤³¤È¤¬¤ï¤«¤ê¤Þ¤·¤¿¡¥

onerror => \&func
Reference to a die-compatible function, such as Carp::croak, 
that is called when there's a fatal error.

If this is set to undef, no errors will ever be shown.

If this value is not passed, Mech uses Carp::croak if Carp is 
installed, or CORE::die if not.

¤È¤¤¤¦¤³¤È¤Ç¡¤mechanize ¤ò new ¤¹¤ë¤È¤­¤Ë²¼µ­¤Î¤è¤¦¤Ë½ñ¤¯¤È¡¤¥¨¥é¡¼»þ¤Ë¤Ï²¿¤âÀ®¸ù¤¹¤ë¤Þ¤Ç¥È¥é¥¤(´À)¤¹¤ë¤è¤¦¤Ë¤Ê¤ê¤Þ¤·¤¿... ¼ÂºÝ¤Ë¤Ï retry ¤Î½èÍý¤Ê¤É¤ò½ñ¤«¤Ê¤¤¤È¤¤¤±¤Ê¤¤¤Î¤Ç¤¹¤¬¡¤get »þ¤ËÌäÂ꤬¤¢¤Ã¤¿¤é½ªÎ»¤·¤Ê¤¤¤è¤¦¤Ë¤Ï¤Ç¤­¤½¤¦¤Ç¤¹¡¥

my $mech = WWW::Mechanize->new(onerror => undef);
until (my $response = $mech->get("$url")) {}

´ØÏ¢¥ê¥ó¥¯

2010/01/15

¢£ [perl] YouTube ¤«¤é¹â²è¼Á¤Ê flv ¤ò¼èÆÀ¤¹¤ë perl ¥¹¥¯¥ê¥×¥È

¿¦¾ì¤ÇÃΤê¹ç¤¤¤«¤é flv ¤À¤±¤ò¼èÆÀ¤¹¤ë¥×¥í¥°¥é¥à¤òºî¤Ã¤ÆÍߤ·¤¤¤È¸À¤ï¤¿¤Î¤Çºî¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥get-youtubeflv.pl(¸å½Ò) ¤ò²¼µ­¤Î¤è¤¦¤Ë¼Â¹Ô¤·¤Þ¤¹¡¥¼Â¹Ô¤Ë¤Ï WebService::YouTube::Util ¤¬É¬ÍפǤ¹¡¥Ubuntu ¤ä debian ¤Ê¤É¤Ç¤Ï libwebservice-youtube-perl ¤È¤¤¤¦¥Ñ¥Ã¥±¡¼¥¸¤¬¤¢¤ë¤è¤¦¤Ç¤¹¡¥

% perl get-youtubeflv.pl videoid > output.flv

videoid ¤Ï http://www.youtube.com/watch?v=ETnQ2TDqCZM ¤È¤¤¤Ã¤¿ url ¤Î v= ¤Ë³¤¯Ê¸»úÎó¤Ç¤¹¡¥

#!/usr/bin/env perl
# get-youtubeflv.pl
use strict;
use WebService::YouTube::Util;
use LWP::Simple;

my $video_id = shift @ARGV or "ETnQ2TDqCZM";
my $uri = WebService::YouTube::Util->get_video_uri($video_id);
$uri .= "&fmt=35";
my $content = get($uri);
print $content;

¹â²è¼Á¤Ê flv ¤Î¼èÆÀ¤Ë¤Ï¤³¤³¤Ë½ñ¤«¤ì¤Æ¤¤¤ë fmt ¤Î¼ïÎà¤Î¤Þ¤È¤á¤«¤é¼êº¢¤Ë»È¤¨¤ë fmt=35 ¤òÁª¤Ó¤Þ¤·¤¿¡¥

  • fmt=35
    • ¼¡´ü "¹â²è¼Á"
    • flv: H264+AAC
  • fmt=22
    • HD²è¼Á
    • mp4: H264+AAC

¤È¤Æ¤â´Êñ¤Ê¥×¥í¥°¥é¥à¤Ê¤Î¤Ç¡¤¼èÆÀ¤ÎÅÓÃæ·Ð²á¤Ïɽ¼¨¤·¤Þ¤»¤ó¡¥¥µ¥¤¥º¤ÎÂ礭¤Ê flv ¤Î¼èÆÀ»þ¤Ë¤Ï¤Á¤ç¤Ã¤ÈÉÔÊؤ«¤â¤·¤ì¤Þ¤»¤ó¤Í¡¥


´ØÏ¢¥ê¥ó¥¯

2009/01/31

¢£ [perl] flickr API ¤Î flickr.tags.getClusters

¿¦¾ì¤Ç flickr API ¤Î flickr.tags.getClusters ¤ò»È¤Ã¤Æ¥¿¥°¤«¤é´ØÏ¢¤¹¤ëÊ̤Υ¿¥°¤òÆÀ¤¿¤¤¤Î¤Ç¥µ¥ó¥×¥ë¤òºî¤Ã¤ÆÍߤ·¤¤¤È¸À¤ï¤ì¤Þ¤·¤¿¡¥

flickr API ¤Ï»È¤Ã¤¿¤³¤È¤¬¤Ê¤«¤Ã¤¿¤Î¤Ç¡¤API Key¤òºî¤Ã¤Æ¤µ¤Ã¤½¤¯»î¤·¤Æ¤ß¤Þ¤·¤¿¡¥

Flickr ¤Î¥µ¥ó¥×¥ë¤ÏÂô»³¤¢¤ë¤À¤í¤¦¤È»×¤Ã¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡¤¼êº¢¤Ê¥µ¥ó¥×¥ë¤¬¤Ê¤¯¤ÆFlickr and Perl¤¬°ìÈ֤ޤȤâ¤Ê´¶¤¸¤Ç¤·¤¿¡¥

ÌäÂê¤Î flickr.tags.getClusters ¤Ï¥µ¥ó¥×¥ë¥³¡¼¥É¤ò Web ¸¡º÷¤Ç¸«¤Ä¤±¤é¤ì¤Ê¤«¤Ã¤¿¤Î¤Ç¡¤¼«Ê¬¤ÇŬÅö¤Ëºî¤Ã¤Æ¤·¤Þ¤¤¤Þ¤·¤¿¡¥flickr.tags.getClusters ¤ÇÆÀ¤é¤ì¤ë·ë²Ì¤ò xpath ¤Ç¥´¥ê¥´¥ê¤Ç¤­¤ë¤«¤È»×¤Ã¤Æ¤¤¤¿¤Î¤Ç¤¹¤¬¡¤¤ä¤êÊý¤¬¤ï¤«¤é¤Ê¤«¤Ã¤¿¤Î¤Ç¡¤·ë²Ì¤Î $response ¤ò¤½¤Î¤Þ¤Þ¥´¥ê¥´¥ê¤·¤Þ¤·¤¿¡¥¤³¤Î¤ä¤êÊý¤ÏÀäÂдְã¤Ã¤Æ¤¤¤½¤¦...

²¼µ­¤Î¥³¡¼¥É¤ò¼Â¹Ô¤¹¤ë¤È¡¤Ìµ»ö¥¿¥°¤Î¥¯¥é¥¹¥¿¤¬ÆÀ¤é¤ì¤Þ¤·¤¿¡¥

% perl get-tagclust.pl schubert
tag: schubert
$VAR1 = {
  '1' => {
    'musica' => 1,
    'music' => 1,
    'piano' => 1
  },
  '0' => {
    'wien' => 1,
    'austria' => 1,
    'vienna' => 1
  },
  '2' => {
    'mozart' => 1,
    'haydn' => 1,
    'beethoven' => 1
  }
};

·ë²Ì¤ò¸«¤ë¤È¤ª¤½¤é¤¯¶¦µ¯ÉÑÅ٤ι⤤¤â¤Î¤ò¥¯¥é¥¹¥¿¥ê¥ó¥°¤·¤Æ¤¤¤ë¤Î¤Ç¤·¤ç¤¦¤Í¡¥

#!/usr/bin/env perl
# get-tagclust.pl
# usage:
#   get-tagclust.pl <tag>
use strict;
use Data::Dumper;
use Flickr::API;
local $Data::Dumper::Indent = 1;

my $tag = shift @ARGV || "cows";
my %tagclust = get_flickrtagclust($tag);

print "tag: $tag\n";
print Dumper \%tagclust;

sub get_flickrtagclust {
 my $tag = shift;
 my $api_key = 'xxx';
 my $api_secret = xxx'';
 
 my $api = new Flickr::API(
			    { 
			     'key' => $api_key,
		     'secret' => $api_secret,
			    });
  my $response = $api->execute_method('flickr.tags.getClusters',
			      {
				       'key' => $api_key,
				       'tag' => $tag,
			      });
  my @tmp = @{$response->{tree}{children}[1]{children}};
  my $count = 0;
  my %clust;
  foreach my $i (@tmp) {
    my @list = ();
    if ($i->{name} eq "cluster") {
      foreach my $j (@{$i->{children}}) {
	if ($j->{children}[0]->{content}) {
	  push @list, $j->{children}[0]->{content};
	}
      }
    }
    if (@list > 0) {
      foreach (@list) {
	$clust{$count}{$_}++;
      }
      $count++;
    }
  }

  return %clust;
}

´ØÏ¢¥ê¥ó¥¯

2008/02/08

¢£ [perl] perl ¤Ç¥¨¥¯¥»¥ë¥Õ¥¡¥¤¥ë¤«¤é¥Æ¥­¥¹¥È¤òÃê½Ð¤¹¤ë

¿¦¾ì¤Ç¤Ê¤¼¤«ËÄÂç¤Ê¥¨¥¯¥»¥ë¥Õ¥¡¥¤¥ë¤ò Web ¥Ú¡¼¥¸¤Ë¤·¤¿¤¤¤È¸À¤ï¤ì¤Þ¤·¤¿¡¥

perl ¤Ç¤Ï Spreadsheet::ParseExcel ¤È¤¤¤¦¥â¥¸¥å¡¼¥ë¤ò»È¤¦¤È¤Ç¤­¤ë¤é¤·¤¤¡¥

¤µ¤Ã¤½¤¯¤³¤Î¥â¥¸¥å¡¼¥ë¤ò¥¤¥ó¥¹¥È¡¼¥ë¤·¤Æ¡¤¥µ¥ó¥×¥ë¥³¡¼¥É¤ò¼Â¹Ô¤¹¤ë¤È

Weak references are not implemented in the version of perl at /usr/....

¤È¤¤¤¦¥¨¥é¡¼¤Ç¼Â¹Ô¤Ç¤­¤Ê¤¤¡¥¥¨¥é¡¼¤ò¤½¤Î¤Þ¤Þ¸¡º÷¤·¤Æ¤ß¤ë¤È¡¤Scalar::Util ¤òºÆ¥¤¥ó¥¹¥È¡¼¥ë¤¹¤ë¤È¤Ê¤ª¤ë¤È¤Î¤³¤È¡¥¤½¤³¤Ç¡¤

cpan> install Scalar::Util

¤¹¤ë¤Èº£Å٤ϡ¤

Cannot forceunlink /usr/lib/perl5/5.8/cygwin/auto/List/Util/Util.dll Permission denied

¼Â¹ÔÃæ¤Î¥Õ¥¡¥¤¥ë¤À¤«¤é¾å½ñ¤­¤Ç¤­¤Ê¤¤¤È¤¤¤¦¤³¤È¤é¤·¤¤(cygwin ¤À¤«¤é¤Ê¤Î¤Ç¤¹¤¬)¡¥

¾åµ­¤Î Util.dll ¤ò¾Ã¤¹¤È cpan ¼«ÂΤ¬»È¤¨¤Ê¤¯¤Ê¤ë¤Î¤Ç¡¤¤É¤¦¤·¤è¤¦¤«¤È cpan ¾å¤ÇºÆ¹½ÃÛ¤¹¤ë¤³¤È¤ÇÂнè¤Ç¤­¤¿¡¥

% cpan
cpan> look Scalar::Util
Scar::Util ¤Î¥Ó¥ë¥É¤ËÆþ¤ë
% perl Makefile.PL
% make uninstall
% perl Makefile.PL -xs
% make
% make install
% exit

cygwin ¤ÏÊѤʤȤ³¤í¤Ç¤Ä¤Þ¤Å¤¯¤Î¤Ç¡¤ÌÌÅݤǤ¹¤Í¡¥¥µ¥¯¥µ¥¯Æ°¤¯ coLinux ¤ÎÊý¤¬Îɤ¤¤Î¤Ç¤·¤ç¤¦¤«¡¥

ºÇ½ªÅª¤Ë¥¨¥¯¥»¥ë¥Õ¥¡¥¤¥ë¤«¤é¥Æ¥­¥¹¥È¤òÃê½Ð¤¹¤ë¥³¡¼¥É¤Ï²¼µ­¤Î¤â¤Î¤ò»²¹Í¤Ë¤µ¤»¤Æ¤â¤é¤¤¤Þ¤·¤¿¡¥ÆüËܸì¤â¥ª¥±¤é¤·¤¤...

use strict;
use Spreadsheet::ParseExcel;
use Spreadsheet::ParseExcel::FmtJapan;
my $oExcel = new Spreadsheet::ParseExcel;
#sjis¡¢jis¤Ê¤É¤Î¥³¡¼¥É
my $oFmtJ = Spreadsheet::ParseExcel::FmtJapan->new(Code => 'euc');
my $oBook = $oExcel->Parse('Excel/Test97.xls', $oFmtJ);
#¾ðÊó¤Î¼è¤ê½Ð¤·Îã
my($iR, $iC, $oWkS, $oWkC);
   
print "FILE  :", $oBook->{File} , "\n";
print "COUNT :", $oBook->{SheetCount} , "\n";
print "AUTHOR:", $oBook->{Author} , "\n";
for(my $iSheet=0; $iSheet < $oBook->{SheetCount} ; $iSheet++) {
  $oWkS = $oBook->{Worksheet}[$iSheet];
  print "--------- SHEET:", $oWkS->{Name}, "\n";
  for(my $iR = $oWkS->{MinRow} ; 
          defined $oWkS->{MaxRow} && $iR <= $oWkS->{MaxRow} ; $iR++) {
      for(my $iC = $oWkS->{MinCol} ;
             defined $oWkS->{MaxCol} && $iC <= $oWkS->{MaxCol} ; $iC++) {
          $oWkC = $oWkS->{Cells}[$iR][$iC];
          print "( $iR , $iC ) =>", $oWkC->Value, "\n" if($oWkC);
      }
  }
}

2007/01/17

¢£ [perl] Perl Hacks

½Ð¤¿¤éÇ㤪¤¦¤«¤Ê¤È»×¤Ã¤Æ¤¤¤Þ¤¹¡¥

2007/01/03

¢£ [perl] ¸¡º÷¥¨¥ó¥¸¥ó Web ¥µ¡¼¥Ó¥¹

ºÇ¶á¸¡º÷¥¨¥ó¥¸¥ó¤Ø¤Î¸¡º÷¼°(¸¡º÷¥­¡¼¥ï¡¼¥É)¤ò³ÈÄ¥¤¹¤ë¥×¥í¥°¥é¥à¤ò½ñ¤¤¤Æ¤¤¤Þ¤¹¡¥

»÷¤¿¤è¤¦¤ÊÏÃ¤Ç Google ¤ä Yahoo! ¤Î´ØÏ¢¸¡º÷¤¬¤¢¤ê¤Þ¤¹¡¥¸¡º÷¥­¡¼¥ï¡¼¥É¤Ë¡Ö11n¡×¤ÈÆþ¤ì¤ë¤È²¼µ­¤Î¤è¤¦¤Ë¡Ö̵Àþ 11n¡×¤È¤¤¤¦¸¡º÷¥­¡¼¥ï¡¼¥É¤Ë´ØÏ¢¤·¤¿¥­¡¼¥ï¡¼¥É¤òÉÕ¤±¤Æ¤¯¤ì¤ë¤â¤Î¤Ç¤¹¡¥

Google ¤ä Yahoo! ¤Î´ØÏ¢¸¡º÷¤Ë¤Ä¤¤¤Æ¤Ï²¼µ­¤Ë¾¯¤·Ê¬ÀϤ¬½ñ¤«¤ì¤Æ¤¤¤Þ¤¹¤¬¡¤¥æ¡¼¥¶¤Î¸¡º÷¥­¡¼¥ï¡¼¥É¥Ù¡¼¥¹¤« Web ¥³¥ó¥Æ¥ó¥Ä¥Ù¡¼¥¹¤«¤È¤¤¤¦°ã¤¤¤¬¤¢¤ë¤è¤¦¤Êµ¤¤¬¤·¤Þ¤¹¡¥

»ä¤â¤¢¤ë¥­¡¼¥ï¡¼¥É¤ËÂФ·¤Æ´ØÏ¢¸ì¤òÍÑ°Õ¤·¤Æ¡¤¤½¤ÎÍ­¸úÀ­¤òÄ´¤Ù¤Æ¤ß¤è¤¦¤È»×¤Ã¤Æ¸¡º÷¥¨¥ó¥¸¥ó¤Ë¿§¡¹¤ÊÌ䤤¹ç¤ï¤»¤ò¹Ô¤Ê¤Ã¤Æ¤¤¤¿¤È¤³¤í¡¤¤¢¤ë»þµÞ¤Ë¸¡º÷¥¨¥ó¥¸¥ó¤«¤éÀܳ¤òµñÈݤµ¤ì¤Þ¤·¤¿¡¥

¤É¤¦¤ä¤é¥×¥í¥°¥é¥à¤Ç¤ä¤¿¤é¸¡º÷¥¨¥ó¥¸¥ó¤òÍøÍѤ¹¤ë¤Î¤Ï¥¤¥±¤Ê¤«¤Ã¤¿¤è¤¦¤Ç¤¹...¤¹¤¤¤Þ¤»¤ó¡¥

¤½¤³¤Ç³«È¯¼ÔÍѤθ¡º÷¥¨¥ó¥¸¥ó¤Î Web ¥µ¡¼¥Ó¥¹¤È¤¤¤¦¤Î¤ò»È¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥¤½¤ì¤¾¤ì²¼µ­¤Î¤è¤¦¤Ê¤â¤Î¤Ë¤Ê¤Ã¤Æ¤¤¤Þ¤¹¡¥

Yahoo!JAPAN

  • ¥¢¥¯¥»¥¹ÊýË¡: REST
  • ¸¡º÷À©¸Â²ó¿ô: 50000 /24h
  • 1 ¸¡º÷¤Ë¤ª¤±¤ëºÇÂ縡º÷·ë²Ì¿ô: 50
  • 1 ¥¯¥¨¥ê¤Ë¤ª¤±¤ëºÇÂ縡º÷¸ì¿ô: ?

Google

  • ¥¢¥¯¥»¥¹ÊýË¡: SOAP
  • ¸¡º÷À©¸Â²ó¿ô: 1000 /1day
  • 1 ¸¡º÷¤Ë¤ª¤±¤ëºÇÂ縡º÷·ë²Ì¿ô: 10
  • 1 ¥¯¥¨¥ê¤Ë¤ª¤±¤ëºÇÂ縡º÷¸ì¿ô: 32

Google ¤ÎÊý¤ÏÍøÍѲÄǽ¤Ê¸¡º÷²ó¿ô¤¬¾¯¤Ê¤¤¾å¤Ë¡¤¸½ºß¤Ï¿·µ¬ÍøÍѼԤòÂǤÁÀڤꤷ¤Æ¤¤¤ë¤Î¤Ç Yahoo! ¤ÎÊý¤ò»È¤Ã¤Æ¤ß¤Þ¤·¤¿¡¥

¤Þ¤º¤³¤Î¥Ú¡¼¥¸¤«¤é¥¢¥×¥ê¥±¡¼¥·¥ç¥ó ID ¤òÅÐÏ¿¤·¤Æ¡¤²¼µ­¤Î¥³¡¼¥É¤ò¼Â¹Ô¤·¤¿¤é Web ¸¡º÷·ë²Ì¤¬ÆÀ¤é¤ì¤Þ¤·¤¿¡¥

#!/usr/bin/env perl
# yapi_test.pl: 
# usage:
#   yapi_test.pl <kw>
use strict;
use LWP::Simple;
use XML::Simple;
use Data::Dumper;

my $kw = shift;
$kw =~ s/([^0-9A-Za-z_])/'%'.unpack('H2',$1)/ge;
$kw =~ s/ /+/g;

my $appid = "your appid";
my $top = "http://api.search.yahoo.co.jp/WebSearchService/V1/webSearch?";
my $url = $top . "appid=$appid&query=$kw&results=50";

my @ranking = map {$_->{Url}} @{get_results($url)}; 
print Dumper @ranking;

sub get_results {
   my ($url) = @_;
   my $yahoo_response = get($url);
   my $xmlsimple = XML::Simple->new();
   my $yahoo_xml = $xmlsimple->XMLin($yahoo_response);
   if (ref($yahoo_xml->{Result}) eq "ARRAY") { # found: many
       return $yahoo_xml->{Result};
   } elsif (ref($yahoo_xml->{Result}) eq "HASH") { # found: 1
       return [$yahoo_xml->{Result}];
   }
   return []; # not found
}

¼Â¹Ô¤¹¤ë¤È²¼µ­¤Î¤è¤¦¤Ê´¶¤¸¤Ë¤Ê¤ê¤Þ¤¹¡¥¤³¤ì¤Ç°ìÆü 5 Ëü²ó¤Þ¤Ç¼Â¸³¤¬¤Ç¤­¤½¤¦¤Ç¤¹¡¥

% perl yapi_test.pl 'som_pak vsom'
$VAR1 = 'http://mikilab.doshisha.ac.jp/dia/research/report/2005/0822/007/report20050822007.html';
$VAR2 = 'http://www.okada.jp.org/RWiki/index.php?R%A4%C7SOM(%BC%AB%B8%CA%C1%C8%BF%A5%B2%BD%A5%DE%A5%C3%A5%D7)';
$VAR3 = 'http://www.cis.hut.fi/research/som_pak/som_doc.txt';
$VAR4 = 'http://hpux.connect.org.uk/hppd/cgi-bin/wwwtar?/hpux/NeuralNets/som_pak-1.2/som_pak-1.2-src-9.01.tar.gz+som_pak-1.2/makefile.bsd+text';
$VAR5 = 'http://www.cis.hut.fi/somtoolbox/package/docs2/som_sompaktrain.html';
....
<Á°¤Î10·ï