mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-08 16:27:31 +00:00
feat: always uses piped api for download to avoid IP block
This commit is contained in:
parent
27fcedc252
commit
869d063023
@ -33,6 +33,7 @@ class DownloadManagerProvider extends ChangeNotifier {
|
|||||||
// related to onFileExists
|
// related to onFileExists
|
||||||
final oldFile = File("$savePath.old");
|
final oldFile = File("$savePath.old");
|
||||||
|
|
||||||
|
// if download failed and old file exists, rename it back
|
||||||
if ((status == DownloadStatus.failed ||
|
if ((status == DownloadStatus.failed ||
|
||||||
status == DownloadStatus.canceled) &&
|
status == DownloadStatus.canceled) &&
|
||||||
await oldFile.exists()) {
|
await oldFile.exists()) {
|
||||||
@ -84,7 +85,7 @@ class DownloadManagerProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
final Ref<DownloadManagerProvider> ref;
|
final Ref<DownloadManagerProvider> ref;
|
||||||
|
|
||||||
YoutubeEndpoints get yt => ref.read(youtubeProvider);
|
YoutubeEndpoints get yt => ref.read(downloadYoutubeProvider);
|
||||||
String get downloadDirectory =>
|
String get downloadDirectory =>
|
||||||
ref.read(userPreferencesProvider.select((s) => s.downloadLocation));
|
ref.read(userPreferencesProvider.select((s) => s.downloadLocation));
|
||||||
|
|
||||||
@ -196,7 +197,7 @@ class DownloadManagerProvider extends ChangeNotifier {
|
|||||||
await addToQueue(track);
|
await addToQueue(track);
|
||||||
} else {
|
} else {
|
||||||
await Future.delayed(
|
await Future.delayed(
|
||||||
const Duration(seconds: 5),
|
const Duration(seconds: 1),
|
||||||
() => addToQueue(track),
|
() => addToQueue(track),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -230,6 +231,7 @@ class DownloadManagerProvider extends ChangeNotifier {
|
|||||||
|
|
||||||
void cancelAll() {
|
void cancelAll() {
|
||||||
for (final download in dl.getAllDownloads()) {
|
for (final download in dl.getAllDownloads()) {
|
||||||
|
if (download.status.value == DownloadStatus.completed) continue;
|
||||||
dl.cancelDownload(download.request.url);
|
dl.cancelDownload(download.request.url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -281,6 +281,45 @@ class UserPreferences extends PersistedChangeNotifier {
|
|||||||
"youtubeApiType": youtubeApiType.name,
|
"youtubeApiType": youtubeApiType.name,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UserPreferences copyWith({
|
||||||
|
ThemeMode? themeMode,
|
||||||
|
SpotubeColor? accentColorScheme,
|
||||||
|
bool? albumColorSync,
|
||||||
|
bool? checkUpdate,
|
||||||
|
AudioQuality? audioQuality,
|
||||||
|
String? downloadLocation,
|
||||||
|
LayoutMode? layoutMode,
|
||||||
|
CloseBehavior? closeBehavior,
|
||||||
|
bool? showSystemTrayIcon,
|
||||||
|
Locale? locale,
|
||||||
|
String? pipedInstance,
|
||||||
|
SearchMode? searchMode,
|
||||||
|
bool? skipNonMusic,
|
||||||
|
YoutubeApiType? youtubeApiType,
|
||||||
|
String? recommendationMarket,
|
||||||
|
bool? saveTrackLyrics,
|
||||||
|
}) {
|
||||||
|
return UserPreferences(
|
||||||
|
ref,
|
||||||
|
themeMode: themeMode ?? this.themeMode,
|
||||||
|
accentColorScheme: accentColorScheme ?? this.accentColorScheme,
|
||||||
|
albumColorSync: albumColorSync ?? this.albumColorSync,
|
||||||
|
checkUpdate: checkUpdate ?? this.checkUpdate,
|
||||||
|
audioQuality: audioQuality ?? this.audioQuality,
|
||||||
|
downloadLocation: downloadLocation ?? this.downloadLocation,
|
||||||
|
layoutMode: layoutMode ?? this.layoutMode,
|
||||||
|
closeBehavior: closeBehavior ?? this.closeBehavior,
|
||||||
|
showSystemTrayIcon: showSystemTrayIcon ?? this.showSystemTrayIcon,
|
||||||
|
locale: locale ?? this.locale,
|
||||||
|
pipedInstance: pipedInstance ?? this.pipedInstance,
|
||||||
|
searchMode: searchMode ?? this.searchMode,
|
||||||
|
skipNonMusic: skipNonMusic ?? this.skipNonMusic,
|
||||||
|
youtubeApiType: youtubeApiType ?? this.youtubeApiType,
|
||||||
|
recommendationMarket: recommendationMarket ?? this.recommendationMarket,
|
||||||
|
saveTrackLyrics: saveTrackLyrics ?? this.saveTrackLyrics,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final userPreferencesProvider = ChangeNotifierProvider(
|
final userPreferencesProvider = ChangeNotifierProvider(
|
||||||
|
|||||||
@ -6,3 +6,13 @@ final youtubeProvider = Provider<YoutubeEndpoints>((ref) {
|
|||||||
final preferences = ref.watch(userPreferencesProvider);
|
final preferences = ref.watch(userPreferencesProvider);
|
||||||
return YoutubeEndpoints(preferences);
|
return YoutubeEndpoints(preferences);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// this provider overrides the API provider to use piped.video for downloading
|
||||||
|
final downloadYoutubeProvider = Provider<YoutubeEndpoints>((ref) {
|
||||||
|
final preferences = ref.watch(userPreferencesProvider);
|
||||||
|
return YoutubeEndpoints(
|
||||||
|
preferences.copyWith(
|
||||||
|
youtubeApiType: YoutubeApiType.piped,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user