mixi ミュージック送信 Perl モジュールを作ってみたよ!
mixi ミュージック送信モジュールを作ってみた!!はまちちゃんのmixi ミュージック送信機をまんま Perl モジュールに移し変えただけだよ…!
これがあれば、mixi station (mixi からダウンロードできるやつ win/mac) とか、iTunes なしで、お気に入りの曲をガンガン送信する Perl スクリプトが書けちゃうかもしれないよ!
やったね!
でもぼく貧乏でプレミアム会員になるお金がないから、このモジュールは全くの未テストなんだけど!
使い方は、コード内の SYNOPSIS を見てね!手抜きじゃないよ、DRY だよ…!
mixi プレミアム会員のひとは、よかったらためしてみてね!
…ちゃんと動くかわかんないけど!
でもあんまりやり過ぎると、はまちちゃんみたいに ID ban されちゃうよ!ほどほどにね…!
追記。
とかゆってたら、Yappo さんが Publish::MixiMusic をつくってたよ!みんな考えることは一緒だね…!
package WebService::MixiMusic; use strict; use warnings; use Readonly; use LWP::UserAgent; use base qw(Class::ErrorHandler); Readonly my $login_uri => 'https://upload.mixi.jp/music/login.pl'; Readonly my $upload_uri => 'http://upload.mixi.jp/music/upload.pl'; sub new { my ($class, %args) = @_; my $email = delete $args{email} || return $class->error('email is required'); my $password = delete $args{password} || return $class->error('password is required'); my $agent = delete $args{agent}; bless { email => $email, password => $password, ua => LWP::UserAgent->new(agent => $agent || 'mmm/v0.1 (by glucose)'), session_id => undef, }, $class; } sub login { my $self = shift; my $response = $self->{ua}->post($login_uri, { email => $self->{email}, password => $self->{password}, }); return $self->error('login failed...') if ($response->is_error || !(($self->{session_id}) = $response->content =~ m|session_id=([0-9a-z_]+)|ims)); } sub upload { my ($self, $report) = @_; my $response = $self->{ua}->post($upload_uri, { session_id => $self->{session_id}, data => $report->as_xml, }); return $self->error($response->code.': '.$response->message) if ($response->is_error); } package WebService::MixiMusic::Report; sub new { my $class = shift; bless { tracks => [] }, $class; } sub add_track { my ($self, @tracks) = @_; for my $track (@tracks) { push @{$self->{tracks}}, $track; } } sub as_xml { my $self = shift; my $xml = qq|<?xml version="1.0" encoding="utf-8"?>\n<report>\n|; for my $track (@{$self->{tracks}}) { $xml .= <<'EOS'; <track> <name>@{[$track->{name}]}</name> <artist>@{[$track->{artist}]}</artist> <album>@{[$track->{album}]}<album> <genre>@{[$track->{genre}]}</genre> <timestamp>@{[$track->{timestamp}]}</timestamp> </track> EOS } $xml .= qq|</report>|; } 1; __END__ =head1 NAME WebService::MixiMusic - Hello! Hello! My name is Hamachi-chan...! =head1 SYNOPSIS use WebService::MixiMusic; use WebService::MixiMusic::Report; my $mm = WebService::MixiMusic->new( email => email, pasword => password, ); $mm->login or die($mm->errstr); my $report = WebService::MixiMusic::Report->new; $report->add_track( { name => 'ぼくはまちちゃん', artist => 'はまちや2', album => 'こんにちは!こんにちは!', genre => 'Rock', timestamp => '2006-05-23T21:35:55%2b09:00', }, { name => 'ぼくけんたろたん><ノ', artist => 'けんたろたん', album => '海ゆかば', genre => 'Jazz', timestamp => '2006-05-23T21:35:55%2b09:00', }, ); $mm->upload($report); =head1 DESCRIPTION WebService::MixiMusic provides a perl interface to Mixi Music. =head1 METHODS =over 4 =head2 login =head2 upload =back =head1 SEE ALSO =over 4 =item Mixi Music L<http://music.mixi.jp/search_music.pl> =item Hamachi-chan's hack L<http://mxxi.hamachiya.com/2006/05/mixi_8.html> =back =head1 AUTHOR Kentaro Kuribayashi, <k.kentaro☆gmail.com> =head1 COPYRIGHT Copyright 2006 Kentaro Kuribayashi This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut