Skip to content

Commit

Permalink
fixed extension problem
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikh Haziq committed Nov 5, 2024
1 parent e401e77 commit c3c0249
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/app_config.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AppConfig appConfig = AppConfig(version: 31, codeName: '2.0.6');
AppConfig appConfig = AppConfig(version: 32, codeName: '2.0.7');

class AppConfig {
int version;
Expand Down
36 changes: 20 additions & 16 deletions lib/services/download_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,13 @@ class DownloadManager {
if (!(await FileStorage.requestPermissions())) return;

AudioOnlyStreamInfo audioSource = await _getSongInfo(song['videoId'],
quality: GetIt.I<SettingsManager>().downloadQuality.name.toLowerCase());
int start = 0;
int end = audioSource.size.totalBytes;

Stream<List<int>> stream = AudioStreamClient().getAudioStream(audioSource,start:start,end: end );
quality:
GetIt.I<SettingsManager>().downloadQuality.name.toLowerCase());
int start = 0;
int end = audioSource.size.totalBytes;

Stream<List<int>> stream = AudioStreamClient()
.getAudioStream(audioSource, start: start, end: end);
int total = audioSource.size.totalBytes;
List<int> received = [];
await _box.put(song['videoId'], {
Expand All @@ -63,15 +65,14 @@ class DownloadManager {
},
onDone: () async {
if (received.length == total) {
File? file = await GetIt.I<FileStorage>().saveMusic(received, song,extension: audioSource.container.name);
print(file);
File? file = await GetIt.I<FileStorage>().saveMusic(received, song);
if (file != null) {
await _box.put(song['videoId'], {
...song,
'status': 'DOWNLOADED',
'progress': 100,
'path': file.path,
'timestamp':DateTime.now().millisecondsSinceEpoch
'timestamp': DateTime.now().millisecondsSinceEpoch
});
} else {
await _box.delete(song['videoId']);
Expand All @@ -93,15 +94,18 @@ class DownloadManager {
}

void _downloadNext() {
if (_downloadQueue.isNotEmpty && _activeDownloads < maxConcurrentDownloads) {
if (_downloadQueue.isNotEmpty &&
_activeDownloads < maxConcurrentDownloads) {
downloadSong(_downloadQueue.removeFirst());
}
}

Future<String> deleteSong(String key, String path) async {
await _box.delete(key);
await File(path).delete();
return 'Song deleted successfully.';
}

updateStatus(String key, String status) {
Map? song = _box.get(key);
if (song != null) {
Expand All @@ -111,7 +115,8 @@ class DownloadManager {
}

Future<void> downloadPlaylist(Map playlist) async {
List songs = await GetIt.I<YTMusic>().getPlaylistSongs(playlist['playlistId']);
List songs =
await GetIt.I<YTMusic>().getPlaylistSongs(playlist['playlistId']);
for (Map song in songs) {
await downloadSong(song); // Queue each song download
}
Expand All @@ -120,12 +125,11 @@ class DownloadManager {
Future<AudioOnlyStreamInfo> _getSongInfo(String videoId,
{String quality = 'high'}) async {
try {
StreamManifest manifest = await ytExplode.videos.streamsClient.getManifest(videoId);
List<AudioOnlyStreamInfo> streamInfos = manifest.audioOnly
.sortByBitrate()
.reversed
.toList();
return quality == 'low' ? streamInfos.first:streamInfos.last;
StreamManifest manifest =
await ytExplode.videos.streamsClient.getManifest(videoId);
List<AudioOnlyStreamInfo> streamInfos =
manifest.audioOnly.sortByBitrate().reversed.toList();
return quality == 'low' ? streamInfos.first : streamInfos.last;
} catch (e) {
rethrow;
}
Expand Down
1 change: 0 additions & 1 deletion lib/services/file_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import 'package:permission_handler/permission_handler.dart';
import 'package:path/path.dart' as path;

import '../utils/enhanced_image.dart';
import '../utils/pprint.dart';
import '../ytmusic/ytmusic.dart';
import 'library.dart';
import 'settings_manager.dart';
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: gyawun
description: "A new Flutter project."
publish_to: 'none'
version: 2.0.6+31
version: 2.0.7+32

environment:
sdk: '>=3.4.1 <4.0.0'
Expand Down

0 comments on commit c3c0249

Please sign in to comment.