Skip to content

Commit

Permalink
RecHtml()が動作するように修正
Browse files Browse the repository at this point in the history
NicoVideoNet()のヘッダー部修正
Start_DL() End_DL()に修正
  • Loading branch information
nnn-revo2012 committed Jul 2, 2023
1 parent 5e41bd0 commit e011ae0
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 168 deletions.
77 changes: 37 additions & 40 deletions Sirrene/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public partial class Form1 : Form

private static bool IsBatchMode { get; set; } //引数指定で実行か?
//0処理待ち 1録画準備 2録画中 3再接続 4中断 5変換処理中 9終了
private volatile bool start_flg = false;
private static int ProgramStatus { get; set; } //プログラム状態
private volatile bool start_flg = false;

//dispose するもの
private ExecProcess _eProcess = null; //Process
Expand Down Expand Up @@ -81,21 +81,7 @@ private void Button1_Click(object sender, EventArgs e)
//中断処理
if (button1.Text == "ABORT")
{
if (_rHtml != null)
{
_rHtml.BreakProcess("");
}
if (_eProcess != null)
{
_eProcess.BreakProcess(epi.BreakKey);
}
if (_ndb != null)
{
_ndb.Dispose();
}
AddLog("中断しました。", 1);
EnableButton(true);
start_flg = false;
End_DL(1);
return;
}

Expand Down Expand Up @@ -163,15 +149,15 @@ private void Button1_Click(object sender, EventArgs e)
return;
#endif
//録画開始
Task.Run(() => StartRec());
Task.Run(() => Start_DL());

}
catch (Exception Ex)
{
AddLog(nameof(Button1_Click) + "() Error: \r\n" + Ex.Message, 2);
}
}
public async void StartRec()
public async void Start_DL()
{
cookiecontainer = null;
try
Expand Down Expand Up @@ -336,21 +322,7 @@ public async void StartRec()

if (!djs.IsWatchVideo)
{
if (_rHtml != null)
{
_rHtml.BreakProcess("");
}
if (_eProcess != null)
{
_eProcess.BreakProcess(epi.BreakKey);
}
if (_ndb != null)
{
_ndb.Dispose();
}
AddLog("ダウンロード終了しました。", 1);
EnableButton(true);
start_flg = false;
End_DL(0);
return;
}

Expand Down Expand Up @@ -427,10 +399,18 @@ public async void StartRec()
}


//if (props.UseExternal == UseExternal.native)
// _rHtml = new RecHtml(this, djs, cookiecontainer, _ndb, rti);
//else
// _eProcess = new ExecProcess(this, djs, rti);
if (props.UseExternal == UseExternal.native)
{
_rHtml = new RecHtml(this, djs, cookiecontainer, _ndb, rti);
_rHtml.ExecPs(djs.Content_Uri, "");
}
else
{
_eProcess = new ExecProcess(this, djs, rti);
var argument = ExecPsInfo.SetOption(epi, djs.Content_Uri, 0);
//_eProcess.ExecPs(_epi.Exec, argument);
_eProcess.ExecPs(epi.Exec, argument);
}

//放送情報を表示
//DispHosoData(bci);
Expand All @@ -443,6 +423,20 @@ public async void StartRec()
await Task.Delay(5000);
start_flg = false;
}
End_DL(0);

return;
} // try
catch (Exception Ex)
{
AddLog(nameof(Start_DL) + "() Error: \r\n" + Ex.Message, 2);
}
}

