mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 16:05:18 +00:00

Player works as previous except shuffling Youtube Search is handled through youtube_explode now
25 lines
940 B
Dart
25 lines
940 B
Dart
import 'package:spotify/spotify.dart';
|
|
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
|
|
|
YoutubeExplode youtube = YoutubeExplode();
|
|
Future<Track> toYoutubeTrack(Track track) async {
|
|
var artistsName = track.artists?.map((ar) => ar.name).toList() ?? [];
|
|
String queryString =
|
|
"${artistsName.first} - ${track.name}${artistsName.length > 1 ? " feat. ${artistsName.sublist(1).join(" ")}" : ""}";
|
|
|
|
SearchList videos = await youtube.search.getVideos(queryString);
|
|
|
|
List<Video> matchedVideos = videos.where((video) {
|
|
return video.title.contains(track.name!) &&
|
|
(track.artists?.every((artist) => video.title.contains(artist.name!)) ??
|
|
false);
|
|
}).toList();
|
|
|
|
Video ytVideo = matchedVideos.isNotEmpty ? matchedVideos.first : videos.first;
|
|
|
|
var trackManifest = await youtube.videos.streams.getManifest(ytVideo.id);
|
|
|
|
track.uri = trackManifest.audioOnly.first.url.toString();
|
|
return track;
|
|
}
|