Changeset 2197 for lang/perl/WWW-NicoVideo
- Timestamp:
- 12/01/07 03:02:29 (14 months ago)
- Location:
- lang/perl/WWW-NicoVideo/trunk/lib/WWW
- Files:
-
- 3 modified
-
NicoVideo.pm (modified) (3 diffs)
-
NicoVideo/Entry.pm (modified) (2 diffs)
-
NicoVideo/URL.pm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/WWW-NicoVideo/trunk/lib/WWW/NicoVideo.pm
r2189 r2197 17 17 use WWW::NicoVideo::URL; 18 18 19 __PACKAGE__->mk_accessors(qw[agent retry retryInterval mail passwd ]);19 __PACKAGE__->mk_accessors(qw[agent retry retryInterval mail passwd fetchEntry]); 20 20 21 21 our $VERSION = "0.04"; … … 37 37 retryInterval => $opts{retryInterval} || 30, 38 38 mail => $opts{mail}, 39 passwd => $opts{passwd}}, $pkg; 39 passwd => $opts{passwd}, 40 fetchEntry => $opts{fetchEntry}}, $pkg; 40 41 } 41 42 … … 149 150 150 151 my $scraper = scraper_entries(); 151 my @res = (map { WWW::NicoVideo::Entry->new($_) } 152 @{$scraper->scrape($html)->{entries} || []}); 152 my @res; 153 foreach my $e (@{$scraper->scrape($html)->{entries} || []}) { 154 my $ent = new WWW::NicoVideo::Entry($e); 155 $ent->fetch if($self->{fetchEntry}); 156 ; 157 push @res, $ent; 158 } 159 153 160 wantarray? @res: \@res; 154 161 } -
lang/perl/WWW-NicoVideo/trunk/lib/WWW/NicoVideo/Entry.pm
r1973 r2197 6 6 use warnings; 7 7 use base qw[Class::Accessor]; 8 use Carp; 9 use WWW::NicoVideo; 10 use WWW::NicoVideo::Scraper; 11 use WWW::NicoVideo::URL; 8 12 9 13 __PACKAGE__->mk_accessors(qw[id 10 14 comment 11 15 desc 16 fullDesc 17 postDateTime 18 postDateTimeStr 19 tags 12 20 imgHeight 13 21 imgUrl … … 21 29 title 22 30 url 31 agent 32 agentOpts 23 33 ]); 24 34 35 sub fetch 36 { 37 my $self = shift; 38 $self->{agent} ||= new LWP::UserAgent(agent => $WWW::NicoVideo::AGENT_NAME, 39 timeout => 30, 40 %{$self->{agentOpts}}); 41 my $uri = nicoURL("entry", $self->{id}); 42 43 my $scraper = scraper_entry; 44 $scraper->user_agent($self->{agent}); 45 46 my $ent; 47 eval { $ent = $scraper->scrape($uri) } or do { 48 carp $@; 49 return; 50 }; 51 52 @$self{keys %$ent} = values %$ent; 53 } 54 25 55 "Ritsuko"; -
lang/perl/WWW-NicoVideo/trunk/lib/WWW/NicoVideo/URL.pm
r2008 r2197 18 18 img => "http://res.nicovideo.jp/img/tpl/head/logo/rc.gif", 19 19 login => "https://secure.nicovideo.jp/secure/login?site=niconico", 20 fmt => "http://www.nicovideo.jp/%s/%s"); 20 entry_fmt => "http://www.nicovideo.jp/watch/%s", 21 entry_list_fmt => "http://www.nicovideo.jp/%s/%s"); 21 22 22 23 sub nicoURL … … 27 28 $type = "top" if(!$type and !@keys); 28 29 29 if(defined $type and @keys) {30 if(defined $type and $type =~ /^(?:tag|search)$/ and @keys) { 30 31 my $keys = join " ", @keys; 31 32 utf8::encode($keys) if(utf8::is_utf8($keys)); 32 return new URI(sprintf($NICO_URL{fmt}, $type, uri_escape($keys))); 33 return new URI(sprintf($NICO_URL{entry_list_fmt}, 34 $type, 35 uri_escape($keys))); 36 } elsif(defined $type and $type eq "entry" and @keys) { 37 my $id = $keys[0]; 38 return new URI(sprintf($NICO_URL{entry_fmt}, 39 $id)); 33 40 } elsif(defined $type and defined $NICO_URL{$type}) { 34 41 return new URI($NICO_URL{$type});
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)