Skip to content

Commit 6e9daf8

Browse files
authored
Merge pull request Hexer10#269 from igormidev/master
Shorts filter added. Closes Hexer10#268
2 parents 80523b9 + 08bcff4 commit 6e9daf8

File tree

7 files changed

+48
-13
lines changed

7 files changed

+48
-13
lines changed

Diff for: 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

Diff for: lib/src/channels/channel_client.dart

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'video_type.dart';
2+
13
import '../common/common.dart';
24
import '../extensions/helpers_extension.dart';
35
import '../playlists/playlists.dart';
@@ -137,14 +139,16 @@ class ChannelClient {
137139
///
138140
/// Use .nextPage() to fetch the next batch of videos.
139141
Future<ChannelUploadsList> getUploadsFromPage(
140-
dynamic channelId, [
142+
dynamic channelId, {
141143
VideoSorting videoSorting = VideoSorting.newest,
142-
]) async {
144+
VideoType videoType = VideoType.normal,
145+
}) async {
143146
channelId = ChannelId.fromString(channelId);
144147
final page = await ChannelUploadPage.get(
145148
_httpClient,
146149
(channelId as ChannelId).value,
147150
videoSorting.code,
151+
videoType,
148152
);
149153

150154
final channel = await get(channelId);

Diff for: 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';

Diff for: lib/src/channels/video_type.dart

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// The type of the video you want to get.
2+
///
3+
/// Will filter only by the type you want.
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+
final String youtubeRenderText;
13+
const VideoType(this.name, this.youtubeRenderText);
14+
}

Diff for: 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

Diff for: 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) {

Diff for: pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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:

0 commit comments

Comments
 (0)