Skip to content

Commit

Permalink
Fix getUploadsFromPage.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hexer10 committed Nov 3, 2022
1 parent 89ba63a commit 3136af8
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ doc/api/
*.iml
/local/

.flutter-plugins-dependencies
.flutter-plugins-dependencies
/coverage/
54 changes: 36 additions & 18 deletions lib/src/reverse_engineering/pages/channel_upload_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,36 @@ class _InitialData extends InitialData {
List<JsonMap> getContentContext() {
List<JsonMap>? context;
if (root.containsKey('contents')) {
final render = root
var render = root
.get('contents')
?.get('twoColumnBrowseResultsRenderer')
?.getList('tabs')
?.map((e) => e['tabRenderer'])
.cast<JsonMap>()
.firstWhereOrNull((e) => e['selected'] as bool? ?? false)
?.get('content')
?.get('sectionListRenderer')
?.getList('contents')
?.firstOrNull
?.get('itemSectionRenderer')
?.getList('contents')
?.firstOrNull;

if (render?.containsKey('gridRenderer') ?? false) {
context =
render?.get('gridRenderer')?.getList('items')?.cast<JsonMap>();
} else if (render?.containsKey('messageRenderer') ?? false) {
// Workaround for no-videos.
context = const [];
?.get('content');

if (render != null) {
if (render.containsKey('sectionListRenderer')) {
render = render
.get('sectionListRenderer')
?.getList('contents')
?.firstOrNull
?.get('itemSectionRenderer')
?.getList('contents')
?.firstOrNull;

if (render?.containsKey('gridRenderer') ?? false) {
context =
render?.get('gridRenderer')?.getList('items')?.cast<JsonMap>();
} else if (render?.containsKey('messageRenderer') ?? false) {
// Workaround for no-videos.
context = const [];
}
} else if (render.containsKey('richGridRenderer')) {
context =
render.get('richGridRenderer')?.getList('contents') ?? const [];
}
}
}
if (context == null && root.containsKey('onResponseReceivedActions')) {
Expand All @@ -112,7 +121,7 @@ class _InitialData extends InitialData {
?.getList('tabs')
?.map((e) => e['tabRenderer'])
.cast<JsonMap>()
.firstWhereOrNull((e) => e['selected'] as bool)
.firstWhereOrNull((e) => e['selected'] as bool? ?? false)
?.get('content')
?.get('sectionListRenderer')
?.getList('contents')
Expand Down Expand Up @@ -142,11 +151,20 @@ class _InitialData extends InitialData {
}

ChannelVideo? _parseContent(JsonMap? content) {
if (content == null || !content.containsKey('gridVideoRenderer')) {
if (content == null) {
return null;
}

var video = content.get('gridVideoRenderer')!;
Map<String, dynamic>? video;
if (content.containsKey('gridVideoRenderer')) {
video = content.get('gridVideoRenderer');
} else if (content.containsKey('richItemRenderer')) {
video = content.get('richItemRenderer')?.get('content')?.get('videoRenderer');
}

if (video == null) {
return null;
}
return ChannelVideo(
VideoId(video.getT<String>('videoId')!),
video.get('title')?.getT<String>('simpleText') ??
Expand Down
7 changes: 7 additions & 0 deletions test/channel_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ void main() {
expect(videos, hasLength(30));
});

test('Get next page of yt video', () async {
var videos =
await yt!.channels.getUploadsFromPage('UCEnBXANsKmyj2r9xVyKoDiQ');
final nextPage = await videos.nextPage();
expect(nextPage, hasLength(30));
});

//TODO: Remove dupe test
test('Get about page of a youtube', () async {
var aboutPage = await yt!.channels.getAboutPageByUsername(
Expand Down

0 comments on commit 3136af8

Please sign in to comment.