public void End_DL(int flag)
{
try
{
if (_rHtml != null)
{
_rHtml.BreakProcess("");
Expand All @@ -455,15 +449,18 @@ public async void StartRec()
{
_ndb.Dispose();
}
AddLog("ダウンロード終了しました。", 1);
if (flag == 1)
AddLog("ダウンロード中断しました。", 1);
else
AddLog("ダウンロード終了しました。", 1);
EnableButton(true);
start_flg = false;
return;

return;
} // try
catch (Exception Ex)
{
AddLog(nameof(StartRec) + "() Error: \r\n" + Ex.Message, 2);
AddLog(nameof(End_DL) + "() Error: \r\n" + Ex.Message, 2);
}
}

Expand Down
24 changes: 5 additions & 19 deletions Sirrene/Net/NicoVideoNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public NicoVideoNet()

_wc.Encoding = Encoding.UTF8;
_wc.Proxy = null;
_wc.Headers.Add(HttpRequestHeader.ContentType, "text/html; charset=UTF-8");
_wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");
_wc.Headers.Add(HttpRequestHeader.UserAgent, Props.UserAgent);
_wc.timeout = 30000;
}
Expand Down Expand Up @@ -142,10 +145,6 @@ public static string GetNicoPageUrl(string videoID)
ps.Add("mail_tel", mail);
ps.Add("password", pass);

_wc.Headers.Add(HttpRequestHeader.ContentType, "text/html; charset=UTF-8");
_wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");

byte[] resArray = await _wc.UploadValuesTaskAsync(Props.NicoLoginUrl, ps).Timeout(_wc.timeout);
var data = System.Text.Encoding.UTF8.GetString(resArray);
flag = Regex.IsMatch(data, "user\\.login_status += +\\'login\\'", RegexOptions.Compiled) ? true : false;
Expand Down Expand Up @@ -198,10 +197,6 @@ public static string GetNicoPageUrl(string videoID)

try
{
_wc.Headers.Add(HttpRequestHeader.ContentType, "text/html; charset=UTF-8");
_wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");

var hs = await _wc.DownloadStringTaskAsync(Props.NicoDomain).Timeout(_wc.timeout);
flag = Regex.IsMatch(hs, "user\\.login_status += +\\'login\\'", RegexOptions.Compiled) ? true : false;
}
Expand Down Expand Up @@ -238,10 +233,6 @@ public static string GetNicoPageUrl(string videoID)
var nicoid = GetVideoID(nicoUrl);
if (string.IsNullOrEmpty(nicoid)) return (data, "null", neterr);

_wc.Headers.Add(HttpRequestHeader.ContentType, "text/html; charset=UTF-8");
_wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");

