| | 51 | # $this->_parse_extra_config(). |
| | 52 | # parse user config. |
| | 53 | # |
| | 54 | sub _parse_extra_config |
| | 55 | { |
| | 56 | my $this = shift; |
| | 57 | my @config; |
| | 58 | $this->{extra} = \@config; |
| | 59 | |
| | 60 | $this->notice(__PACKAGE__."#_parse_extra_config"); |
| | 61 | $this->notice(">> ".join(", ", map{split(' ', $_)}$this->config->extra('all'))); |
| | 62 | |
| | 63 | foreach my $token (map{split(' ', $_)}$this->config->extra('all')) |
| | 64 | { |
| | 65 | $this->notice("extra: $token"); |
| | 66 | my $name = "extra-$token"; |
| | 67 | my $block = $this->config->$name; |
| | 68 | if( !$block ) |
| | 69 | { |
| | 70 | $this->notice("no such extra config: $name"); |
| | 71 | next; |
| | 72 | } |
| | 73 | if( !ref($block) ) |
| | 74 | { |
| | 75 | my $literal = $block; |
| | 76 | $block = Configuration::Block->new($name); |
| | 77 | $block->extract($literal); |
| | 78 | } |
| | 79 | my $has_param; |
| | 80 | my $config = {}; |
| | 81 | $config->{name} = $name; |
| | 82 | $config->{url} = $block->url; |
| | 83 | if( !$config->{url} ) |
| | 84 | { |
| | 85 | $this->notice("no url on $name"); |
| | 86 | next; |
| | 87 | } |
| | 88 | if( my $recv_limit = $block->get('recv_limit') ) |
| | 89 | { |
| | 90 | while( $recv_limit =~ s/^\s*(\d+)\*(\d+)/$1*$2/e ) |
| | 91 | { |
| | 92 | } |
| | 93 | $config->{recv_limit} = $recv_limit; |
| | 94 | $has_param = 1; |
| | 95 | } |
| | 96 | my @extract; |
| | 97 | foreach my $line ($block->extract('all')) |
| | 98 | { |
| | 99 | $has_param ||= 1; |
| | 100 | my $type; |
| | 101 | my $value = $line; |
| | 102 | if( $value =~ s/^(\w+)(:\s*|\s+)// ) |
| | 103 | { |
| | 104 | $type = $1; |
| | 105 | } |
| | 106 | $type ||= 're'; |
| | 107 | if( $type eq 're' ) |
| | 108 | { |
| | 109 | $value =~ s{^/(.*)/(\w*)\z/}{(?$2:$1)}; |
| | 110 | my $re = eval{ |
| | 111 | local($SIG{__DIE__}) = 'DEFAULT'; |
| | 112 | qr/$value/s; |
| | 113 | }; |
| | 114 | if( my $err = $@ ) |
| | 115 | { |
| | 116 | chomp $err; |
| | 117 | $this->notice("invalid regexp $re on $name, $err"); |
| | 118 | next; |
| | 119 | } |
| | 120 | push(@extract, $re); |
| | 121 | }else |
| | 122 | { |
| | 123 | $this->notice("unknown extract type $type on $name"); |
| | 124 | next; |
| | 125 | } |
| | 126 | } |
| | 127 | if( @extract ) |
| | 128 | { |
| | 129 | $config->{extract} = @extract==1 ? $extract[0] : \@extract; |
| | 130 | } |
| | 131 | if( keys %$config==1 ) |
| | 132 | { |
| | 133 | $this->notice("no config on $name"); |
| | 134 | next; |
| | 135 | } |
| | 136 | push(@config, $config); |
| | 137 | } |
| | 138 | |
| | 139 | $this; |
| | 140 | } |
| | 141 | |
| | 142 | # ----------------------------------------------------------------------------- |
| | 253 | { |
| | 254 | # 15. game? |
| | 255 | url => 'http://splax.net/jun.html?p=*', |
| | 256 | extract => sub{ |
| | 257 | my $req = shift; |
| | 258 | if( $req->{url} =~ /\?p=([^&;=#]+)/ ) |
| | 259 | { |
| | 260 | my $q = $1; |
| | 261 | $q =~ s/%([0-9A-F]{2})/pack("H*",$1)/gie; |
| | 262 | $q =~ s/\*([0-9A-F]{2})/pack("H*",$1)/gie; |
| | 263 | $q = Unicode::Japanese->new($q, "sjis")->utf8; |
| | 264 | $q =~ s/\*.*//; |
| | 265 | $q = "「$qの唄」"; |
| | 266 | }else |
| | 267 | { |
| | 268 | return; |
| | 269 | } |
| | 270 | }, |
| | 271 | }, |
| | 272 | { |
| | 273 | # 16. recordchina. |
| | 274 | url => 'http://www.recordchina.co.jp/group/*', |
| | 275 | recv_limit => 12*1024, |
| | 276 | extract => qr{<div id="news_detail_title" class="ft04">(.*?)</div>}s, |
| | 277 | }, |