シリーズ仮対応


ニコニコのシリーズをマイリストタブで開けるようにする
お気に入り登録は→ https://writening.net/page?XCsKEa
2/3 仕様変更がありました
nico.rbの修正部分 https://writening.net/page?sNWHd2
       
1/27 タイトル等に一部の文字が含まれてると開けない問題を修正
投稿時間が数時間前と表示される物が含まれていると開けない問題を修正(現在時刻で代用)


直せそうもない不具合(ニコニコ側の仕様)
・並べ替えは左上のドロップメニューでは出来ない
 タイトルや登録更新日時といった部分をクリックしてやるのは可能

*追記
nico.rbがShift-JIS以外の形式で保存されているとエラーが出る模様

Rubyを使用しているので先に以下の修正が必要
センシティブな動画を検索する https://writening.net/page?wkJnYg
投稿動画をすべて取得する https://writening.net/page?ahTbLZ
dnSpy
nFinder>mFinder_Main
5098行目辺りにある
flag = (Microsoft.VisualBasic.Strings.InStr(text, "http://www.nicovideo.jp/myvideo/", CompareMethod.Text) > 0);
を右クリックしてEdit IL
"http://www.nicovideo.jp/myvideo/"

"http://www.nicovideo.jp/series/"
に変更
少し下にも"http://www.nicovideo.jp/myvideo/"があるのでそこも同様に変更しOK 保存

動画情報欄から開けるようする部分
dnSpy
nFinder>mPlayer_Sputnik
13082行目辺り
flag = (Microsoft.VisualBasic.Strings.InStr(redirectUrl, "http://www.nicovideo.jp/myvideo/"
を右クリックしてEdit IL...
"http://www.nicovideo.jp/myvideo/"

"http://www.nicovideo.jp/series/"
に変更して保存。
myvideoはもう使われていないので差し替えても問題ないはず


以下では動かないので注意
修正版を利用して→ https://writening.net/page?sNWHd2
nico.rb
9行目辺りにある
require 'kconv'
の下に
require 'rss/maker'
をコピペ

40行目付近にある
if target.include?("/video?")の上に以下をコピペ

if nico_url.include?("/series") #シリーズ読込
doc = Nokogiri::HTML.parse(html)
conta = "div.NC-MediaObject.NC-VideoMediaObject.NC-VideoMediaObject_thumbnailWidth192.SeriesVideoListContainer-video > div"

rss = RSS::Maker.make("2.0") do |maker|
maker.channel.title = CGI.escapeHTML(doc.css('div.SeriesDetailContainer-bodyTitle').inner_text)#シリーズ名
maker.channel.description = doc.css("div.ExpandableText-expandedText > div").text #シリーズ説明
maker.channel.link = doc.css("head > meta:nth-child(14)").attribute('content') #シリーズURL
maker.channel.dc_creator = doc.css('div.SeriesAdditionalContainer-ownerArea > a').inner_text #投稿者名

doc.css(conta).each do |node| #動画の数だけ繰り返す
title = CGI.escapeHTML(node.css("div.NC-Thumbnail-image").attribute('aria-label').to_s) #タイトル
link = node.css("a.NC-Link.NC-MediaObject-contents").attribute('href').value #リンク
link = link.sub("https","http")#httpsは読めない
length = node.css("div.NC-VideoLength").text #動画時間
time = node.css("span.NC-VideoRegisteredAtText-text").text #投稿日時
time = Time.now.to_s if time.include?("前".encode("UTF-8"))#数分~数時間前に投稿された動画は現在時刻で代用
time = Time.parse(time).strftime("%Y年%m月%d日 %H:%M:%S").to_s.encode("UTF-8")#年月日に変換しておかないと読めない
view = node.css("div.NC-VideoMetaCount.NC-VideoMetaCount_view").text#再生回数
view = (view.to_f * 10000).to_i.to_s if view.include?("万".encode("UTF-8"))
#数字以外が入ると正しく取得できないので消す
comment = node.css("div.NC-VideoMetaCount.NC-VideoMetaCount_comment").text #コメント数
comment =(comment.to_f * 10000).to_i.to_s if comment.include?("万".encode("UTF-8"))
my = node.css("div.NC-VideoMetaCount.NC-VideoMetaCount_mylist").text #マイリスト数
my =(my.to_f * 10000).to_i.to_s if my.include?("万".encode("UTF-8"))

description = '<![CDATA[<p class="nico-thumbnail"><img alt="" src="" width="94" height="70" border="0"/></p><p class="nico-description"></p><p class="nico-info"><small><strong class="nico-info-length">'<< length <<'</strong><strong class="nico-info-date">'<< time <<'</strong></small></p><p class="nico-numbers"><small><strong class="nico-numbers-view">'<< view <<'</strong><strong class="nico-numbers-res">'<< comment <<'</strong><strong class="nico-numbers-mylist">'<< my <<'</strong></small></p>]]>'
#nFinderは正規表現置換で読み込んでいるのでほぼ弄れない
item = maker.items.new_item #rss作成部分
item.title = title
item.link = link
item.description = description
end
end
result = CGI.unescapeHTML(rss.to_s.tr("\n^", ''))
result = Regexp.escape(result)
result = NKF.nkf("--ic=UTF-8 --oc=SJIS --fb-java", result)
puts result
puts ""
puts ""
puts ""
exit(0)
end

#コメントは備忘録代わりに残してます。修正歓迎
お知らせ
実務でも趣味でも役に立つ多機能Webツールサイト【無限ツールズ】で、日常をちょっと便利にしちゃいましょう!
無限ツールズ

 
writening