spotube/lib/services/youtube_engine/newpipe_engine.dart
Alessio fece073def This pull request primarily involves the removal of several configuration files and assets, as well as minor updates to documentation. The most significant changes are the deletion of various .vscode configuration files and the removal of unused assets from the project.
Configuration File Removals:

    .vscode/c_cpp_properties.json: Removed the entire configuration for C/C++ properties.
    .vscode/launch.json: Removed the Dart launch configurations for different environments and modes.
    .vscode/settings.json: Removed settings related to CMake, spell checking, file nesting, and Dart Flutter SDK path.
    .vscode/snippets.code-snippets: Removed code snippets for Dart, including PaginatedState and PaginatedNotifier templates.
    .vscode/tasks.json: Removed the tasks configuration file.

Documentation Updates:

    CONTRIBUTION.md: Removed heart emoji from the introductory text.
    README.md: Updated the logo image and made minor text adjustments, including removing emojis and updating section titles. [1] [2] [3] [4] [5]

Asset Removals:

    lib/collections/assets.gen.dart: Removed multiple unused asset references, including images related to Spotube logos and banners. [1] [2] [3]

Minor Code Cleanups:

    cli/commands/build/linux.dart, cli/commands/build/windows.dart, cli/commands/translated.dart, cli/commands/untranslated.dart: Adjusted import statements for consistency. [1] [2] [3] [4]
    integration_test/app_test.dart: Removed an unnecessary blank line.
    lib/collections/routes.dart: Commented out the TrackRoute configuration.
2025-04-13 18:40:37 +02:00

110 lines
3.1 KiB
Dart

import 'package:flutter_new_pipe_extractor/flutter_new_pipe_extractor.dart'
hide Engagement;
import 'package:http_parser/http_parser.dart';
import 'package:spotube/services/youtube_engine/youtube_engine.dart';
import 'package:spotube/utils/platform.dart';
import 'package:youtube_explode_dart/youtube_explode_dart.dart';
class NewPipeEngine implements YouTubeEngine {
static bool get isAvailableForPlatform => kIsAndroid;
AudioOnlyStreamInfo _parseAudioStream(AudioStream stream, String videoId) {
return AudioOnlyStreamInfo(
VideoId(videoId),
stream.itag,
Uri.parse(stream.content),
StreamContainer.parse(stream.mediaFormat!.mimeType.split("/").last),
FileSize.unknown,
Bitrate(stream.bitrate),
stream.codec,
stream.quality,
[],
MediaType.parse(stream.mediaFormat!.mimeType),
null,
);
}
Video _parseVideo(VideoInfo info) {
return Video(
VideoId(info.id),
info.name,
info.uploaderName,
ChannelId(info.uploaderUrl),
info.uploadDate.offsetDateTime,
info.uploadDate.offsetDateTime.toString(),
info.uploadDate.offsetDateTime,
info.description.content ?? "",
Duration(seconds: info.duration),
ThumbnailSet(info.id),
info.tags,
Engagement(
info.viewCount,
info.likeCount,
info.dislikeCount,
),
!info.streamType.name.toLowerCase().contains("live"),
);
}
Video _parseVideoResult(VideoSearchResultItem info) {
final id = Uri.parse(info.url).queryParameters["v"]!;
return Video(
VideoId(id),
info.name,
info.uploaderName,
ChannelId(info.uploaderUrl),
info.uploadDate?.offsetDateTime,
info.uploadDate?.offsetDateTime.toString(),
info.uploadDate?.offsetDateTime,
info.shortDescription ?? "",
Duration(seconds: info.duration),
ThumbnailSet(id),
[],
Engagement(info.viewCount, null, null),
!info.streamType.name.toLowerCase().contains("live"),
);
}
@override
Future<StreamManifest> getStreamManifest(String videoId) async {
final video = await NewPipeExtractor.getVideoInfo(videoId);
final streams =
video.audioStreams.map((stream) => _parseAudioStream(stream, videoId));
return StreamManifest(streams);
}
@override
Future<Video> getVideo(String videoId) async {
final video = await NewPipeExtractor.getVideoInfo(videoId);
return _parseVideo(video);
}
@override
Future<(Video, StreamManifest)> getVideoWithStreamInfo(String videoId) async {
final video = await NewPipeExtractor.getVideoInfo(videoId);
final streams =
video.audioStreams.map((stream) => _parseAudioStream(stream, videoId));
return (_parseVideo(video), StreamManifest(streams));
}
@override
Future<List<Video>> searchVideos(String query) async {
final results = await NewPipeExtractor.search(
query,
contentFilters: [SearchContentFilters.videos],
);
final resultsWithVideos = results
.whereType<VideoSearchResultItem>()
.map((e) => _parseVideoResult(e))
.toList();
return resultsWithVideos;
}
}