var hs = await _wc.DownloadStringTaskAsync(Props.NicoVideoUrl + nicoid).Timeout(_wc.timeout);
if (string.IsNullOrEmpty(hs)) return (data, "null", neterr);
var ttt = WebUtility.HtmlDecode(Regex.Match(hs, "data-api-data=\"([^\"]*)\"", RegexOptions.Compiled).Groups[1].Value);
Expand Down Expand Up @@ -285,10 +276,6 @@ public static string GetNicoPageUrl(string videoID)
{
if (string.IsNullOrEmpty(url)) return (data, "null", neterr);

_wc.Headers.Add(HttpRequestHeader.ContentType, "text/html; charset=UTF-8");
_wc.Headers.Add(HttpRequestHeader.Accept, "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");

int index = url.IndexOf("/", "https://".Length);
var host_url = url.Substring(0, index);
data = await _wc.DownloadStringTaskAsync(host_url).Timeout(_wc.timeout);
Expand Down Expand Up @@ -329,9 +316,8 @@ public static string GetNicoPageUrl(string videoID)

_wc.Headers.Add(HttpRequestHeader.ContentType, "application/json");
_wc.Headers.Add(HttpRequestHeader.Accept, "application/json");
_wc.Headers.Add(HttpRequestHeader.AcceptLanguage, "ja,en-US;q=0.9,en;q=0.8");
_wc.Headers.Add("Origin", "https://www.nicovideo.jp");
_wc.Headers.Add(HttpRequestHeader.Referer, "https://www.nicovideo.jp/");
_wc.Headers.Add("Origin", Props.NicoOrigin);
_wc.Headers.Add(HttpRequestHeader.Referer, Props.NicoDomain);

var result = await _wc.UploadStringTaskAsync(url, "POST", senddata).Timeout(_wc.timeout);
if (string.IsNullOrEmpty(result)) return (data, "result is null", neterr);
Expand Down
1 change: 1 addition & 0 deletions Sirrene/Process/AExecProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public abstract class AEexecProcess
public volatile int PsStatus = -1; //実行ファイルの状態

protected NicoDb _ndb = null;
protected DataJson _djs = null;
protected RetryInfo _ri = null;
protected Form1 _form = null;

Expand Down
13 changes: 2 additions & 11 deletions Sirrene/Process/ExecProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ public class ExecProcess : AEexecProcess, IDisposable
//Debug
public bool IsDebug { get; set; }

public ExecProcess(Form1 fo, RetryInfo ri)
public ExecProcess(Form1 fo, DataJson djs, RetryInfo ri)
{
IsDebug = false;

PsStatus = -1;
this._djs = djs;
this._ri = ri;
this._form = fo;
}
Expand Down Expand Up @@ -81,10 +82,6 @@ public override void ExecPs(string exefile, string argument)
PsStatus = 0; //実行中
//EnableButton(false);

if (Form1.props.IsComment)
{

}
if (Form1.props.IsVideo)
{
_ps.BeginOutputReadLine();
Expand Down Expand Up @@ -147,12 +144,6 @@ private void ExitedPs(object sender, EventArgs e)
_ps.Dispose();
_ps = null;
}

//生放送の場合プロセスが終了したらコメントサーバーを切断する。
if (Form1.props.IsComment)
{

}
}
catch (Exception Ex)
{
Expand Down
26 changes: 2 additions & 24 deletions Sirrene/Prop/Props.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,13 @@ public class Props
public static readonly string NicoDomain = "https://www.nicovideo.jp/";

public static readonly string NicoVideoUrl = NicoDomain + "watch/";
public static readonly string NicoOrigin = NicoDomain;
public static readonly string NicoOrigin = "https://www.nicovideo.jp";
public static readonly string NicoUserUrl = "https://www.nicovideo.jp/user/";

//public static readonly string NicoLoginUrl = "https://secure.nicovideo.jp/secure/login?site=niconico";
public static readonly string NicoLoginUrl = "https://account.nicovideo.jp/login/redirector?show_button_twitter=1&site=niconico&show_button_facebook=1&next_url=%2F";

public static readonly string[] Quality =
{ "1080p", "720p", "480p", "360p", "低画質", };

public static readonly string[][] ReplaceWords =
{
new[] {"?PID?","lv1234567","ProgramId。lv1234567のような文字列。"},
new[] {"?UNAME?","ユーザ名","ユーザ名。公式の場合、official"},
new[] {"?UID?","ユーザID","ユーザID。nicovideo.jp/user/に続く数字の列。公式の場合、official"},
new[] {"?CNAME?","コミュニティ名","コミュニティ名。公式の場合、official"},
new[] {"?CID?","コミュニティID","コミュニティID。co1234のような文字列。公式の場合、official"},
new[] {"?TITLE?","放送タイトル","放送タイトル。"},
new[] {"?YEAR?","2019","年4桁(開演時刻)"},
new[] {"?MONTH?","09","月2桁(開演時刻)"},
new[] {"?DAY?","01","日2桁(開演時刻)"},
new[] {"?DAY8?","20190901","年4桁,月2桁,日2桁"},
new[] {"?DAY6?","190901","年2桁,月2桁,日2桁"},
new[] {"?HOUR?","18","時2桁"},
new[] {"?MINUTE?","31","分2桁"},
new[] {"?SECOND?","02","秒2桁"},
new[] {"?TIME6?","183102","時2桁,分2桁,秒2桁"},
new[] {"?TIME4?","3102","時2桁,分2桁"}
//new[] {"", "",""}
};
{ "1080p", "720p", "480p", "360p", "低画質", };

public static readonly IDictionary<string, string> PropLists =
new Dictionary<string, string>()
Expand Down
Loading

0 comments on commit e011ae0

Please sign in to comment.