[nFinder] data-api-dataの形式変更対応


data-api-dataの形式変更対応#

html5版再生ページがまた変わったので対策。mediaTypeとwatchAuthKeyとcsrfTokenが見当たらんが、大丈夫かな?
smile鯖が403返す現象の対策が不明なので、今のところDMC対応必須。例によってeco/非プレは未確認。
Niconicomeの修正内容を参考にさせていただいた。

1. nFinder2 → nFinder2.exe → TrinityCS → Scrape を開く
2. 「SmileVideoInfoDataClass GetVideoInfoHTML_Zero」を検索
3. Edit Method (C#)...
4. 1個目の「catch」のすぐ下にある「{」と「}」の間に下記を挿入
(https://writening.net/page?C6unDM の対応をしている人は、その際に足した分を消して下記を入れなおす。)
foreach (HtmlNode htmlNode2 in ((IEnumerable<HtmlNode>)htmlDocument.DocumentNode.SelectNodes("//div[@id=\"js-initial-watch-data\"]")))
{
text = WebUtility.HtmlDecode(htmlNode2.GetAttributeValue("data-api-data", ""));
if (text != "")
{
Dictionary<string, string> dict = new Dictionary<string, string>();
dict[":root:owner:nickname"] = "";
dict[":root:owner:id"] = "";
dict[":root:channel:name"] = "";
dict[":root:channel:id"] = "";
dict[":root:channel:isOfficialAnime"] = "";
dict[":root:client:watchId"] = "";
dict[":root:video:id"] = "";
dict[":root:video:description"] = "";
dict[":root:video:thumbnail:url"] = "";
dict[":root:video:registeredAt"] = "";
dict[":root:video:count:view"] = "";
dict[":root:video:count:mylist"] = "";
dict[":root:video:duration"] = "";
dict[":root:video:title"] = "";
using (System.Xml.XmlDictionaryReader reader = System.Runtime.Serialization.Json.JsonReaderWriterFactory.CreateJsonReader(System.Text.Encoding.UTF8.GetBytes(text), System.Xml.XmlDictionaryReaderQuotas.Max))
{
string key = "";
while (reader.Read())
{
if (reader.NodeType == System.Xml.XmlNodeType.Element)
{
key = key + ":" + reader.Name;
}
else if (reader.NodeType == System.Xml.XmlNodeType.EndElement)
{
key = key.Substring(0, key.Length - reader.Name.Length - 1);
}
else if (reader.NodeType == System.Xml.XmlNodeType.Text)
{
string val = "";
dict.TryGetValue(key, out val);
dict[key] = val + reader.Value;
}
}
}
smileVideoInfoDataClass.username = dict[":root:owner:nickname"];
smileVideoInfoDataClass.userId = dict[":root:owner:id"];
if (smileVideoInfoDataClass.username == "")
{
smileVideoInfoDataClass.username = dict[":root:channel:name"];
smileVideoInfoDataClass.userId = dict[":root:channel:id"];
}
smileVideoInfoDataClass.v = dict[":root:client:watchId"];
smileVideoInfoDataClass.isOfficialAnime = dict[":root:channel:isOfficialAnime"];
smileVideoInfoDataClass.id = dict[":root:video:id"];
smileVideoInfoDataClass.description = dict[":root:video:description"];
smileVideoInfoDataClass.thumbnail = dict[":root:video:thumbnail:url"];
smileVideoInfoDataClass.postedAt = Regex.Replace(dict[":root:video:registeredAt"], "[ +].*", "").Replace('-', '/').Replace('T', ' ');
smileVideoInfoDataClass.viewCount = dict[":root:video:count:view"];
smileVideoInfoDataClass.mylistCount = dict[":root:video:count:mylist"];
smileVideoInfoDataClass.length = dict[":root:video:duration"];
smileVideoInfoDataClass.title = dict[":root:video:title"];
smileVideoInfoDataClass.channelId = dict[":root:channel:id"];
smileVideoInfoDataClass.VideoScriptBody = string.Concat(new string[]
{
"\tso.addVariable(\"thumbTitle\", \"",
HttpUtility.UrlEncode(smileVideoInfoDataClass.title),
"\");\r\n\tso.addVariable(\"thumbDescription\", \"",
HttpUtility.UrlEncode(Regex.Replace(smileVideoInfoDataClass.description, "</?a[^>]*>", "")),
"\");\r\n\tso.addVariable(\"thumbImage\", \"",
HttpUtility.UrlEncode(smileVideoInfoDataClass.thumbnail),
"\");\r\n\tso.addVariable(\"videoTitle\", \"",
HttpUtility.UrlEncode(smileVideoInfoDataClass.title),
"\");\r\n\tso.addVariable(\"v\", \"",
smileVideoInfoDataClass.v,
"\");\r\n\tso.addVariable(\"videoId\", \"",
smileVideoInfoDataClass.id,
"\");\r\n\tso.addVariable(\"movie_type\", \"mp4\");\r\n"
});
return smileVideoInfoDataClass;
}
}
5. Compileを押す
6. 「Identifier expected」等のエラーが下に出るので、そこをダブルクリック
7. 赤い「o__SiteContainer0」ってのがある行に移動するので、
その2行上の「// Token: ...」の行から、「p__Site3」がある行の1行下の「}」までを削除。
(そこより後ろに「}」がもう2個あるけどそれらは残す)
8. Compileを押す。今度は成功するはず。
9. Save AllでnFinder.exeを保存
10. nico.rbに「exit(1) if json["video"]["dmcInfo"].nil?」 という行がある場合は削除
11. nico.rbの「dmc_info = json["video"]["dmcInfo"]["session_api"]」の行から
「"priority":dmc_info["priority"]}}.to_json」の行まで(24行くらい)を削除、下記に差し替える
exit(1) if json["media"].nil?
exit(1) if json["media"]["delivery"].nil?
dmc_info = json["media"]["delivery"]

req_body =
{"session":{"recipe_id":dmc_info["recipeId"],
"content_id":dmc_info["movie"]["contentId"],
"content_type":"movie",
"content_src_id_sets":[{"content_src_ids":[{"src_id_to_mux":{
"video_src_ids":dmc_info["movie"]["session"]["videos"],
"audio_src_ids":dmc_info["movie"]["session"]["audios"]}}]}],
"timing_constraint":"unlimited",
"keep_method":{"heartbeat":{"lifetime":dmc_info["movie"]["session"]["heartbeatLifetime"]}},
"protocol":{"name":"http",
"parameters":{"http_parameters":{"parameters":{"http_output_download_parameters":{"use_well_known_port":"no",
"use_ssl":"no"}}}}},
"content_uri":"",
"session_operation_auth":{"session_operation_auth_by_signature":{
"token":dmc_info["movie"]["session"]["token"],
"signature":dmc_info["movie"]["session"]["signature"]}},
"content_auth":{"auth_type":dmc_info["movie"]["session"]["authTypes"]["http"],
"content_key_timeout":dmc_info["movie"]["session"]["contentKeyTimeout"],
"service_id":"nicovideo",
"service_user_id":dmc_info["movie"]["session"]["serviceUserId"]},
"client_info":{"player_id":dmc_info["movie"]["session"]["playerId"]},
"priority":dmc_info["movie"]["session"]["priority"]}}.to_json
12. nico.rbに「"originalTitle"」と書かれているとこが一か所あるので「"title"」に変更
お知らせ
実務でも趣味でも役に立つ多機能Webツールサイト【無限ツールズ】で、日常をちょっと便利にしちゃいましょう!
無限ツールズ

 
writening