mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2026-02-16 22:39:34 +00:00
123
This commit is contained in:
parent
6ffd76a194
commit
b0f5dd8951
18 changed files with 441 additions and 64 deletions
|
|
@ -22,6 +22,7 @@ class AudiobookDownloadManager {
|
|||
this.requiresWiFi = true,
|
||||
this.retries = 0,
|
||||
this.allowPause = false,
|
||||
this.path = '',
|
||||
|
||||
// /// The maximum number of concurrent tasks to run at any given time.
|
||||
// int maxConcurrent = 3,
|
||||
|
|
@ -60,6 +61,9 @@ class AudiobookDownloadManager {
|
|||
// whether to allow pausing of downloads
|
||||
final bool allowPause;
|
||||
|
||||
// 下载目录
|
||||
final String path;
|
||||
|
||||
final StreamController<TaskUpdate> _taskStatusController =
|
||||
StreamController.broadcast();
|
||||
|
||||
|
|
@ -68,11 +72,16 @@ class AudiobookDownloadManager {
|
|||
late StreamSubscription<TaskUpdate> _updatesSubscription;
|
||||
|
||||
Future<void> queueAudioBookDownload(
|
||||
LibraryItemExpanded item,
|
||||
) async {
|
||||
LibraryItemExpanded item, {
|
||||
String prePath = '',
|
||||
}) async {
|
||||
_logger.info('queuing download for item: ${item.id}');
|
||||
// create a download task for each file in the item
|
||||
for (final file in item.libraryFiles) {
|
||||
// 仅下载音频和视频
|
||||
if (![FileType.audio, FileType.video].contains(file.fileType)) {
|
||||
continue;
|
||||
}
|
||||
// check if the file is already downloaded
|
||||
if (isFileDownloaded(
|
||||
constructFilePath(item, file),
|
||||
|
|
@ -84,7 +93,7 @@ class AudiobookDownloadManager {
|
|||
final task = DownloadTask(
|
||||
taskId: file.ino,
|
||||
url: file.url(baseUrl, item.id, token).toString(),
|
||||
directory: item.relPath,
|
||||
directory: prePath + item.relPath,
|
||||
filename: file.metadata.filename,
|
||||
requiresWiFi: requiresWiFi,
|
||||
retries: retries,
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:background_downloader/background_downloader.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
|
|
@ -26,6 +28,7 @@ class SimpleDownloadManager extends _$SimpleDownloadManager {
|
|||
requiresWiFi: downloadSettings.requiresWiFi,
|
||||
retries: downloadSettings.retries,
|
||||
allowPause: downloadSettings.allowPause,
|
||||
path: downloadSettings.path,
|
||||
);
|
||||
core.tq.maxConcurrent = downloadSettings.maxConcurrent;
|
||||
core.tq.maxConcurrentByHost = downloadSettings.maxConcurrentByHost;
|
||||
|
|
@ -56,6 +59,8 @@ class DownloadManager extends _$DownloadManager {
|
|||
LibraryItemExpanded item,
|
||||
) async {
|
||||
_logger.fine('queueing download for ${item.id}');
|
||||
// final appSettings = ref.read(appSettingsProvider);
|
||||
|
||||
await state.queueAudioBookDownload(
|
||||
item,
|
||||
);
|
||||
|
|
@ -66,6 +71,24 @@ class DownloadManager extends _$DownloadManager {
|
|||
await state.deleteDownloadedItem(item);
|
||||
ref.notifyListeners();
|
||||
}
|
||||
|
||||
String _getDirectory(String path) {
|
||||
if (Platform.isWindows) {
|
||||
return path;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
BaseDirectory _getBaseDirectory() {
|
||||
if (Platform.isIOS) {
|
||||
return BaseDirectory.applicationDocuments;
|
||||
} else if (Platform.isAndroid) {
|
||||
return BaseDirectory.temporary;
|
||||
} else if (Platform.isWindows) {
|
||||
return BaseDirectory.root;
|
||||
}
|
||||
return BaseDirectory.applicationSupport;
|
||||
}
|
||||
}
|
||||
|
||||
@riverpod
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ class _DownloadHistoryProviderElement
|
|||
}
|
||||
|
||||
String _$simpleDownloadManagerHash() =>
|
||||
r'8ab13f06ec5f2f73b73064bd285813dc890b7f36';
|
||||
r'da5798e4becce751db80c41b93a48217418e4648';
|
||||
|
||||
/// See also [SimpleDownloadManager].
|
||||
@ProviderFor(SimpleDownloadManager)
|
||||
|
|
@ -176,7 +176,7 @@ final simpleDownloadManagerProvider = NotifierProvider<SimpleDownloadManager,
|
|||
);
|
||||
|
||||
typedef _$SimpleDownloadManager = Notifier<core.AudiobookDownloadManager>;
|
||||
String _$downloadManagerHash() => r'852012e32e613f86445afc7f7e4e85bec808e982';
|
||||
String _$downloadManagerHash() => r'92afe484d6735d5de53473011ea9ecbad107fc1c';
|
||||
|
||||
/// See also [DownloadManager].
|
||||
@ProviderFor(DownloadManager)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue