-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
165 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
*.pl text eol=lf | ||
*.cgi text eol=lf | ||
*.html text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
#!/usr/bin/perl | ||
#use Net::Netrc; | ||
use LWP::UserAgent; | ||
use URI::Escape; | ||
use CGI; | ||
use Web::Scraper; | ||
use Unicode::Escape qw(escape unescape); | ||
use JSON; | ||
use File::Spec; | ||
use File::Basename; | ||
|
||
require File::Spec->catfile(dirname(__FILE__),"common.pl"); | ||
|
||
print <<"HEAD"; | ||
Content-type: application/xml | ||
Access-Control-Allow-Origin: * | ||
HEAD | ||
|
||
#my $mach = Net::Netrc->lookup('nicovideo'); | ||
#my ($nicologin, $nicopassword, $nicoaccount) = $mach->lpa; | ||
|
||
my %conf=GetConf("/etc/nicochcgi/nicoch.conf"); | ||
$nicologin = $conf{"niconico_id"}; | ||
$nicopassword=$conf{"niconico_password"}; | ||
|
||
my $login_info = { | ||
mail_tel => $nicologin, | ||
password => $nicopassword, | ||
}; | ||
|
||
my $q=new CGI; | ||
#my $movie_id=$q->param('id'); | ||
my $movie_id="so43707962"; | ||
|
||
my $ua = LWP::UserAgent->new(cookie_jar => {}); | ||
$ua->post("https://secure.nicovideo.jp/secure/login?site=niconico", $login_info); | ||
|
||
my $info_res = $ua->get("https://www.nicovideo.jp/watch/".$movie_id); | ||
my $info_json = scraper { | ||
process 'div#js-initial-watch-data', 'json' => '@data-api-data' | ||
}->scrape($info_res->content)->{json}; | ||
$info_json = unescape($info_json); | ||
$info = decode_json( $info_json ); | ||
|
||
#my $ms= $info->{thread}->{serverUrl}; | ||
my $ms= $info->{comment}->{server}->{url};#"https://nvcomment.nicovideo.jp/legacy/api/" | ||
#my $user_id= $info->{video}->{dmcInfo}->{user}->{user_id}; | ||
my $user_id = $info->{viewer}->{id}; | ||
my $user_key = $info->{comment}->{keys}->{userKey}; | ||
my $length = $info->{video}->{duration}; | ||
my $threads = $info->{comment}->{threads}; | ||
|
||
my $min=int($length/60)+1; | ||
my $post_msg="<packet>\n"; | ||
|
||
foreach my $thread (@$threads){ | ||
if($thread->{isActive} == 1){ | ||
my $thread_id = $thread->{id}; | ||
if($thread->{isThreadkeyRequired} == 1){ | ||
#my $thread_key_res=$ua->get("http://flapi.nicovideo.jp/api/getthreadkey?thread=".$thread->{id}); | ||
|
||
#my $thread_key = ParseUrl($thread_key_res->content,"threadkey"); | ||
#my $force_184 = ParseUrl($thread_key_res->content,"force_184"); | ||
my $thread_key = $thread->{threadkey}; | ||
my $force_184 = $thread->{is184Forced}; | ||
|
||
$post_msg.=<<"PACKET" | ||
<thread thread="$thread_id" version="20090904" threadkey="$thread_key" force_184="$force_184" user_id="$user_id" /> | ||
<thread_leaves scores="1" thread="$thread_id" threadkey="$thread_key" force_184="$force_184" user_id="$user_id">0-$min:100,1000</thread_leaves> | ||
PACKET | ||
}else{ | ||
$post_msg.=" <thread thread=\"$thread_id\" version=\"20061206\" res_from=\"-1000\" user_id=\"$user_id\" userkey=\"$user_key\" />\n"; | ||
if($thread->{isLeafRequired} == 1){ | ||
$post_msg.=" <thread_leaves scores=\"1\" thread=\"$thread_id\" user_id=\"$user_id\" userkey=\"$user_key\">0-$min:100,1000</thread_leaves>\n"; | ||
} | ||
} | ||
} | ||
} | ||
|
||
$post_msg.="</packet>\n"; | ||
|
||
my $req=HTTP::Request->new(POST => $ms); | ||
$req->content($post_msg); | ||
print $ua->request($req)->content; | ||
|
||
sub ParseUrl{ | ||
my $text=$_[0]; | ||
my $key=$_[1]; | ||
my ($res) = $text=~ m/$key\=([^\&]+)/; | ||
return uri_unescape($res); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters