From 775edb00dba902cce4d09e276676cec94717e4b1 Mon Sep 17 00:00:00 2001 From: Sheikh Haziq Date: Fri, 27 Sep 2024 23:40:22 +0530 Subject: [PATCH] fixed youtube library loading bug --- lib/app_config.dart | 2 +- lib/ytmusic/mixins/browsing.dart | 2 -- lib/ytmusic/mixins/library.dart | 45 +++++++++++++++++++++++--------- pubspec.yaml | 2 +- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/lib/app_config.dart b/lib/app_config.dart index da889c8..2137409 100644 --- a/lib/app_config.dart +++ b/lib/app_config.dart @@ -1,4 +1,4 @@ -AppConfig appConfig = AppConfig(version: 27, codeName: '2.0.2'); +AppConfig appConfig = AppConfig(version: 28, codeName: '2.0.3'); class AppConfig { int version; diff --git a/lib/ytmusic/mixins/browsing.dart b/lib/ytmusic/mixins/browsing.dart index 65efd3c..85f6182 100644 --- a/lib/ytmusic/mixins/browsing.dart +++ b/lib/ytmusic/mixins/browsing.dart @@ -60,8 +60,6 @@ mixin BrowsingMixin on YTMusicServices { 'secondaryContents', 'sectionListRenderer' ]); - // pprint(nav(sectionListRenderer, - // ['contents', 0, 'musicShelfRenderer', 'continuations'])); List? chips = nav(sectionListRenderer, ['header', 'chipCloudRenderer', 'chips']); if (chips != null) { diff --git a/lib/ytmusic/mixins/library.dart b/lib/ytmusic/mixins/library.dart index 760a0b9..930544d 100644 --- a/lib/ytmusic/mixins/library.dart +++ b/lib/ytmusic/mixins/library.dart @@ -1,3 +1,5 @@ +import 'package:gyawun/utils/pprint.dart'; + import '../helpers.dart'; import '../yt_service_provider.dart'; import 'utils.dart'; @@ -5,14 +7,16 @@ import 'utils.dart'; mixin LibraryMixin on YTMusicServices { Future getLibrarySongs({String? continuationParams}) async { Map body = {'browseId': 'FEmusic_liked_videos'}; + final response = await sendRequest('browse', body, additionalParams: continuationParams ?? ''); + Map outerContents = {}; if (continuationParams != null) { outerContents = nav(response, ['continuationContents', 'musicShelfContinuation']); } else { - outerContents = nav(response, [ + Map contents = nav(response, [ 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', @@ -22,8 +26,13 @@ mixin LibraryMixin on YTMusicServices { 'sectionListRenderer', 'contents', 0, + ]); + outerContents = nav(contents, [ 'musicShelfRenderer' + ])??nav(contents, [ + 'itemSectionRenderer' ]); + } String? continuation = nav(outerContents, @@ -47,8 +56,7 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'gridContinuation']); } else { - outerContents = nav(response, [ - 'contents', + Map contents = nav(response, ['contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -56,8 +64,11 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0, + 0,]); + outerContents = nav(contents, [ 'gridRenderer', + ])??nav(contents, [ + 'itemSectionRenderer', ]); } String? continuation = nav(outerContents, @@ -65,7 +76,7 @@ mixin LibraryMixin on YTMusicServices { if (continuation != null) { continuation = getContinuationString(continuation); } - List contents = nav(outerContents, ['items']); + List contents = nav(outerContents, ['items'])??nav(outerContents, ['contents']); return { 'contents': handleContents(contents), @@ -85,8 +96,7 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'musicShelfContinuation']); } else { - outerContents = nav(response, [ - 'contents', + Map contents = nav(response,['contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -94,8 +104,11 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0, + 0,]); + outerContents = nav(contents, [ 'musicShelfRenderer', + ])??nav(contents,[ + 'itemSectionRenderer', ]); } String? continuation = nav(outerContents, @@ -120,8 +133,7 @@ mixin LibraryMixin on YTMusicServices { outerContents = nav(response, ['continuationContents', 'gridContinuation']); } else { - outerContents = nav(response, [ - 'contents', + Map contents = nav(response,[ 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', 0, @@ -129,9 +141,14 @@ mixin LibraryMixin on YTMusicServices { 'content', 'sectionListRenderer', 'contents', - 0, + 0,]); + outerContents = nav(contents, [ 'gridRenderer' + ])?? + nav(contents, [ + 'itemSectionRenderer', ]); + } String? continuation = nav(outerContents, ['continuations', 0, 'nextContinuationData', 'continuation']); @@ -158,7 +175,7 @@ mixin LibraryMixin on YTMusicServices { outerContents = outerContents = nav(response, ['continuationContents', 'musicShelfContinuation']); } else { - outerContents = nav(response, [ + Map contents = nav(response,[ 'contents', 'singleColumnBrowseResultsRenderer', 'tabs', @@ -168,7 +185,11 @@ mixin LibraryMixin on YTMusicServices { 'sectionListRenderer', 'contents', 0, + ]); + outerContents = nav(contents, [ 'musicShelfRenderer', + ])??nav(contents, [ + 'itemSectionRenderer', ]); } String? continuation = nav(outerContents, diff --git a/pubspec.yaml b/pubspec.yaml index 6d0ca81..08145dd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,7 +1,7 @@ name: gyawun description: "A new Flutter project." publish_to: 'none' -version: 2.0.2+27 +version: 2.0.3+28 environment: sdk: '>=3.4.1 <4.0.0'