mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00
fix: re-enable download manager
This commit is contained in:
parent
7abe2c1073
commit
ea45c4f42a
@ -79,6 +79,17 @@ flutter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
constraints {
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version") {
|
||||||
|
because("kotlin-stdlib-jdk7 is now a part of kotlin-stdlib")
|
||||||
|
}
|
||||||
|
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version") {
|
||||||
|
because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
|
||||||
|
|
||||||
|
// other deps so just ignore
|
||||||
implementation 'com.android.support:multidex:2.0.1'
|
implementation 'com.android.support:multidex:2.0.1'
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
buildscript {
|
buildscript {
|
||||||
ext.kotlin_version = '1.7.21'
|
ext.kotlin_version = '1.8.22'
|
||||||
repositories {
|
repositories {
|
||||||
google()
|
google()
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import 'package:auto_size_text/auto_size_text.dart';
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
|
import 'package:background_downloader/background_downloader.dart';
|
||||||
// import 'package:background_downloader/background_downloader.dart';
|
// import 'package:background_downloader/background_downloader.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
@ -65,14 +66,11 @@ class UserDownloads extends HookConsumerWidget {
|
|||||||
.where((element) => element.taskId == track.id),
|
.where((element) => element.taskId == track.id),
|
||||||
);
|
);
|
||||||
final taskItSelf = useFuture(
|
final taskItSelf = useFuture(
|
||||||
Future.value(null),
|
FileDownloader().database.recordForId(track.id!),
|
||||||
// FileDownloader().database.recordForId(track.id!),
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final hasFailed = failedTaskStream
|
final hasFailed = failedTaskStream.hasData ||
|
||||||
.hasData /* ||
|
taskItSelf.data?.status == TaskStatus.failed;
|
||||||
taskItSelf.data?.status == TaskStatus.failed */
|
|
||||||
;
|
|
||||||
|
|
||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text(track.name ?? ''),
|
title: Text(track.name ?? ''),
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
// import 'package:background_downloader/background_downloader.dart';
|
import 'package:background_downloader/background_downloader.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:http/http.dart';
|
import 'package:http/http.dart';
|
||||||
@ -19,8 +19,8 @@ import 'package:spotube/utils/type_conversion_utils.dart';
|
|||||||
class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
||||||
final Ref ref;
|
final Ref ref;
|
||||||
|
|
||||||
final StreamController /* <TaskProgressUpdate> */ activeDownloadProgress;
|
final StreamController<TaskProgressUpdate> activeDownloadProgress;
|
||||||
final StreamController /* <Task> */ failedDownloads;
|
final StreamController<Task> failedDownloads;
|
||||||
Track? _activeItem;
|
Track? _activeItem;
|
||||||
|
|
||||||
FutureOr<bool> Function(Track)? onFileExists;
|
FutureOr<bool> Function(Track)? onFileExists;
|
||||||
@ -29,78 +29,78 @@ class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
|||||||
: activeDownloadProgress = StreamController.broadcast(),
|
: activeDownloadProgress = StreamController.broadcast(),
|
||||||
failedDownloads = StreamController.broadcast(),
|
failedDownloads = StreamController.broadcast(),
|
||||||
super([]) {
|
super([]) {
|
||||||
// FileDownloader().registerCallbacks(
|
FileDownloader().registerCallbacks(
|
||||||
// group: FileDownloader.defaultGroup,
|
group: FileDownloader.defaultGroup,
|
||||||
// taskNotificationTapCallback: (task, notificationType) {
|
taskNotificationTapCallback: (task, notificationType) {
|
||||||
// router.go("/library");
|
router.go("/library");
|
||||||
// },
|
},
|
||||||
// taskStatusCallback: (update) async {
|
taskStatusCallback: (update) async {
|
||||||
// if (update.status == TaskStatus.running) {
|
if (update.status == TaskStatus.running) {
|
||||||
// _activeItem =
|
_activeItem =
|
||||||
// state.firstWhereOrNull((track) => track.id == update.task.taskId);
|
state.firstWhereOrNull((track) => track.id == update.task.taskId);
|
||||||
// state = state.toList();
|
state = state.toList();
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (update.status == TaskStatus.failed ||
|
if (update.status == TaskStatus.failed ||
|
||||||
// update.status == TaskStatus.notFound) {
|
update.status == TaskStatus.notFound) {
|
||||||
// failedDownloads.add(update.task);
|
failedDownloads.add(update.task);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (update.status == TaskStatus.complete) {
|
if (update.status == TaskStatus.complete) {
|
||||||
// final track =
|
final track =
|
||||||
// state.firstWhere((element) => element.id == update.task.taskId);
|
state.firstWhere((element) => element.id == update.task.taskId);
|
||||||
|
|
||||||
// // resetting the replace downloaded file state on queue completion
|
// resetting the replace downloaded file state on queue completion
|
||||||
// if (state.last == track) {
|
if (state.last == track) {
|
||||||
// ref.read(replaceDownloadedFileState.notifier).state = null;
|
ref.read(replaceDownloadedFileState.notifier).state = null;
|
||||||
// }
|
}
|
||||||
|
|
||||||
// state = state
|
state = state
|
||||||
// .where((element) => element.id != update.task.taskId)
|
.where((element) => element.id != update.task.taskId)
|
||||||
// .toList();
|
.toList();
|
||||||
|
|
||||||
// final imageUri = TypeConversionUtils.image_X_UrlString(
|
final imageUri = TypeConversionUtils.image_X_UrlString(
|
||||||
// track.album?.images ?? [],
|
track.album?.images ?? [],
|
||||||
// placeholder: ImagePlaceholder.online,
|
placeholder: ImagePlaceholder.online,
|
||||||
// );
|
);
|
||||||
// final response = await get(Uri.parse(imageUri));
|
final response = await get(Uri.parse(imageUri));
|
||||||
|
|
||||||
// final tempFile = File(await update.task.filePath());
|
final tempFile = File(await update.task.filePath());
|
||||||
|
|
||||||
// final file = tempFile.copySync(_getPathForTrack(track));
|
final file = tempFile.copySync(_getPathForTrack(track));
|
||||||
|
|
||||||
// await tempFile.delete();
|
await tempFile.delete();
|
||||||
|
|
||||||
// await MetadataGod.writeMetadata(
|
await MetadataGod.writeMetadata(
|
||||||
// file: file.path,
|
file: file.path,
|
||||||
// metadata: Metadata(
|
metadata: Metadata(
|
||||||
// title: track.name,
|
title: track.name,
|
||||||
// artist: track.artists?.map((a) => a.name).join(", "),
|
artist: track.artists?.map((a) => a.name).join(", "),
|
||||||
// album: track.album?.name,
|
album: track.album?.name,
|
||||||
// albumArtist: track.artists?.map((a) => a.name).join(", "),
|
albumArtist: track.artists?.map((a) => a.name).join(", "),
|
||||||
// year: track.album?.releaseDate != null
|
year: track.album?.releaseDate != null
|
||||||
// ? int.tryParse(track.album!.releaseDate!)
|
? int.tryParse(track.album!.releaseDate!)
|
||||||
// : null,
|
: null,
|
||||||
// trackNumber: track.trackNumber,
|
trackNumber: track.trackNumber,
|
||||||
// discNumber: track.discNumber,
|
discNumber: track.discNumber,
|
||||||
// durationMs: track.durationMs?.toDouble(),
|
durationMs: track.durationMs?.toDouble(),
|
||||||
// fileSize: file.lengthSync(),
|
fileSize: file.lengthSync(),
|
||||||
// trackTotal: track.album?.tracks?.length,
|
trackTotal: track.album?.tracks?.length,
|
||||||
// picture: response.headers['content-type'] != null
|
picture: response.headers['content-type'] != null
|
||||||
// ? Picture(
|
? Picture(
|
||||||
// data: response.bodyBytes,
|
data: response.bodyBytes,
|
||||||
// mimeType: response.headers['content-type']!,
|
mimeType: response.headers['content-type']!,
|
||||||
// )
|
)
|
||||||
// : null,
|
: null,
|
||||||
// ),
|
),
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
// },
|
},
|
||||||
// taskProgressCallback: (update) {
|
taskProgressCallback: (update) {
|
||||||
// activeDownloadProgress.add(update);
|
activeDownloadProgress.add(update);
|
||||||
// },
|
},
|
||||||
// );
|
);
|
||||||
// FileDownloader().trackTasks(markDownloadedComplete: true);
|
FileDownloader().trackTasks(markDownloadedComplete: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
UserPreferences get preferences => ref.read(userPreferencesProvider);
|
UserPreferences get preferences => ref.read(userPreferencesProvider);
|
||||||
@ -115,9 +115,9 @@ class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
|||||||
"${track.name} - ${track.artists?.map((a) => a.name).join(", ")}.m4a",
|
"${track.name} - ${track.artists?.map((a) => a.name).join(", ")}.m4a",
|
||||||
);
|
);
|
||||||
|
|
||||||
Future /* <Task> */ _ensureSpotubeTrack(Track track) async {
|
Future<Task> _ensureSpotubeTrack(Track track) async {
|
||||||
if (state.any((element) => element.id == track.id)) {
|
if (state.any((element) => element.id == track.id)) {
|
||||||
final task = null /* await FileDownloader().taskForId(track.id!) */;
|
final task = await FileDownloader().taskForId(track.id!);
|
||||||
if (task != null) {
|
if (task != null) {
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
@ -133,17 +133,16 @@ class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
|||||||
pipedClient,
|
pipedClient,
|
||||||
);
|
);
|
||||||
state = [...state, spotubeTrack];
|
state = [...state, spotubeTrack];
|
||||||
// final task = DownloadTask(
|
final task = DownloadTask(
|
||||||
// url: spotubeTrack.ytUri,
|
url: spotubeTrack.ytUri,
|
||||||
// baseDirectory: BaseDirectory.applicationSupport,
|
baseDirectory: BaseDirectory.applicationSupport,
|
||||||
// taskId: spotubeTrack.id!,
|
taskId: spotubeTrack.id!,
|
||||||
// updates: Updates.statusAndProgress,
|
updates: Updates.statusAndProgress,
|
||||||
// );
|
);
|
||||||
// return task;
|
return task;
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Future /* <Task?> */ enqueue(Track track) async {
|
Future<Task?> enqueue(Track track) async {
|
||||||
final replaceFileGlobal = ref.read(replaceDownloadedFileState);
|
final replaceFileGlobal = ref.read(replaceDownloadedFileState);
|
||||||
final file = File(_getPathForTrack(track));
|
final file = File(_getPathForTrack(track));
|
||||||
if (file.existsSync() &&
|
if (file.existsSync() &&
|
||||||
@ -156,11 +155,11 @@ class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
|||||||
|
|
||||||
final task = await _ensureSpotubeTrack(track);
|
final task = await _ensureSpotubeTrack(track);
|
||||||
|
|
||||||
// await FileDownloader().enqueue(task);
|
await FileDownloader().enqueue(task);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<List /* <Task> */ > enqueueAll(List<Track> tracks) async {
|
Future<List<Task>> enqueueAll(List<Track> tracks) async {
|
||||||
final tasks = await Future.wait(tracks.mapIndexed((i, e) {
|
final tasks = await Future.wait(tracks.mapIndexed((i, e) {
|
||||||
if (i != 0) {
|
if (i != 0) {
|
||||||
/// One second delay between each download to avoid
|
/// One second delay between each download to avoid
|
||||||
@ -174,16 +173,16 @@ class DownloadManagerProvider extends StateNotifier<List<SpotubeTrack>> {
|
|||||||
ref.read(replaceDownloadedFileState.notifier).state = null;
|
ref.read(replaceDownloadedFileState.notifier).state = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return tasks. /* whereType<Task>(). */ toList();
|
return tasks.whereType<Task>().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cancel(Track track) async {
|
Future<void> cancel(Track track) async {
|
||||||
// await FileDownloader().cancelTaskWithId(track.id!);
|
await FileDownloader().cancelTaskWithId(track.id!);
|
||||||
state = state.where((element) => element.id != track.id).toList();
|
state = state.where((element) => element.id != track.id).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> cancelAll() async {
|
Future<void> cancelAll() async {
|
||||||
// (await FileDownloader().reset());
|
(await FileDownloader().reset());
|
||||||
state = [];
|
state = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.0"
|
version: "3.0.0"
|
||||||
|
background_downloader:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: background_downloader
|
||||||
|
sha256: "5e38a1d5d88a5cfea35c44cb376b89427688070518471ee52f6b04d07d85668e"
|
||||||
|
url: "https://pub.dev"
|
||||||
|
source: hosted
|
||||||
|
version: "7.4.0"
|
||||||
badges:
|
badges:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -103,6 +103,7 @@ dependencies:
|
|||||||
media_kit_native_event_loop: ^1.0.4
|
media_kit_native_event_loop: ^1.0.4
|
||||||
dbus: ^0.7.8
|
dbus: ^0.7.8
|
||||||
motion_toast: ^2.6.8
|
motion_toast: ^2.6.8
|
||||||
|
background_downloader: ^7.4.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
build_runner: ^2.3.2
|
build_runner: ^2.3.2
|
||||||
|
Loading…
Reference in New Issue
Block a user