У меня есть ссылка для загрузки файла JSON, например:
http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100.json
в этом файле JSON указаны URL-адреса для загрузки файлов .pkg. файл JSON представляет собой одну строку, закодированную следующим образом:
{"originalFileSize":52797636608,"packageDigest":"034961E6083C51B05AE57146F127BCB36E0DCBFBC9B1DDD427A436F8C0A51BF8","numberOfSplitFiles":13,"pieces":[{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_0.pkg","fileOffset":0,"fileSize":4294967296,"hashValue":"f1eac9118319f5fcdfceccac5eca4c3daa1af700"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_1.pkg","fileOffset":4294967296,"fileSize":4294967296,"hashValue":"f6e06d5c93178a0f665b1a29e65b233cb0ceea3e"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_2.pkg","fileOffset":8589934592,"fileSize":4294967296,"hashValue":"1ebdf355ce74a7e0b8accbdeabbd696c0a44b0b4"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_3.pkg","fileOffset":12884901888,"fileSize":4294967296,"hashValue":"8141d4ad4778991b06bdd50152c2b410449e46e6"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_4.pkg","fileOffset":17179869184,"fileSize":4294967296,"hashValue":"101ec75fc13c9bc4e8f3b715e5b07b7a099da49d"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_5.pkg","fileOffset":21474836480,"fileSize":4294967296,"hashValue":"f2c1aebbdecb2764a3969b985fe2a912b27247ac"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_6.pkg","fileOffset":25769803776,"fileSize":4294967296,"hashValue":"9c0deb38f6af962c185273a7c77aa18c1d6dd6ce"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_7.pkg","fileOffset":30064771072,"fileSize":4294967296,"hashValue":"d60461b730121736e539186930b976b75907b859"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_8.pkg","fileOffset":34359738368,"fileSize":4294967296,"hashValue":"bcd290e8cce92a2b05f6036c236a8f48ed9b4b2f"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_9.pkg","fileOffset":38654705664,"fileSize":4294967296,"hashValue":"349e2868390a987dc40e4e994ce918e12694a8ba"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_10.pkg","fileOffset":42949672960,"fileSize":4294967296,"hashValue":"55df1417e50eb2127f0f7f06d67b70f1349073f4"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_11.pkg","fileOffset":47244640256,"fileSize":4294967296,"hashValue":"d87bbd10fa9b92f1cea37f74c62959bf6c94a53f"},{"url":"http://gs2.ww.prod.dl.playstation.net/gs2/ppkgo/prod/CUSA01788_00/115/f_5bf30bf9b21eec7cbd06a0205f32349bb9e506aa61f89881c02f57d8a4f413c3/f/EP0001-CUSA01788_00-RAINBOWSIXSIEGE0-A0189-V0100_12.pkg","fileOffset":51539607552,"fileSize":1258029056,"hashValue":"5e75d31eed102669c554e950a2252fc26b25e9dd"}]}
Я сделал приложение для извлечения всех URL-адресов внутри этого JSON файла и сохранения их в текстовый файл двумя способами
Способ 1 с использованием JSON Parse: (он работает хорошо, но проблема в том, что файл TXT полон повторяющихся / повторяющихся много раз URL-адресов, и все URL-адреса отсутствуют !!!)
public class Piece
{
public string url { get; set; }
public object fileOffset { get; set; }
public object fileSize { get; set; }
public string hashValue { get; set; }
}
public class Root
{
public long originalFileSize { get; set; }
public string packageDigest { get; set; }
public int numberOfSplitFiles { get; set; }
public List<Piece> pieces { get; set; }
}
private void button1_Click(object sender, EventArgs e)
{
Uri uri = new Uri(tb_psn.Text);
var converted = uri.GetLeftPart(UriPartial.Path);
var jpaths = Application.StartupPath + @"\DataFiles\downloadall.json";
var tpaths = Application.StartupPath + @"\DataFiles\downloadall.txt";
var streamWriter = new StreamWriter(tpaths);
string[] urlEndings = { "_0.pkg", "_1.pkg", "_2.pkg", "_3.pkg", "_4.pkg", "_5.pkg", "_6.pkg", "_7.pkg", "_8.pkg", "_9.pkg", "-V0100_0.pkg", "-V0100_1.pkg", "-V0100_2.pkg", "-V0100_3.pkg", "-V0100_4.pkg", "-V0100_5.pkg", "-V0100_6.pkg", "-V0100_7.pkg", "-V0100_8.pkg", "-V0100_9.pkg" };
if (urlEndings.Any(x => converted.EndsWith(x)))
{
converted = converted.Substring(0, converted.Length - 6);
Clipboard.SetDataObject(converted + ".json");
string six = converted + ".json";
System.Net.WebClient client = new System.Net.WebClient();
String json = client.DownloadString(six);
File.WriteAllText(jpaths, json);
dynamic jsonObject = JObject.Parse(File.ReadAllText(jpaths));
JArray files = jsonObject.pieces;
StringBuilder sb = new StringBuilder();
foreach (dynamic file in files)
{
string url = file.url;
sb.AppendLine(url);
streamWriter.Write(sb.ToString());
}
ShowCopySuccess((MouseEventArgs)e);
}
else { bye bye}
Way 2 с использованием DEGEX: (результат лучше, чем способ 1, но файл TXT не завершен! Все URL-адреса не находятся в файле TXT !! Почему?)
Обновление: способ 2 исправлен решение : мы должны закрыть StreamWriter после записи строки !!
private void button1_Click(object sender, EventArgs e)
{
Uri uri = new Uri(tb_psn.Text);
var converted = uri.GetLeftPart(UriPartial.Path);
var jpaths = Application.StartupPath + @"\DataFiles\downloadall.json";
var tpaths = Application.StartupPath + @"\DataFiles\downloadall.txt";
var streamWriter = new StreamWriter(tpaths);
string[] urlEndings = { "_0.pkg", "_1.pkg", "_2.pkg", "_3.pkg", "_4.pkg", "_5.pkg", "_6.pkg", "_7.pkg", "_8.pkg", "_9.pkg", "-V0100_0.pkg", "-V0100_1.pkg", "-V0100_2.pkg", "-V0100_3.pkg", "-V0100_4.pkg", "-V0100_5.pkg", "-V0100_6.pkg", "-V0100_7.pkg", "-V0100_8.pkg", "-V0100_9.pkg" };
if (urlEndings.Any(x => converted.EndsWith(x)))
{
converted = converted.Substring(0, converted.Length - 6);
Clipboard.SetDataObject(converted + ".json");
string six = converted + ".json";
System.Net.WebClient client = new System.Net.WebClient();
String json = client.DownloadString(six);
File.WriteAllText(jpaths, json);
string rdj = File.ReadAllText(jpaths);
foreach (Match item in Regex.Matches(rdj, @"(http|ftp|https):\/\/([\w\-_]+(?:(?:\.[\w\-_]+)+))([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?"))
{
streamWriter.WriteLine(item.Value.ToString());
}
// Here we have to close streamWriter
streamWriter.Close();
ShowCopySuccess((MouseEventArgs)e);
}
else { bye bye}
пожалуйста, дайте мне знать, в чем мой неправильный код. Спасибо за вашу помощь Извините за мой плохой английский sh