diff --git a/Sirrene/DataJson.cs b/Sirrene/DataJson.cs index eb1c40c..c04bafd 100644 --- a/Sirrene/DataJson.cs +++ b/Sirrene/DataJson.cs @@ -22,7 +22,6 @@ public class DataJson { public string Status { set; get; } public string Error { set; get; } - public bool IsDms { set; get; } public string VideoId { set; get; } public string Title { set; get; } @@ -43,8 +42,6 @@ public class DataJson public bool IsWatchVideo { set; get; } public string Session_Uri { set; get; } public string Content_Uri { set; get; } - public string Heartbeat_Uri { set; get; } - public string Heartbeat_Data { set; get; } public string AccessRightKey { set; get; } //DMS only public DataJson(string videoid) @@ -52,7 +49,6 @@ public DataJson(string videoid) this.VideoId = videoid; this.Status = null; this.Error = null; - this.IsDms = false; this.IsPremium = false; this.IsPeakTime = false; @@ -65,14 +61,13 @@ public DataJson(string videoid) this.TagList = new List(); this.Session_Uri = null; this.Content_Uri = null; - this.Heartbeat_Uri = null; } + public (bool result, string err) GetDataJson(JObject datajson) { var result = false; var err = ""; - JToken delivery = null; JToken domand = null; try @@ -99,75 +94,22 @@ public DataJson(string videoid) return (result, err); } - this.IsDms = false; if (datajson["media"]["domand"] != null) { if (datajson["media"]["domand"].HasValues) { domand = datajson["media"]["domand"]; this.IsWatchVideo = true; - this.IsDms = true; } else this.IsWatchVideo = false; } - if (!this.IsDms) - { - if (datajson["media"]["delivery"] != null) - { - if (datajson["media"]["delivery"].HasValues) - { - delivery = datajson["media"]["delivery"]; - this.IsWatchVideo = true; - } - else - this.IsWatchVideo = false; - } - else - { - err = "JSON data media domand/delivery not found."; - return (result, err); - } - } this.IsEconomy = this.IsPeakTime; if (this.IsPeakTime) if (this.IsPremium) - { this.IsEconomy = false; - } - else - { - if (IsWatchVideo) - { - if (IsDms) - { - } - else - { - if (delivery["movie"] != null) - { - if ((bool)(delivery["movie"]["audios"][0]["isAvailable"]) && - (bool)(delivery["movie"]["videos"][0]["isAvailable"])) - this.IsEconomy = false; - } - } - - } - } - if (IsWatchVideo) - if (IsDms) - { - } - else - { - if (delivery["encryption"] != null && - delivery["encryption"].HasValues) - { - this.IsEncrypt = true; - this.IsWatchVideo = false; - } - } + if (datajson["video"] != null) { this.Title = (string)datajson["video"]["title"]; @@ -258,148 +200,6 @@ public DataJson(string videoid) return (result, err); } - public (string result, string err) MakeDmcSession(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 lifetime = session["heartbeatLifetime"].ToString(); - var timeout = session["contentKeyTimeout"].ToString(); - var priority = session["priority"].ToString(); - 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(); - this.Session_Uri = session["urls"][0]["url"].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\": " + lifetime); - 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\": " + timeout + ","); - 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\": " + priority); - sb.Append(" }"); - sb.Append("}"); - - result = sb.ToString(); - var obj = JsonConvert.DeserializeObject(result); - result = JsonConvert.SerializeObject(obj, Formatting.None); - } - catch (Exception Ex) //その他のエラー - { - DebugWrite.Writeln(nameof(MakeDmcSession), Ex); - err = Ex.Message; - result = sb.ToString(); - return (result, err); - } - return (result, err); - } - - public (bool result, string err) GetDmcContentUri(JObject session_json) - { - var result = false; - var err = ""; - this.Content_Uri = null; - - try - { - if (session_json["data"] != null) - { - this.Content_Uri = (string)session_json["data"]["session"]["content_uri"]; - this.Heartbeat_Uri = this.Session_Uri + "/" + - (string)session_json["data"]["session"]["id"] + - "?_format=json&_method=PUT"; - var obj = JsonConvert.DeserializeObject(session_json["data"].ToString()); - this.Heartbeat_Data = JsonConvert.SerializeObject(obj, Formatting.None); - - result = true; - } - else - { - err = "content_uri not found."; - } - } - catch (Exception Ex) //その他のエラー - { - DebugWrite.Writeln(nameof(GetDmcContentUri), Ex); - err = Ex.Message; - return (result, err); - } - return (result, err); - } - public (bool result, string err) GetDmsContentUri(JObject session_json) { var result = false; diff --git a/Sirrene/Form1.cs b/Sirrene/Form1.cs index 9da0786..3d37373 100644 --- a/Sirrene/Form1.cs +++ b/Sirrene/Form1.cs @@ -260,23 +260,14 @@ public async void Start_DL() return; } if (djs.IsPremium) - AddLog("Premium Account", 1); - else - AddLog("Normal Account", 1); + AddLog("Premium Account", 1); + else + AddLog("Normal Account", 1); if (djs.IsPeakTime) AddLog("PeakTime(Economy Time)", 1); else AddLog("No PeakTime(Not Econmy Time)", 1); - if (djs.IsDms) - AddLog("新サーバー(DMS)を使用します。", 1); - else - AddLog("旧サーバー(DMC)を使用します。", 1); - if (djs.IsEconomy) - AddLog("エコノミー動画をダウンロードします。", 1); - else - AddLog("通常動画をダウンロードします。", 1); - if (djs.IsEncrypt) - AddLog("暗号化された動画です。", 1); + AddLog("新サーバー(DMS)を使用します。", 1); if (!djs.IsWatchVideo) AddLog("動画がダウンロードできません。", 1); @@ -289,20 +280,11 @@ public async void Start_DL() epi.Sfolder = djs.SetRecFolderFormat(props.SaveFolder); epi.Protocol = "hls"; epi.Seq = 0; - ExecPsInfo.MakeRecDir(epi); + //ExecPsInfo.MakeRecDir(epi); AddLog("Genre: " + djs.Genre, 1); AddLog("TAG(" + djs.TagList.Count + ")" , 1); + epi.SaveFile = ExecPsInfo.GetSaveFileSqlite3(epi) + epi.Ext; - if (props.UseExternal == UseExternal.native) - { - var file = ExecPsInfo.GetSaveFileSqlite3(epi); - file += ".sqlite3"; - epi.SaveFile = file; - _ndb = new NicoDb(this, epi.SaveFile); - _ndb.CreateDbAll(); - - //_ndb.WriteDbKvsProps(djs.Data_Props); - } AddLog("File: "+epi.SaveFile, 9); EnableButton(false); @@ -330,79 +312,40 @@ public async void Start_DL() // Session作成 String session = ""; - if (djs.IsDms) - (session, err) = djs.MakeDmsSession(dataJson); - else - (session, err) = djs.MakeDmcSession(dataJson); + (session, err) = djs.MakeDmsSession(dataJson); if (!string.IsNullOrEmpty(session)) { if (!string.IsNullOrEmpty(err)) { - if (djs.IsDms) - AddLog("MakeDmsSession Error: " + err, 1); - else - AddLog("MakeDmcSession Error: " + err, 1); + AddLog("MakeDmsSession Error: " + err, 1); return; } AddSession(JObject.Parse(session).ToString()); } // SessionをapiにPOST - if (djs.IsDms) + AddLog("Send PostDmsSession", 1); + (sessionJson, err, neterr) = await nvn.PostNicoDmsSessionAsync(cookiecontainer, djs.Session_Uri, session, djs.AccessRightKey); + if (!string.IsNullOrEmpty(err)) { - AddLog("Send PostDmsSession", 1); - (sessionJson, err, neterr) = await nvn.PostNicoDmsSessionAsync(cookiecontainer, djs.Session_Uri, session, djs.AccessRightKey); - if (!string.IsNullOrEmpty(err)) - { - AddLog("Send PostDmsSession Error: " + err + "(" + neterr + ")", 1); - } - else - { - if (sessionJson["meta"] != null) - { - var msg = (string)sessionJson["meta"]["message"] + - "(" + sessionJson["meta"]["status"].ToString() + ")"; - AddLog("Send PostDmsSession " + msg, 9); - } - AddSession("\r\nResponse:\r\n" + sessionJson.ToString()); - (flg, err) = djs.GetDmsContentUri(sessionJson); - if (flg) - { - AddLog("Content_Uri: " + djs.Content_Uri, 9); - } - else - { - AddLog("Content_Uri Error: " + err, 1); - } - } + AddLog("Send PostDmsSession Error: " + err + "(" + neterr + ")", 1); } else { - AddLog("Send PostDmcSession", 1); - (sessionJson, err, neterr) = await nvn.PostNicoDmcSessionAsync(cookiecontainer, djs.Session_Uri + "?_format=json", session); - if (!string.IsNullOrEmpty(err)) + if (sessionJson["meta"] != null) { - AddLog("Send PostDmcSession Error: " + err + "(" + neterr + ")", 1); + var msg = (string)sessionJson["meta"]["message"] + + "(" + sessionJson["meta"]["status"].ToString() + ")"; + AddLog("Send PostDmsSession " + msg, 9); + } + AddSession("\r\nResponse:\r\n" + sessionJson.ToString()); + (flg, err) = djs.GetDmsContentUri(sessionJson); + if (flg) + { + AddLog("Content_Uri: " + djs.Content_Uri, 9); } else { - if (sessionJson["meta"] != null) - { - var msg = (string)sessionJson["meta"]["message"] + - "(" + sessionJson["meta"]["status"].ToString() + ")"; - AddLog("Send PostDmcSession " + msg, 9); - } - AddSession("\r\nResponse:\r\n" + sessionJson.ToString()); - (flg, err) = djs.GetDmcContentUri(sessionJson); - if (flg) - { - AddLog("Content_Uri: " + djs.Content_Uri, 9); - AddLog("Heartbeat_Uri: " + djs.Heartbeat_Uri, 9); - //AddSession("\r\nHeartbeat:\r\n" + djs.Heartbeat_Data); - } - else - { - AddLog("Content_Uri Error: " + err, 1); - } + AddLog("Content_Uri Error: " + err, 1); } } @@ -411,26 +354,23 @@ public async void Start_DL() rti.Count = 3; //DEBUG - if (djs.IsDms) + AddLog("Get NicoMasterDms", 1); + AddSession("\r\nMaster.m3u8:\r\n"); + string data; + (data, err, neterr) = await nvn.GetNicoMasterDmsAsync(cookiecontainer, djs.Content_Uri); + if (!string.IsNullOrEmpty(err)) { - AddLog("Get NicoMasterDms", 1); - AddSession("\r\nMaster.m3u8:\r\n"); - string data; - (data, err, neterr) = await nvn.GetNicoMasterDmsAsync(cookiecontainer, djs.Content_Uri); - if (!string.IsNullOrEmpty(err)) - { - AddLog("GetNicoMasterDmsAsync Error: " + err + "(" + neterr + ")", 1); - } - else - { - AddLog("GetNicoMasterDmsAsync", 1); - } - AddSession(data); - - End_DL(0); - return; + AddLog("GetNicoMasterDmsAsync Error: " + err + "(" + neterr + ")", 1); } + else + { + AddLog("GetNicoMasterDmsAsync", 1); + } + AddSession(data); + End_DL(0); + +/* //動画ダウンロード IsStart_flg = true; IsBreak_flg = false; @@ -491,6 +431,7 @@ public async void Start_DL() End_DL(0); await Task.Run(() => StartExtract(epi.SaveFile)); } + */ return; } // try diff --git a/Sirrene/Net/NicoVideoNet.cs b/Sirrene/Net/NicoVideoNet.cs index 780b497..58576c4 100644 --- a/Sirrene/Net/NicoVideoNet.cs +++ b/Sirrene/Net/NicoVideoNet.cs @@ -469,6 +469,7 @@ public static string GetNicoPageUrl(string videoID) return (data, err, neterr); } + /* public async Task<(string data, string err, int neterr)> GetNicoCrossDomainAsync(CookieContainer cookie, string url) { string data = null; @@ -575,6 +576,7 @@ public static string GetNicoPageUrl(string videoID) return (data, err, neterr); } + */ } } diff --git a/Sirrene/Prop/Version.cs b/Sirrene/Prop/Version.cs index 5d334a3..737ecbc 100644 --- a/Sirrene/Prop/Version.cs +++ b/Sirrene/Prop/Version.cs @@ -4,8 +4,8 @@ namespace Sirrene.Prop { public class Ver { - public static readonly string Version = "0.1.0.08"; - public static readonly string VerDate = "2024/01/27"; + public static readonly string Version = "0.1.0.09"; + public static readonly string VerDate = "2024/05/26"; public static string GetFullVersion() {