Skip to content

Commit

Permalink
fix: track loading when not found in Youtube
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Feb 17, 2024
1 parent badd522 commit e964f61
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/services/sourced_track/sources/youtube.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:collection/collection.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:http/http.dart';
import 'package:spotify/spotify.dart';
import 'package:spotube/models/source_match.dart';
import 'package:spotube/services/sourced_track/enums.dart';
Expand Down Expand Up @@ -70,9 +71,14 @@ class YoutubeSourcedTrack extends SourcedTrack {
);
}
final item = await youtubeClient.videos.get(cachedSource.sourceId);
final manifest = await youtubeClient.videos.streamsClient.getManifest(
cachedSource.sourceId,
);
final manifest = await youtubeClient.videos.streamsClient
.getManifest(
cachedSource.sourceId,
)
.timeout(
const Duration(seconds: 5),
onTimeout: () => throw ClientException("Timeout"),
);
return YoutubeSourcedTrack(
ref: ref,
siblings: [],
Expand Down Expand Up @@ -125,7 +131,10 @@ class YoutubeSourcedTrack extends SourcedTrack {
SourceMap? sourceMap;
if (index == 0) {
final manifest =
await youtubeClient.videos.streamsClient.getManifest(item.id);
await youtubeClient.videos.streamsClient.getManifest(item.id).timeout(
const Duration(seconds: 5),
onTimeout: () => throw ClientException("Timeout"),
);
sourceMap = toSourceMap(manifest);
}

Expand Down Expand Up @@ -243,8 +252,12 @@ class YoutubeSourcedTrack extends SourcedTrack {
final newSiblings = siblings.where((s) => s.id != sibling.id).toList()
..insert(0, sourceInfo);

final manifest =
await youtubeClient.videos.streamsClient.getManifest(newSourceInfo.id);
final manifest = await youtubeClient.videos.streamsClient
.getManifest(newSourceInfo.id)
.timeout(
const Duration(seconds: 5),
onTimeout: () => throw ClientException("Timeout"),
);

await SourceMatch.box.put(
id!,
Expand Down

0 comments on commit e964f61

Please sign in to comment.