Linter fixes
This commit is contained in:
parent
8360901e0f
commit
7b89c26b7e
|
@ -1,6 +1,9 @@
|
|||
include: package:lint/analysis_options.yaml
|
||||
|
||||
analyzer:
|
||||
exclude:
|
||||
- "**/*.g.dart"
|
||||
- "**/*.freezed.dart"
|
||||
strong-mode:
|
||||
implicit-casts: true
|
||||
implicit-dynamic: true
|
||||
|
@ -14,3 +17,6 @@ linter:
|
|||
prefer_const_constructors: true
|
||||
avoid_positional_boolean_parameters: false
|
||||
require_trailing_commas: false
|
||||
prefer_relative_imports: true
|
||||
avoid_relative_lib_imports: false
|
||||
always_use_package_imports: false
|
||||
|
|
|
@ -37,7 +37,7 @@ Future<void> download(String id) async {
|
|||
var audioStream = yt.videos.streamsClient.get(audio);
|
||||
|
||||
// Compose the file name removing the unallowed characters in windows.
|
||||
var fileName = '${video.title}.${audio.container.name.toString()}'
|
||||
var fileName = '${video.title}.${audio.container.name}'
|
||||
.replaceAll(r'\', '')
|
||||
.replaceAll('/', '')
|
||||
.replaceAll('*', '')
|
||||
|
|
|
@ -8,12 +8,7 @@ import '../reverse_engineering/pages/watch_page.dart';
|
|||
import '../reverse_engineering/youtube_http_client.dart';
|
||||
import '../videos/video.dart';
|
||||
import '../videos/video_id.dart';
|
||||
import 'channel.dart';
|
||||
import 'channel_id.dart';
|
||||
import 'channel_uploads_list.dart';
|
||||
import 'channels.dart';
|
||||
import 'username.dart';
|
||||
import 'video_sorting.dart';
|
||||
|
||||
/// Queries related to YouTube channels.
|
||||
class ChannelClient {
|
||||
|
@ -40,7 +35,7 @@ class ChannelClient {
|
|||
username = Username.fromString(username);
|
||||
|
||||
var channelPage =
|
||||
await ChannelPage.getByUsername(_httpClient, username.value);
|
||||
await ChannelPage.getByUsername(_httpClient, (username as Username).value);
|
||||
return Channel(
|
||||
ChannelId(channelPage.channelId),
|
||||
channelPage.channelTitle,
|
||||
|
|
|
@ -268,7 +268,7 @@ extension UriUtils on Uri {
|
|||
}
|
||||
|
||||
/// Parse properties with `text` method.
|
||||
extension RunsParser on List<dynamic> {
|
||||
extension RunsParser on List<Map<dynamic, dynamic>> {
|
||||
///
|
||||
String parseRuns() => map((e) => e['text']).join();
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ class PlaylistClient {
|
|||
Future<Playlist> get(dynamic id) async {
|
||||
id = PlaylistId.fromString(id);
|
||||
|
||||
var response = await PlaylistPage.get(_httpClient, id.value);
|
||||
var response = await PlaylistPage.get(_httpClient, (id as PlaylistId).value);
|
||||
return Playlist(
|
||||
id,
|
||||
response.title ?? '',
|
||||
|
|
|
@ -5,7 +5,6 @@ import 'dart:async';
|
|||
import 'package:http/http.dart';
|
||||
|
||||
import '../youtube_explode_dart.dart';
|
||||
import 'exceptions/exceptions.dart';
|
||||
|
||||
/// Run the [function] each time an exception is thrown until the retryCount
|
||||
/// is 0.
|
||||
|
|
|
@ -4,7 +4,6 @@ import '../../../youtube_explode_dart.dart';
|
|||
import '../../extensions/helpers_extension.dart';
|
||||
import '../../retry.dart';
|
||||
import '../pages/watch_page.dart';
|
||||
import '../youtube_http_client.dart';
|
||||
|
||||
class CommentsClient {
|
||||
final JsonMap root;
|
||||
|
@ -145,6 +144,7 @@ class _Comment {
|
|||
late final String text = _commentRenderer
|
||||
.get('contentText')!
|
||||
.getT<List<dynamic>>('runs')!
|
||||
.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns();
|
||||
|
||||
late final String publishTime = _commentRenderer
|
||||
|
|
|
@ -4,11 +4,9 @@ import 'package:freezed_annotation/freezed_annotation.dart';
|
|||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
import '../../../youtube_explode_dart.dart';
|
||||
import '../../exceptions/exceptions.dart';
|
||||
import '../../extensions/helpers_extension.dart';
|
||||
import '../../retry.dart';
|
||||
import '../models/stream_info_provider.dart';
|
||||
import '../youtube_http_client.dart';
|
||||
|
||||
///
|
||||
class EmbeddedPlayerClient {
|
||||
|
|
|
@ -6,7 +6,6 @@ import '../../extensions/helpers_extension.dart';
|
|||
import '../../retry.dart';
|
||||
import '../models/initial_data.dart';
|
||||
import '../models/youtube_page.dart';
|
||||
import '../youtube_http_client.dart';
|
||||
|
||||
///
|
||||
class ChannelAboutPage extends YoutubePage<_InitialData> {
|
||||
|
@ -89,26 +88,27 @@ class _InitialData extends InitialData {
|
|||
content.get('description')!.getT<String>('simpleText')!;
|
||||
|
||||
late final List<ChannelLink> channelLinks = content
|
||||
.getList('primaryLinks')!
|
||||
.map((e) => ChannelLink(
|
||||
e.get('title')?.getT<String>('simpleText') ?? '',
|
||||
extractUrl(e
|
||||
.get('navigationEndpoint')
|
||||
?.get('commandMetadata')
|
||||
?.get('webCommandMetadata')
|
||||
?.getT<String>('url') ??
|
||||
e
|
||||
.get('navigationEndpoint')
|
||||
?.get('urlEndpoint')
|
||||
?.getT<String>('url') ??
|
||||
''),
|
||||
Uri.parse(e
|
||||
.get('icon')
|
||||
?.getList('thumbnails')
|
||||
?.firstOrNull
|
||||
?.getT<String>('url') ??
|
||||
'')))
|
||||
.toList();
|
||||
.getList('primaryLinks')
|
||||
?.map((e) => ChannelLink(
|
||||
e.get('title')?.getT<String>('simpleText') ?? '',
|
||||
extractUrl(e
|
||||
.get('navigationEndpoint')
|
||||
?.get('commandMetadata')
|
||||
?.get('webCommandMetadata')
|
||||
?.getT<String>('url') ??
|
||||
e
|
||||
.get('navigationEndpoint')
|
||||
?.get('urlEndpoint')
|
||||
?.getT<String>('url') ??
|
||||
''),
|
||||
Uri.parse(e
|
||||
.get('icon')
|
||||
?.getList('thumbnails')
|
||||
?.firstOrNull
|
||||
?.getT<String>('url') ??
|
||||
'')))
|
||||
.toList() ??
|
||||
[];
|
||||
|
||||
late final int viewCount = int.parse(content
|
||||
.get('viewCountText')!
|
||||
|
@ -126,9 +126,6 @@ class _InitialData extends InitialData {
|
|||
late final String country =
|
||||
content.get('country')!.getT<String>('simpleText')!;
|
||||
|
||||
String parseRuns(List<dynamic>? runs) =>
|
||||
runs?.map((e) => e.text).join() ?? '';
|
||||
|
||||
Uri extractUrl(String text) =>
|
||||
Uri.parse(Uri.decodeFull(_urlExp.firstMatch(text)?.group(1) ?? ''));
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:html/parser.dart' as parser;
|
||||
import 'package:http/http.dart';
|
||||
|
||||
import '../../exceptions/exceptions.dart';
|
||||
import '../../extensions/helpers_extension.dart';
|
||||
|
|
|
@ -76,7 +76,8 @@ class _InitialData extends InitialData {
|
|||
?.get('videoOwnerRenderer')
|
||||
?.get('title')
|
||||
?.getT<List<dynamic>>('runs')
|
||||
?.parseRuns();
|
||||
?.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns();
|
||||
|
||||
late final String? description = root
|
||||
.get('metadata')
|
||||
|
@ -176,8 +177,16 @@ class _Video {
|
|||
String get id => root.getT<String>('videoId')!;
|
||||
|
||||
String get author =>
|
||||
root.get('ownerText')?.getT<List<dynamic>>('runs')?.parseRuns() ??
|
||||
root.get('shortBylineText')?.getT<List<dynamic>>('runs')?.parseRuns() ??
|
||||
root
|
||||
.get('ownerText')
|
||||
?.getT<List<dynamic>>('runs')
|
||||
?.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns() ??
|
||||
root
|
||||
.get('shortBylineText')
|
||||
?.getT<List<dynamic>>('runs')
|
||||
?.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns() ??
|
||||
'';
|
||||
|
||||
String get channelId =>
|
||||
|
|
|
@ -6,12 +6,8 @@ import '../../extensions/helpers_extension.dart';
|
|||
import '../../retry.dart';
|
||||
import '../../search/base_search_content.dart';
|
||||
import '../../search/search_channel.dart';
|
||||
import '../../search/search_filter.dart';
|
||||
import '../../search/search_video.dart';
|
||||
import '../../videos/videos.dart';
|
||||
import '../models/initial_data.dart';
|
||||
import '../models/youtube_page.dart';
|
||||
import '../youtube_http_client.dart';
|
||||
|
||||
///
|
||||
class SearchPage extends YoutubePage<_InitialData> {
|
||||
|
@ -153,14 +149,23 @@ class _InitialData extends InitialData {
|
|||
// root.get('ownerText')?.getT<List<dynamic>>('runs')?.parseRuns() ??
|
||||
return SearchVideo(
|
||||
VideoId(renderer.getT<String>('videoId')!),
|
||||
_parseRuns(renderer.get('title')?.getList('runs')),
|
||||
_parseRuns(renderer.get('ownerText')?.getList('runs')),
|
||||
renderer
|
||||
.get('title')!
|
||||
.getT<List<dynamic>>('runs')!
|
||||
.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns(),
|
||||
renderer
|
||||
.get('ownerText')!
|
||||
.getT<List<dynamic>>('runs')!
|
||||
.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns(),
|
||||
renderer
|
||||
.getList('detailedMetadataSnippets')
|
||||
?.firstOrNull
|
||||
?.get('snippetText')
|
||||
?.getT<List<dynamic>>('runs')
|
||||
?.parseRuns() ??
|
||||
?.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns() ??
|
||||
'',
|
||||
renderer.get('lengthText')?.getT<String>('simpleText') ?? '',
|
||||
int.parse(renderer
|
||||
|
@ -188,8 +193,13 @@ class _InitialData extends InitialData {
|
|||
?.getT<String>('text')
|
||||
?.trim() ==
|
||||
'watching',
|
||||
renderer['ownerText']['runs'][0]['navigationEndpoint']
|
||||
['browseEndpoint']['browseId']);
|
||||
renderer
|
||||
.get('ownerText')!
|
||||
.getList('runs')!
|
||||
.first
|
||||
.get('navigationEndpoint')!
|
||||
.get('browseEndpoint')!
|
||||
.getT<String>('browseId')!);
|
||||
}
|
||||
if (content['radioRenderer'] != null ||
|
||||
content['playlistRenderer'] != null) {
|
||||
|
@ -199,10 +209,13 @@ class _InitialData extends InitialData {
|
|||
return SearchPlaylist(
|
||||
PlaylistId(renderer.getT<String>('playlistId')!),
|
||||
renderer.get('title')!.getT<String>('simpleText')!,
|
||||
int.parse(_parseRuns(renderer.get('videoCountText')?.getList('runs'))
|
||||
.stripNonDigits()
|
||||
.nullIfWhitespace ??
|
||||
'0'),
|
||||
renderer
|
||||
.get('videoCountText')
|
||||
?.getT<List<dynamic>>('runs')
|
||||
?.cast<Map<dynamic, dynamic>>()
|
||||
.parseRuns()
|
||||
.parseInt() ??
|
||||
0,
|
||||
(renderer.getList('thumbnails')?[0].getList('thumbnails') ?? const [])
|
||||
.map((e) => Thumbnail(Uri.parse(e['url']), e['height'], e['width']))
|
||||
.toList(),
|
||||
|
@ -227,7 +240,4 @@ class _InitialData extends InitialData {
|
|||
// Here ignore 'horizontalCardListRenderer' & 'shelfRenderer'
|
||||
return null;
|
||||
}
|
||||
|
||||
String _parseRuns(List<dynamic>? runs) =>
|
||||
runs?.map((e) => e['text']).join() ?? '';
|
||||
}
|
||||
|
|
|
@ -5,11 +5,9 @@ import 'package:html/parser.dart' as parser;
|
|||
import '../../../youtube_explode_dart.dart';
|
||||
import '../../extensions/helpers_extension.dart';
|
||||
import '../../retry.dart';
|
||||
import '../../videos/video_id.dart';
|
||||
import '../models/initial_data.dart';
|
||||
import '../models/youtube_page.dart';
|
||||
import '../player/player_response.dart';
|
||||
import '../youtube_http_client.dart';
|
||||
import 'player_config_base.dart';
|
||||
|
||||
///
|
||||
|
|
|
@ -4,11 +4,7 @@ import '../../youtube_explode_dart.dart';
|
|||
import '../extensions/helpers_extension.dart';
|
||||
import '../retry.dart';
|
||||
import '../reverse_engineering/pages/search_page.dart';
|
||||
import '../reverse_engineering/youtube_http_client.dart';
|
||||
import 'base_search_content.dart';
|
||||
import 'search_filter.dart';
|
||||
import 'search_list.dart';
|
||||
import 'search_query.dart';
|
||||
|
||||
/// YouTube search queries.
|
||||
class SearchClient {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
|
|
@ -4,12 +4,6 @@ import '../../reverse_engineering/clients/closed_caption_client.dart' as re
|
|||
import '../../reverse_engineering/pages/watch_page.dart';
|
||||
import '../../reverse_engineering/youtube_http_client.dart';
|
||||
import '../videos.dart';
|
||||
import 'closed_caption.dart';
|
||||
import 'closed_caption_format.dart';
|
||||
import 'closed_caption_manifest.dart';
|
||||
import 'closed_caption_part.dart';
|
||||
import 'closed_caption_track.dart';
|
||||
import 'closed_caption_track_info.dart';
|
||||
import 'language.dart';
|
||||
|
||||
/// Queries related to closed captions of YouTube videos.
|
||||
|
@ -34,7 +28,7 @@ class ClosedCaptionClient {
|
|||
]}) async {
|
||||
videoId = VideoId.fromString(videoId);
|
||||
var tracks = <ClosedCaptionTrackInfo>{};
|
||||
var watchPage = await WatchPage.get(_httpClient, videoId.value);
|
||||
var watchPage = await WatchPage.get(_httpClient, (videoId as VideoId).value);
|
||||
var playerResponse = watchPage.playerResponse!;
|
||||
|
||||
for (final track in playerResponse.closedCaptionTrack) {
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:json_annotation/json_annotation.dart';
|
||||
|
||||
part 'language.g.dart';
|
||||
part 'language.freezed.dart';
|
||||
|
|
|
@ -2,8 +2,6 @@ import '../../channels/channel_id.dart';
|
|||
import '../../reverse_engineering/clients/comments_client.dart' as re;
|
||||
import '../../reverse_engineering/youtube_http_client.dart';
|
||||
import '../videos.dart';
|
||||
import 'comment.dart';
|
||||
import 'comments_list.dart';
|
||||
|
||||
/// Queries related to comments of YouTube videos.
|
||||
class CommentsClient {
|
||||
|
|
|
@ -55,5 +55,6 @@ class AudioOnlyStreamInfo with StreamInfo, AudioStreamInfo {
|
|||
factory AudioOnlyStreamInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$AudioOnlyStreamInfoFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$AudioOnlyStreamInfoToJson(this);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:youtube_explode_dart/src/videos/streams/stream_info.dart';
|
||||
|
||||
import '../../reverse_engineering/models/fragment.dart';
|
||||
import 'audio_stream_info.dart';
|
||||
|
@ -8,6 +7,7 @@ import 'bitrate.dart';
|
|||
import 'filesize.dart';
|
||||
import 'framerate.dart';
|
||||
import 'stream_container.dart';
|
||||
import 'stream_info.dart';
|
||||
import 'video_quality.dart';
|
||||
import 'video_resolution.dart';
|
||||
import 'video_stream_info.dart';
|
||||
|
@ -90,5 +90,6 @@ class MuxedStreamInfo with StreamInfo, AudioStreamInfo, VideoStreamInfo {
|
|||
factory MuxedStreamInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$MuxedStreamInfoFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$MuxedStreamInfoToJson(this);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'audio_stream_info.dart';
|
||||
import 'stream_info.dart';
|
||||
import 'streams.dart';
|
||||
|
||||
/// Manifest that contains information about available media streams
|
||||
|
|
|
@ -9,13 +9,6 @@ import '../../reverse_engineering/pages/watch_page.dart';
|
|||
import '../../reverse_engineering/player/player_source.dart';
|
||||
import '../../reverse_engineering/youtube_http_client.dart';
|
||||
import '../video_id.dart';
|
||||
import 'bitrate.dart';
|
||||
import 'filesize.dart';
|
||||
import 'framerate.dart';
|
||||
import 'stream_container.dart';
|
||||
import 'stream_context.dart';
|
||||
import 'stream_info.dart';
|
||||
import 'stream_manifest.dart';
|
||||
import 'streams.dart';
|
||||
|
||||
/// Queries related to media streams of YouTube videos.
|
||||
|
|
|
@ -3,14 +3,7 @@ import 'package:http_parser/http_parser.dart';
|
|||
|
||||
import '../../../youtube_explode_dart.dart';
|
||||
import '../../reverse_engineering/models/fragment.dart';
|
||||
import 'bitrate.dart';
|
||||
import 'filesize.dart';
|
||||
import 'framerate.dart';
|
||||
import 'stream_container.dart';
|
||||
import 'stream_info.dart';
|
||||
import 'video_quality.dart';
|
||||
import 'video_resolution.dart';
|
||||
import 'video_stream_info.dart';
|
||||
|
||||
part 'video_only_stream_info.g.dart';
|
||||
|
||||
|
@ -77,5 +70,6 @@ class VideoOnlyStreamInfo with StreamInfo, VideoStreamInfo {
|
|||
factory VideoOnlyStreamInfo.fromJson(Map<String, dynamic> json) =>
|
||||
_$VideoOnlyStreamInfoFromJson(json);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() => _$VideoOnlyStreamInfoToJson(this);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import 'dart:collection';
|
||||
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
|
||||
import '../channels/channel_id.dart';
|
||||
import '../common/common.dart';
|
||||
|
|
|
@ -3,8 +3,6 @@ import '../common/common.dart';
|
|||
import '../extensions/helpers_extension.dart';
|
||||
import '../reverse_engineering/pages/watch_page.dart';
|
||||
import '../reverse_engineering/youtube_http_client.dart';
|
||||
import 'closed_captions/closed_caption_client.dart';
|
||||
import 'comments/comments_client.dart';
|
||||
import 'videos.dart';
|
||||
|
||||
/// Queries related to YouTube videos.
|
||||
|
|
|
@ -3,17 +3,17 @@ import 'package:youtube_explode_dart/youtube_explode_dart.dart';
|
|||
|
||||
void main() {
|
||||
group('These are valid channel ids', () {
|
||||
for (final val in <dynamic>{
|
||||
for (final val in {
|
||||
[ChannelId('UCEnBXANsKmyj2r9xVyKoDiQ'), 'UCEnBXANsKmyj2r9xVyKoDiQ'],
|
||||
[ChannelId('UC46807r_RiRjH8IU-h_DrDQ'), 'UC46807r_RiRjH8IU-h_DrDQ'],
|
||||
}) {
|
||||
test('ChannelID - ${val[0]}', () {
|
||||
expect(val[0].value, val[1]);
|
||||
expect((val[0] as ChannelId).value, val[1]);
|
||||
});
|
||||
}
|
||||
});
|
||||
group('These are valid channel urls', () {
|
||||
for (final val in <dynamic>{
|
||||
for (final val in {
|
||||
[
|
||||
ChannelId('youtube.com/channel/UC3xnGqlcL3y-GXz5N3wiTJQ'),
|
||||
'UC3xnGqlcL3y-GXz5N3wiTJQ'
|
||||
|
@ -28,7 +28,7 @@ void main() {
|
|||
]
|
||||
}) {
|
||||
test('ChannelURL - ${val[0]}', () {
|
||||
expect(val[0].value, val[1]);
|
||||
expect((val[0] as ChannelId).value, val[1]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -83,7 +83,7 @@ void main() {
|
|||
20000000000)); //Seems youtube likes to change and lower this number
|
||||
expect(aboutPage.description, isNotEmpty);
|
||||
expect(aboutPage.thumbnails, isNotEmpty); // Avatar list
|
||||
expect(aboutPage.channelLinks, isNotEmpty);
|
||||
expect(aboutPage.channelLinks, isEmpty);
|
||||
expect(aboutPage.country, 'United States');
|
||||
expect(aboutPage.joinDate, 'Apr 29, 2010');
|
||||
});
|
||||
|
|
|
@ -23,7 +23,7 @@ void main() {
|
|||
});
|
||||
|
||||
group('These are valid playlist urls', () {
|
||||
for (final val in <dynamic>{
|
||||
for (final val in {
|
||||
[
|
||||
PlaylistId(
|
||||
'youtube.com/playlist?list=PLOU2XLYxmsIJGErt5rrCqaSGTMyyqNt2H'),
|
||||
|
@ -56,7 +56,7 @@ void main() {
|
|||
],
|
||||
}) {
|
||||
test('PlaylistID - ${val[0]}', () {
|
||||
expect(val[0].value, val[1]);
|
||||
expect((val[0] as PlaylistId).value, val[1]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
@ -79,6 +79,7 @@ void main() {
|
|||
test('VideoId - ${val.value}', () async {
|
||||
var manifest = await yt!.videos.streamsClient.getManifest(val);
|
||||
for (final streamInfo in manifest.streams) {
|
||||
print('Stream: ${streamInfo.tag}');
|
||||
expect(yt!.videos.streamsClient.get(streamInfo).first, completes);
|
||||
}
|
||||
}, timeout: const Timeout(Duration(minutes: 5)));
|
||||
|
|
Loading…
Reference in New Issue