line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: JASRAC.pm 1 2006-03-14 18:30:19Z daisuke $ |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Copyright (c) 2006 Daisuke Maki |
4
|
|
|
|
|
|
|
# All rights reserved. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package WWW::JASRAC; |
7
|
1
|
|
|
1
|
|
22285
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
8
|
1
|
|
|
1
|
|
982
|
use Encode qw(encode decode); |
|
1
|
|
|
|
|
14292
|
|
|
1
|
|
|
|
|
135
|
|
9
|
1
|
|
|
1
|
|
1288
|
use HTML::TreeBuilder; |
|
1
|
|
|
|
|
42744
|
|
|
1
|
|
|
|
|
12
|
|
10
|
1
|
|
|
1
|
|
1238
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
54270
|
|
|
1
|
|
|
|
|
41
|
|
11
|
1
|
|
|
1
|
|
603
|
use WWW::JASRAC::Result; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
12
|
|
|
|
|
|
|
our $VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
BEGIN { |
15
|
1
|
|
|
1
|
|
17
|
$VERSION = '0.01' |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use constant O_NAIGAI => 'naigai'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
64
|
|
19
|
1
|
|
|
1
|
|
5
|
use constant O_DOMESTIC => 'naikoku'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
20
|
1
|
|
|
1
|
|
4
|
use constant O_INTL => 'gaikoku'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
21
|
1
|
|
|
1
|
|
4
|
use constant O_ZENPOU => 'zenpou'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
39
|
|
22
|
1
|
|
|
1
|
|
12
|
use constant O_BUBUN => 'bubun'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
63
|
|
23
|
1
|
|
|
1
|
|
5
|
use constant O_KOHO => 'koho'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
45
|
|
24
|
1
|
|
|
1
|
|
6
|
use constant O_KANZEN => 'kanzen'; |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
41
|
|
25
|
1
|
|
|
1
|
|
5
|
use constant DEFAULT_OE => 'euc-jp'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
46
|
|
26
|
1
|
|
|
1
|
|
4
|
use constant DEFAULT_IE => 'euc-jp'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1184
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub new |
29
|
|
|
|
|
|
|
{ |
30
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
31
|
0
|
|
|
|
|
|
my %args = @_; |
32
|
0
|
|
0
|
|
|
|
my $self = bless { |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
33
|
|
|
|
|
|
|
ie => $args{ie} || DEFAULT_OE, |
34
|
|
|
|
|
|
|
oe => $args{oe} || DEFAULT_IE, |
35
|
|
|
|
|
|
|
ua => LWP::UserAgent->new, |
36
|
|
|
|
|
|
|
uri => $args{uri} || 'http://www2.jasrac.or.jp/cgi-bin/db2www/jwid040.d2w/report', |
37
|
|
|
|
|
|
|
}, $class; |
38
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub search |
44
|
|
|
|
|
|
|
{ |
45
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
46
|
0
|
|
|
|
|
|
my %args = @_; |
47
|
|
|
|
|
|
|
|
48
|
0
|
|
0
|
|
|
|
my $ie = $args{ie} || $self->{ie}; |
49
|
0
|
|
0
|
|
|
|
my $oe = $args{oe} || $self->{oe}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $ua = $self->{ua}; |
52
|
0
|
|
|
|
|
|
my %form = ( |
53
|
|
|
|
|
|
|
Naigai => 'naigai', |
54
|
|
|
|
|
|
|
Kensu => 110, |
55
|
|
|
|
|
|
|
# 作品名 |
56
|
|
|
|
|
|
|
L_SakJ => undef, |
57
|
|
|
|
|
|
|
K_SakJ => undef, # 前方/部分/後方/完全一致 |
58
|
|
|
|
|
|
|
L_SakK => undef, |
59
|
|
|
|
|
|
|
K_SakK => undef, # 前方/部分/後方/完全一致 |
60
|
|
|
|
|
|
|
# 権利者名 |
61
|
|
|
|
|
|
|
L_KenJ => undef, |
62
|
|
|
|
|
|
|
K_KenJ => undef, |
63
|
|
|
|
|
|
|
L_KenK => undef, |
64
|
|
|
|
|
|
|
K_KenK => undef, |
65
|
|
|
|
|
|
|
# アーティスト名 |
66
|
|
|
|
|
|
|
L_KasJ => undef, |
67
|
|
|
|
|
|
|
K_KasJ => undef, |
68
|
|
|
|
|
|
|
L_KasK => undef, |
69
|
|
|
|
|
|
|
K_KasK => undef, |
70
|
|
|
|
|
|
|
# 作品コード |
71
|
|
|
|
|
|
|
L_SakC => undef, |
72
|
|
|
|
|
|
|
K_SakC => undef, |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
0
|
0
|
|
|
|
|
if ($args{code}) { |
76
|
0
|
0
|
|
|
|
|
my $f = ref($args{code}) eq 'HASH' ? |
77
|
|
|
|
|
|
|
$args{code} : { text => $args{code} }; |
78
|
0
|
|
|
|
|
|
$form{L_SakC} = $f->{text}; |
79
|
0
|
|
0
|
|
|
|
$form{K_SakC} = $f->{option} || O_KANZEN; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
if ($args{title}) { |
83
|
0
|
0
|
|
|
|
|
my $f = ref($args{title}) eq 'HASH' ? |
84
|
|
|
|
|
|
|
$args{title} : { text => $args{title} }; |
85
|
0
|
|
|
|
|
|
$form{L_SakJ} = $f->{text}; |
86
|
0
|
|
0
|
|
|
|
$form{K_SakJ} = $f->{option} || O_KANZEN; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
if ($args{title_yomi}) { |
90
|
0
|
0
|
|
|
|
|
my $f = ref($args{title_yomi}) eq 'HASH' ? |
91
|
|
|
|
|
|
|
$args{title_yomi} : { text => $args{title_yomi} }; |
92
|
0
|
|
|
|
|
|
$form{L_SakK} = $f->{text}; |
93
|
0
|
|
0
|
|
|
|
$form{K_SakK} = $f->{option} || O_KANZEN; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
0
|
0
|
|
|
|
|
if ($args{rights_holder}) { |
97
|
0
|
0
|
|
|
|
|
my $f = ref($args{rights_holder}) eq 'HASH' ? |
98
|
|
|
|
|
|
|
$args{rights_holder} : { text => $args{rights_holder} }; |
99
|
0
|
|
|
|
|
|
$form{L_KenJ} = $f->{text}; |
100
|
0
|
|
0
|
|
|
|
$form{K_KenJ} = $f->{option} || O_KANZEN; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
0
|
0
|
|
|
|
|
if ($args{rights_holder_yomi}) { |
104
|
0
|
0
|
|
|
|
|
my $f = ref($args{rights_holder_yomi}) eq 'HASH' ? |
105
|
|
|
|
|
|
|
$args{rights_holder_yomi} : { text => $args{rights_holder_yomi} }; |
106
|
0
|
|
|
|
|
|
$form{L_KenK} = $f->{text}; |
107
|
0
|
|
0
|
|
|
|
$form{K_KenK} = $f->{option} || O_KANZEN; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
0
|
|
|
|
|
if ($args{artist}) { |
111
|
0
|
0
|
|
|
|
|
my $f = ref($args{artist}) eq 'HASH' ? |
112
|
|
|
|
|
|
|
$args{artist} : { text => $args{artist} }; |
113
|
0
|
|
|
|
|
|
$form{L_KasJ} = $f->{text}; |
114
|
0
|
|
0
|
|
|
|
$form{K_KasJ} = $f->{option} || O_KANZEN; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
0
|
0
|
|
|
|
|
if ($args{artist_yomi}) { |
118
|
0
|
0
|
|
|
|
|
my $f = ref($args{artist_yomi}) eq 'HASH' ? |
119
|
|
|
|
|
|
|
$args{artist_yomi} : { text => $args{artist_yomi} }; |
120
|
0
|
|
|
|
|
|
$form{L_KasK} = $f->{text}; |
121
|
0
|
|
0
|
|
|
|
$form{K_KasK} = $f->{option} || O_KANZEN; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
foreach my $key (keys %form) { |
125
|
0
|
0
|
|
|
|
|
unless ($form{$key}) { |
126
|
0
|
|
|
|
|
|
delete $form{$key} ; |
127
|
0
|
|
|
|
|
|
next ; |
128
|
|
|
|
|
|
|
} |
129
|
0
|
|
|
|
|
|
$form{$key} = encode('sjis', decode($ie, $form{$key})); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
my $response = $ua->post($self->{uri}, \%form); |
133
|
0
|
|
|
|
|
|
my $content = $response->content; |
134
|
0
|
|
|
|
|
|
my $original_encoding; |
135
|
0
|
0
|
|
|
|
|
if ($response->header('Content-Type') =~ /charset=([\w-]+)/) { |
136
|
0
|
|
|
|
|
|
$original_encoding = $1; |
137
|
|
|
|
|
|
|
} |
138
|
0
|
|
0
|
|
|
|
$original_encoding ||= 'sjis'; |
139
|
|
|
|
|
|
|
|
140
|
0
|
|
|
|
|
|
$content = encode($oe, decode($original_encoding, $content)); |
141
|
|
|
|
|
|
|
|
142
|
0
|
0
|
|
|
|
|
if ($content =~ /該当するデータは存在しませんでした/) { |
143
|
0
|
|
|
|
|
|
return undef; |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my @ret; |
147
|
0
|
|
|
|
|
|
my $tree = HTML::TreeBuilder->new_from_content($content); |
148
|
0
|
|
|
|
|
|
foreach my $row ($tree->look_down(_tag => 'tr')) { |
149
|
0
|
|
|
|
|
|
my @list = $row->content_list; |
150
|
0
|
0
|
|
|
|
|
next unless ref $list[0]; |
151
|
0
|
0
|
|
|
|
|
next unless $list[0]->as_text =~ /^([\d-]+)<\d+>$/; |
152
|
|
|
|
|
|
|
|
153
|
0
|
|
|
|
|
|
my $title = ($list[1]->look_down(_tag => 'a')); |
154
|
0
|
0
|
|
|
|
|
push @ret, WWW::JASRAC::Result->new( |
155
|
|
|
|
|
|
|
code => $1, |
156
|
|
|
|
|
|
|
link => $title->attr('href'), |
157
|
|
|
|
|
|
|
text => encode($self->{oe}, decode('euc-jp', $title->as_text)), |
158
|
|
|
|
|
|
|
rights => [ |
159
|
0
|
|
|
|
|
|
grep { length($_) && !/^\s+$/ } |
160
|
0
|
|
|
|
|
|
map { s/ / /g; s/\s$//; s/^\s+//; s/\s+/ /g; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
encode($self->{oe}, decode('euc-jp', $_)) } |
162
|
0
|
0
|
|
|
|
|
grep { !ref($_) } |
163
|
|
|
|
|
|
|
$list[2]->content_list ], |
164
|
|
|
|
|
|
|
artists => [ |
165
|
0
|
|
|
|
|
|
grep { length($_) && !/^\s+$/ } |
166
|
0
|
|
|
|
|
|
map { s/ / /g; s/\s$//; s/^\s+//; s/\s+/ /g; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
167
|
0
|
|
|
|
|
|
encode($self->{oe}, decode('euc-jp', $_)) } |
168
|
0
|
|
|
|
|
|
grep { !ref($_) } |
169
|
|
|
|
|
|
|
$list[3]->content_list ], |
170
|
|
|
|
|
|
|
); |
171
|
|
|
|
|
|
|
} |
172
|
0
|
|
|
|
|
|
$tree->delete; |
173
|
|
|
|
|
|
|
|
174
|
0
|
0
|
|
|
|
|
return wantarray ? @ret : \@ret; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
__END__ |