Skip to content

Commit a95c895

Browse files
committed
refactor ytdlp-resolver
1 parent c46e475 commit a95c895

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Packages/idv.jlchntoz.vvmw/Editor/Common/YtdlpResolver.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ public static async UniTask<List<YtdlpPlayListEntry>> GetPlayLists(string url) {
9494
await DownLoadYtDlpIfNotExists();
9595
if (!HasYtDlp()) return new List<YtdlpPlayListEntry>();
9696
var text = EditorI18N.Instance["YTDLPResolver.get_playlists"];
97-
using var progress = new CancellableProgressBar(text, text);
97+
using var progress = new CancelableProgressBar(text, text);
9898
return await Fetch(url, progress);
9999
}
100100

101101
public static async UniTask FetchTitles(YtdlpPlayListEntry[] entries) {
102102
await DownLoadYtDlpIfNotExists();
103103
if (!HasYtDlp()) return;
104104
var text = EditorI18N.Instance["YTDLPResolver.get_titles"];
105-
using var progress = new CancellableProgressBar(text, text);
105+
using var progress = new CancelableProgressBar(text, text);
106106
var token = progress.CancelToken;
107107
if (token.IsCancellationRequested) return;
108108
for (int i = 0; i < entries.Length; i++) {
@@ -120,7 +120,7 @@ public static async UniTask FetchTitles(YtdlpPlayListEntry[] entries) {
120120
}
121121
}
122122

123-
static async UniTask<List<YtdlpPlayListEntry>> Fetch(string url, CancellableProgressBar progress, float startProgress = 0F, float endProgress = 1F) {
123+
static async UniTask<List<YtdlpPlayListEntry>> Fetch(string url, CancelableProgressBar progress, float startProgress = 0F, float endProgress = 1F) {
124124
var cancelToken = progress.CancelToken;
125125
var orgInfo = progress.Info;
126126
var results = new List<YtdlpPlayListEntry>();
@@ -163,31 +163,30 @@ public struct YtdlpPlayListEntry {
163163
public string url;
164164
}
165165

166-
class CancellableProgressBar : IDisposable, IProgress<float> {
166+
class CancelableProgressBar : IDisposable, IProgress<float> {
167167
readonly CancellationTokenSource cts;
168-
string title;
169-
string info;
168+
string title, info;
170169
float progress;
171170

172171
public string Title {
173172
get => title;
174173
set {
175174
title = value;
176-
Report(progress);
175+
Report();
177176
}
178177
}
179178

180179
public string Info {
181180
get => info;
182181
set {
183182
info = value;
184-
Report(progress);
183+
Report();
185184
}
186185
}
187186

188187
public CancellationToken CancelToken => cts.Token;
189188

190-
public CancellableProgressBar(string title, string info, float initialProgress = 0) {
189+
public CancelableProgressBar(string title, string info, float initialProgress = 0) {
191190
cts = new CancellationTokenSource();
192191
this.title = title;
193192
this.info = info;
@@ -196,7 +195,11 @@ public CancellableProgressBar(string title, string info, float initialProgress =
196195

197196
public void Report(float value) {
198197
progress = value;
199-
if (EditorUtility.DisplayCancelableProgressBar(title, info, value))
198+
Report();
199+
}
200+
201+
void Report() {
202+
if (EditorUtility.DisplayCancelableProgressBar(title, info, progress))
200203
cts.Cancel();
201204
}
202205

0 commit comments

Comments
 (0)