@@ -25,6 +25,7 @@ public class BandcampFeaturedExtractor extends KioskExtractor<PlaylistInfoItem>
2525
2626 public static final String KIOSK_FEATURED = "Featured" ;
2727 public static final String FEATURED_API_URL = BASE_API_URL + "/mobile/24/bootstrap_data" ;
28+ public static final String MORE_FEATURED_API_URL = BASE_API_URL + "/mobile/24/feed_older_logged_out" ;
2829
2930 private JsonObject json ;
3031
@@ -56,12 +57,18 @@ public String getName() throws ParsingException {
5657 @ Override
5758 public InfoItemsPage <PlaylistInfoItem > getInitialPage () throws IOException , ExtractionException {
5859
59- final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector (getServiceId ());
6060
6161 final JsonArray featuredStories = json .getObject ("feed_content" )
6262 .getObject ("stories" )
6363 .getArray ("featured" );
6464
65+ return extractItems (featuredStories );
66+ }
67+
68+ private InfoItemsPage <PlaylistInfoItem > extractItems (JsonArray featuredStories ) {
69+
70+ final PlaylistInfoItemsCollector c = new PlaylistInfoItemsCollector (getServiceId ());
71+
6572 for (int i = 0 ; i < featuredStories .size (); i ++) {
6673 final JsonObject featuredStory = featuredStories .getObject (i );
6774
@@ -73,12 +80,37 @@ public InfoItemsPage<PlaylistInfoItem> getInitialPage() throws IOException, Extr
7380 c .commit (new BandcampPlaylistInfoItemFeaturedExtractor (featuredStory ));
7481 }
7582
76- return new InfoItemsPage <>(c , null );
83+ final JsonObject lastFeaturedStory = featuredStories .getObject (featuredStories .size () - 1 );
84+
85+ return new InfoItemsPage <>(c , makeNextPage (lastFeaturedStory ));
86+ }
7787
88+ /**
89+ * The query for more featured stories needs parameters from the last featured
90+ * story.
91+ */
92+ private Page makeNextPage (JsonObject lastFeaturedStory ) {
93+ final long lastStoryDate = lastFeaturedStory .getLong ("story_date" );
94+ final long lastStoryId = lastFeaturedStory .getLong ("ntid" );
95+ final String lastStoryType = lastFeaturedStory .getString ("story_type" );
96+ return new Page (
97+ MORE_FEATURED_API_URL + "?story_groups=featured"
98+ + ':' + lastStoryDate + ':' + lastStoryType + ':' + lastStoryId
99+ );
78100 }
79101
80102 @ Override
81- public InfoItemsPage <PlaylistInfoItem > getPage (Page page ) {
82- return null ;
103+ public InfoItemsPage <PlaylistInfoItem > getPage (Page page ) throws IOException , ExtractionException {
104+
105+ JsonObject response ;
106+ try {
107+ response = JsonParser .object ().from (
108+ getDownloader ().get (page .getUrl ()).responseBody ()
109+ );
110+ } catch (final JsonParserException e ) {
111+ throw new ParsingException ("Could not parse Bandcamp featured API response" , e );
112+ }
113+
114+ return extractItems (response .getObject ("stories" ).getArray ("featured" ));
83115 }
84116}
0 commit comments