Skip to content

Commit

Permalink
Versiom 0.1.0.02
Browse files Browse the repository at this point in the history
MakeSession()作成
DataJson()メソッドのtry...catch作成
start_rec()内でエラーが出た場合のエラー処理強化
中断(Abort)作成
  • Loading branch information
nnn-revo2012 committed Jun 19, 2023
1 parent a1ea784 commit 84bef51
Show file tree
Hide file tree
Showing 5 changed files with 265 additions and 58 deletions.
241 changes: 197 additions & 44 deletions Sirrene/DataJson.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Diagnostics;
Expand Down Expand Up @@ -31,11 +32,12 @@ public class DataJson
public string Community_Id { set; get; }
public string Community_Thumbnail { set; get; }
public string User_Id { set; get; }
public string AccountType { set; get; }
public bool IsPremium { set; get; }
public bool IsPeakTime { set; get; }
public bool IsEconomy { set; get; }
public bool IsWatchVideo { set; get; }
public string Session_Url { set; get; }
public string Session_Data { set; get; }


public DataJson(string videoid)
Expand All @@ -51,42 +53,185 @@ public DataJson(string videoid)
this.Title = "";

}
public bool GetData(JObject datajson)
public (bool result, string err) GetDataJson(JObject datajson)
{
if (datajson["viewer"] != null)
{
if ((bool)datajson["viewer"]["isPremium"])
this.IsPremium = true;
}
var result = false;
var err = "";

if (datajson["system"] != null)
try
{
if ((bool)datajson["system"]["isPeakTime"])
this.IsPeakTime = true;
}
if (datajson["viewer"] != null)
{
if ((bool)datajson["viewer"]["isPremium"])
this.IsPremium = true;
}
else
{
err = "JSON data viewer not found.";
return (result, err);
}

if (datajson["media"]["delivery"] != null)
{
if (!datajson["media"]["delivery"].HasValues)
this.IsWatchVideo = false;
}
if (datajson["system"] != null)
{
if ((bool)datajson["system"]["isPeakTime"])
this.IsPeakTime = true;
}
else
{
err = "JSON data system not found.";
return (result, err);
}

if (datajson["media"]["delivery"] != null)
{
if (!datajson["media"]["delivery"].HasValues)
this.IsWatchVideo = false;
}
else
{
err = "JSON data media delivery not found.";
return (result, err);
}

this.IsEconomy = this.IsPeakTime;
if (this.IsPeakTime && !this.IsPremium)
if (IsWatchVideo)
if (datajson["media"]["delivery"]["movie"] != null)
this.IsEconomy = this.IsPeakTime;
if (this.IsPeakTime)
if (this.IsPremium)
{
if ((bool)(datajson["media"]["delivery"]["movie"]["audios"][0]["isAvailable"]) &&
(bool)(datajson["media"]["delivery"]["movie"]["videos"][0]["isAvailable"]))
this.IsEconomy = false;
this.IsEconomy = false;
}
else
{
if (IsWatchVideo)
if (datajson["media"]["delivery"]["movie"] != null)
{
if ((bool)(datajson["media"]["delivery"]["movie"]["audios"][0]["isAvailable"]) &&
(bool)(datajson["media"]["delivery"]["movie"]["videos"][0]["isAvailable"]))
this.IsEconomy = false;
}
}

if (datajson["video"] != null)
{
this.Title = (string)datajson["video"]["title"];
}
else
{
err = "JSON data video not found.";
return (result, err);
}

if (datajson["video"] != null)
result = true;
return (result, err);
}
catch (Exception Ex) //その他のエラー
{
this.Title = (string)datajson["video"]["title"];
DebugWrite.Writeln(nameof(GetDataJson), Ex);
err = Ex.Message;
return (result, err);
}
}

