Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

订阅 #12

Merged
merged 3 commits into from
Jul 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions AdnmbBackup-gui/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ private void button1_Click(object sender, EventArgs e)
catch (Exception ex)
{
MessageBox.Show(ex.Message);
// log the error
var err = new List<string>();
err.Add("[" + DateTime.Now.ToString() + "] 串 " + id + " 备份失败,错误信息:" + ex.Message);
err.Add(" ");
File.AppendAllLines("error.log", err);
return;
}
ConvertToText(id);
Expand Down Expand Up @@ -431,6 +436,81 @@ static string ReadGzip(byte[] bytes)
}
private void Form1_Shown(object sender, EventArgs e)
{
if (File.Exists("uuid.txt"))
{
// read uuid
var uuid = File.ReadAllText("uuid.txt");
// get cookie
if (!File.Exists("cookie.txt"))
{
MessageBox.Show("请先放好小饼干");
return;
}
int errCount = 0;
var err = new List<string>();
var cookie = File.ReadAllText("cookie.txt");
HashSet<string> ids; // Store the ids.
if (File.Exists("AutoBackupList.txt"))
{
// Read the existing ids if the file already exists.
ids = new HashSet<string>(File.ReadAllLines("AutoBackupList.txt"));
}
else
{
// Otherwise, initialize a new HashSet.
ids = new HashSet<string>();
}
int pageNo = 1;

// get ids via api
while (true) // We will break out of the loop when we get an empty response.
{
string feedurl = String.Format("https://api.nmb.best/Api/feed?uuid={0}&page={1}", uuid, pageNo);
label4.Text = "正在获取订阅串列表,第" + pageNo + "页,url:";
CookieContainer cookieContainer = new CookieContainer();
cookieContainer.Add(new Cookie("userhash", cookie, "/", "api.nmb.best"));
HttpClientHandler handler = new HttpClientHandler() { UseCookies = true };
handler.CookieContainer = cookieContainer;
HttpClient http = new HttpClient(handler);
http.DefaultRequestHeaders.Add("Host", "api.nmb.best");
http.DefaultRequestHeaders.Add("Accept", "application/json");
http.DefaultRequestHeaders.Add("Accept-Encoding", "gzip");
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.0.0 Safari/537.36"); // todo: change to the App UA with github link
label4.Text = "正在获取订阅串列表,第" + pageNo + "页";
var t = http.GetAsync(feedurl);
t.Wait();
var result = t.Result;
var t2 = result.Content.ReadAsByteArrayAsync();
t2.Wait();
var bytes = t2.Result;
string str = null;
try {

str = ReadGzip(bytes);
// If response is empty (i.e., "[]"), break out of the loop.
if (str == "[]") break;
// or length is smaller than 10
if (str.Length < 10) break;

var jArray = JArray.Parse(str);
foreach (var item in jArray)
{
var id = item["id"].ToString();
ids.Add(id); // If 'id' already exists, HashSet will automatically ignore it.
label4.Text = "正在获取订阅串列表,第" + pageNo + "页,已获取" + ids.Count + "个订阅串";
}

pageNo += 1;
}
catch (Exception) {
label4.Text = "获取订阅串列表时出错"; errCount++;
err.Add("获取订阅串列表时出错"); err.Add(" ");
break;
}
}
// write ids to file
File.WriteAllLines("AutoBackupList.txt", ids);
}
if (File.Exists("AutoBackupList.txt"))
{
if (!File.Exists("cookie.txt"))
Expand Down Expand Up @@ -610,6 +690,7 @@ private void Form1_Shown(object sender, EventArgs e)
}
else { label4.Text = "自动备份已完成,可在上方手动输入串号继续进行备份"; }
}

}
}
}
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
# AdnmbBackup-gui

一个让你本地备份A岛串的小程序。

已完美适配X岛
[饼干获取教程](https://www.coldthunder11.com/index.php/2020/03/19/%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96a%e5%b2%9b%e7%9a%84%e9%a5%bc%e5%b9%b2/)
支持批量自动备份,在程序目录下新建AtuobBackupList.txt将需要自动备份的串号填入(一行一个),每天第一次打开会自动备份

备份需要获取饼干,这里是[饼干获取教程](https://www.coldthunder11.com/index.php/2020/03/19/%e5%a6%82%e4%bd%95%e8%8e%b7%e5%8f%96a%e5%b2%9b%e7%9a%84%e9%a5%bc%e5%b9%b2/)

支持批量自动备份,方法如下:

1. 在程序目录下新建`uuid.txt`,写入移动端订阅id,每次打开会自动将所有订阅的串号加入自动备份列表
2. 在程序目录下新建`AutoBackupList.txt`,可以手动加入其他需要备份的串号填入(一行一个)

每天第一次打开会自动备份所有在`AutoBackupList.txt`中的串,备份文件在`output`文件夹中。

需要 .net framework4.8。
json文件为完整数据文件,txt为易读的文件

json文件为完整数据文件,txt为易读的文件,md为markdown格式的文件包含图片及部分格式。

目前文件结构:

```
``` bash
├─AdnmbBackup-gui
│ ├─po
│ │ ├─*.txt // 内容将覆盖po的饼干。可多行,一行一个
Expand All @@ -26,7 +37,6 @@ json文件为完整数据文件,txt为易读的文件
| | ├─*_po_only.txt // po的内容的txt文件
| | ├─*_po_only.md // po的内容的md文件
| ├─AdnmbBackup-gui.exe
| ├─AdnmbBackup-gui.exe.config
│ ├─cookie.txt // 饼干
│ ├─Newtonsoft.Json.dll
│ ├─Newtonsoft.Json.xml
Expand All @@ -39,9 +49,9 @@ TODO:
- [ ] 串号从剪贴板获取
- [ ] 任务计划自动备份(或教程)
- [ ] Cookie获取教程
- [ ] 方便的加入自动备份列表
- [x] 方便的加入自动备份列表
- [ ] 方便的更改po
- [ ] 文件名系统
- [x] markdown格式备份支持
- [x] markdown中插入图片
- [x] 重命名文件
- [x] 重命名文件
Loading