Skip to content

Commit ffbbcc1

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 2d7b19c + ec2f72a commit ffbbcc1

File tree

8 files changed

+53
-14
lines changed

8 files changed

+53
-14
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 2.1.0
2+
- BREAKING CHANGE:
3+
- In `getUploadsFromPage`: the `videoSorting` parameter is now a named parameter
4+
- Shorts filter possibility added in `getUploadsFromPage`.
5+
16
## 2.0.4
27
- Fix issue when parsing dates formatted as "Streamed <q> <unit> ago" due to a leading whitespace. #265
38

lib/src/channels/channel_client.dart

+5-2
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,20 @@ class ChannelClient {
134134

135135
/// Enumerates videos uploaded by the specified channel.
136136
/// This fetches thru all the uploads pages of the channel.
137+
/// The content by default is sorted by time of upload.
137138
///
138139
/// Use .nextPage() to fetch the next batch of videos.
139140
Future<ChannelUploadsList> getUploadsFromPage(
140-
dynamic channelId, [
141+
dynamic channelId, {
141142
VideoSorting videoSorting = VideoSorting.newest,
142-
]) async {
143+
VideoType videoType = VideoType.normal,
144+
}) async {
143145
channelId = ChannelId.fromString(channelId);
144146
final page = await ChannelUploadPage.get(
145147
_httpClient,
146148
(channelId as ChannelId).value,
147149
videoSorting.code,
150+
videoType,
148151
);
149152

150153
final channel = await get(channelId);

lib/src/channels/channels.dart

+1
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ export 'channel_uploads_list.dart';
1313
export 'channel_video.dart';
1414
export 'username.dart';
1515
export 'video_sorting.dart';
16+
export 'video_type.dart';

lib/src/channels/video_sorting.dart

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:meta/meta.dart';
2+
13
/// Metadata about video are sorted with [ChannelClient.getUploadsFromPage]
24
enum VideoSorting {
35
newest._('dd'),
@@ -6,6 +8,7 @@ enum VideoSorting {
68

79
/// Code used to fetch the video.
810
/// Used internally.
11+
@internal
912
final String code;
1013

1114
const VideoSorting._(this.code);

lib/src/channels/video_type.dart

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import 'package:meta/meta.dart';
2+
3+
/// Video types provided by Youtube
4+
enum VideoType {
5+
/// Default horizontal video
6+
normal('videos', 'videoRenderer'),
7+
8+
/// Youtube shorts video
9+
shorts('shorts', 'reelItemRenderer');
10+
11+
final String name;
12+
13+
@internal
14+
final String youtubeRenderText;
15+
16+
const VideoType(this.name, this.youtubeRenderText);
17+
}

lib/src/extensions/helpers_extension.dart

+4-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,10 @@ extension StringUtility2 on String? {
172172
// Streamed x y ago
173173
parts = parts.skip(1).toList();
174174
}
175-
assert(parts.length == 3);
175+
176+
if (parts.length != 3) {
177+
return null;
178+
}
176179

177180
final qty = int.parse(parts.first);
178181

lib/src/reverse_engineering/pages/channel_upload_page.dart

+17-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:collection/collection.dart';
22
import 'package:html/parser.dart' as parser;
3+
import '../../channels/video_type.dart';
34

45
import '../../channels/channel_video.dart';
56
import '../../exceptions/exceptions.dart';
@@ -15,10 +16,12 @@ class ChannelUploadPage extends YoutubePage<_InitialData> {
1516
///
1617
final String channelId;
1718

19+
final VideoType type;
20+
1821
late final List<ChannelVideo> uploads = initialData.uploads;
1922

2023
/// InitialData
21-
ChannelUploadPage.id(this.channelId, super.initialData)
24+
ChannelUploadPage.id(this.channelId, this.type, super.initialData)
2225
: super.fromInitialData();
2326

2427
///
@@ -28,30 +31,33 @@ class ChannelUploadPage extends YoutubePage<_InitialData> {
2831
}
2932

3033
final data = await httpClient.sendContinuation('browse', initialData.token);
31-
return ChannelUploadPage.id(channelId, _InitialData(data));
34+
return ChannelUploadPage.id(channelId, type, _InitialData(data, type));
3235
}
3336

3437
///
3538
static Future<ChannelUploadPage> get(
3639
YoutubeHttpClient httpClient,
3740
String channelId,
3841
String sorting,
42+
VideoType type,
3943
) {
4044
final url =
41-
'https://www.youtube.com/channel/$channelId/videos?view=0&sort=$sorting&flow=grid';
45+
'https://www.youtube.com/channel/$channelId/${type.name}?view=0&sort=$sorting&flow=grid';
4246
return retry(httpClient, () async {
4347
final raw = await httpClient.getString(url);
44-
return ChannelUploadPage.parse(raw, channelId);
48+
return ChannelUploadPage.parse(raw, channelId, type);
4549
});
4650
}
4751

4852
///
49-
ChannelUploadPage.parse(String raw, this.channelId)
50-
: super(parser.parse(raw), (root) => _InitialData(root));
53+
ChannelUploadPage.parse(String raw, this.channelId, this.type)
54+
: super(parser.parse(raw), (root) => _InitialData(root, type));
5155
}
5256

5357
class _InitialData extends InitialData {
54-
_InitialData(super.root);
58+
_InitialData(super.root, this.type);
59+
60+
final VideoType type;
5561

5662
late final JsonMap? continuationContext = getContinuationContext();
5763

@@ -175,8 +181,10 @@ class _InitialData extends InitialData {
175181
if (content.containsKey('gridVideoRenderer')) {
176182
video = content.get('gridVideoRenderer');
177183
} else if (content.containsKey('richItemRenderer')) {
178-
video =
179-
content.get('richItemRenderer')?.get('content')?.get('videoRenderer');
184+
video = content
185+
.get('richItemRenderer')
186+
?.get('content')
187+
?.get(type.youtubeRenderText);
180188
}
181189

182190
if (video == null) {

pubspec.yaml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
name: youtube_explode_dart
22
description: A port in dart of the youtube explode library. Supports several API functions without the need of Youtube API Key.
3-
version: 2.0.4
3+
version: 2.1.0
44
homepage: https://github.com/Hexer10/youtube_explode_dart
55

66
topics:
77
- youtube
8-
- lints
98
- video
109
- streams
1110

0 commit comments

Comments
 (0)