return true;
public (string result, string err) MakeSession(JObject datajson)
{
var result = "";
var err = "";
JToken session = null;
StringBuilder sb = new StringBuilder();

try
{
if (datajson["media"]["delivery"] != null)
{
if (datajson["media"]["delivery"].HasValues)
session = datajson["media"]["delivery"]["movie"]["session"];
}
else
{
err = "JSON data media delivery not found.";
return (result, err);
}

var recipe_id = (string)session["recipeId"];
var player_id = (string)session["playerId"];
var content_id = (string)session["contentId"];
var token = ((string)session["token"]).Replace("\"", "\\\"");
var signature = (string)session["signature"];
var user_id = (string)session["serviceUserId"];
var videos = session["videos"].ToString();
var audios = session["audios"].ToString();

sb.Append("{");
sb.Append(" \"session\": {");
sb.Append(" \"recipe_id\": \"" + recipe_id + "\",");
sb.Append(" \"content_id\": \"" + content_id + "\",");
sb.Append(" \"content_type\": \"movie\",");
sb.Append(" \"content_src_id_sets\": [");
sb.Append(" {");
sb.Append(" \"content_src_ids\": [");
sb.Append(" {");
sb.Append(" \"src_id_to_mux\": {");
sb.Append(" \"video_src_ids\": ");
sb.Append(" " + videos);
sb.Append(" ,");
sb.Append(" \"audio_src_ids\": ");
sb.Append(" " + audios);
sb.Append(" ");
sb.Append(" }");
sb.Append(" }");
sb.Append(" ]");
sb.Append(" }");
sb.Append(" ],");
sb.Append(" \"timing_constraint\": \"unlimited\",");
sb.Append(" \"keep_method\": {");
sb.Append(" \"heartbeat\": {");
sb.Append(" \"lifetime\": 120000");
sb.Append(" }");
sb.Append(" },");
sb.Append(" \"protocol\": {");
sb.Append(" \"name\": \"http\",");
sb.Append(" \"parameters\": {");
sb.Append(" \"http_parameters\": {");
sb.Append(" \"parameters\": {");
sb.Append(" \"hls_parameters\": {");
sb.Append(" \"use_well_known_port\": \"yes\",");
sb.Append(" \"use_ssl\": \"yes\",");
sb.Append(" \"transfer_preset\": \"\",");
sb.Append(" \"segment_duration\": 6000");
sb.Append(" }");
sb.Append(" }");
sb.Append(" }");
sb.Append(" }");
sb.Append(" },");
sb.Append(" \"content_uri\": \"\",");
sb.Append(" \"session_operation_auth\": {");
sb.Append(" \"session_operation_auth_by_signature\": {");
sb.Append(" \"token\": \"" + token + "\",");
sb.Append(" \"signature\": \"" + signature + "\"");
sb.Append(" }");
sb.Append(" },");
sb.Append(" \"content_auth\": {");
sb.Append(" \"auth_type\": \"ht2\",");
sb.Append(" \"content_key_timeout\": 600000,");
sb.Append(" \"service_id\": \"nicovideo\",");
sb.Append(" \"service_user_id\": \"" + user_id + "\"");
sb.Append(" },");
sb.Append(" \"client_info\": {");
sb.Append(" \"player_id\": \"" + player_id + "\"");
sb.Append(" },");
//sb.Append(" \"priority\": 0.6");
sb.Append(" }");
sb.Append("}");

result = sb.ToString();
}
catch (Exception Ex) //その他のエラー
{
DebugWrite.Writeln(nameof(MakeSession), Ex);
err = Ex.Message;
result = sb.ToString();
return (result, err);
}
return (result, err);
}

//指定フォーマットに基づいて録画サブディレクトリー名を作る
Expand All @@ -109,27 +254,35 @@ public string SetRecFileFormat(string s)
  %TAGn% →(n+1)番めのタグ (半角記号を全角化)
  %tagn% →全角記号を削除した%TAGn%
*/
String result = s;
if (result.Contains("%LOW%"))
String result = s;
try
{
result = result.Replace("%LOW%", ReplaceWords("low_"));
result = result.Replace("%ID%", ReplaceWords(this.VideoId));
result = result.Replace("%id%", "[" + ReplaceWords(this.VideoId)) + "]";
if (result.Contains("%LOW%"))
{
result = result.Replace("%LOW%", ReplaceWords("low_"));
result = result.Replace("%ID%", ReplaceWords(this.VideoId));
result = result.Replace("%id%", "[" + ReplaceWords(this.VideoId)) + "]";
}
else
{
var low = "";
if (this.IsEconomy)
low = "low_";
result = result.Replace("%ID%", ReplaceWords(this.VideoId) + low);
result = result.Replace("%id%", "[" + ReplaceWords(this.VideoId) + "]" + low);
}
result = result.Replace("%TITLE%", ReplaceWords(this.Title));
result = result.Replace("%title%", ReplaceWords(this.Title.Replace(" ", " ")));
//result = result.Replace("%CAT%", ReplaceWords(this.Provider_Id));
//result = result.Replace("%cat%", ReplaceWords(this.Community_Title));
//result = result.Replace("%TAGn%", ReplaceWords(this.Community_Id));
//result = result.Replace("%tagn%", ReplaceWords(this.Title));
}
else
catch (Exception Ex) //その他のエラー
{
var low = "";
if (this.IsEconomy)
low = "low_";
result = result.Replace("%ID%", ReplaceWords(this.VideoId) + low);
result = result.Replace("%id%", "[" + ReplaceWords(this.VideoId) + "]" + low);
DebugWrite.Writeln(nameof(SetRecFileFormat), Ex);
return result;
}
result = result.Replace("%TITLE%", ReplaceWords(this.Title));
result = result.Replace("%title%", ReplaceWords(this.Title.Replace(" ", " ")));
//result = result.Replace("%CAT%", ReplaceWords(this.Provider_Id));
//result = result.Replace("%cat%", ReplaceWords(this.Community_Title));
//result = result.Replace("%TAGn%", ReplaceWords(this.Community_Id));
//result = result.Replace("%tagn%", ReplaceWords(this.Title));

return result;
}
Expand All @@ -154,6 +307,6 @@ private string ReplaceWords(string s)

return result;
}
}

}
}
Loading

0 comments on commit 84bef51

Please sign in to comment.