11package org .schabi .newpipe .extractor .services .soundcloud ;
22
3- import com .github .openjson .JSONObject ;
3+ import com .grack .nanojson .JsonObject ;
4+ import com .grack .nanojson .JsonParser ;
5+ import com .grack .nanojson .JsonParserException ;
46import org .schabi .newpipe .extractor .Downloader ;
57import org .schabi .newpipe .extractor .NewPipe ;
68import org .schabi .newpipe .extractor .StreamingService ;
1416@ SuppressWarnings ("WeakerAccess" )
1517public class SoundcloudChannelExtractor extends ChannelExtractor {
1618 private String userId ;
17- private JSONObject user ;
19+ private JsonObject user ;
1820
1921 public SoundcloudChannelExtractor (StreamingService service , String url , String nextStreamsUrl ) throws IOException , ExtractionException {
2022 super (service , url , nextStreamsUrl );
@@ -29,16 +31,16 @@ public void fetchPage() throws IOException, ExtractionException {
2931 "?client_id=" + SoundcloudParsingHelper .clientId ();
3032
3133 String response = dl .download (apiUrl );
32- user = new JSONObject (response );
34+ try {
35+ user = JsonParser .object ().from (response );
36+ } catch (JsonParserException e ) {
37+ throw new ParsingException ("Could not parse json response" , e );
38+ }
3339 }
3440
3541 @ Override
3642 public String getCleanUrl () {
37- try {
38- return user .getString ("permalink_url" );
39- } catch (Exception e ) {
40- return getOriginalUrl ();
41- }
43+ return user .isString ("permalink_url" ) ? user .getString ("permalink_url" ) : getOriginalUrl ();
4244 }
4345
4446 @ Override
@@ -53,16 +55,12 @@ public String getName() {
5355
5456 @ Override
5557 public String getAvatarUrl () {
56- return user .optString ("avatar_url" );
58+ return user .getString ("avatar_url" );
5759 }
5860
5961 @ Override
6062 public String getBannerUrl () throws ParsingException {
61- try {
62- return user .getJSONObject ("visuals" ).getJSONArray ("visuals" ).getJSONObject (0 ).getString ("visual_url" );
63- } catch (Exception e ) {
64- throw new ParsingException ("Could not get Banner" , e );
65- }
63+ return user .getObject ("visuals" ).getArray ("visuals" ).getObject (0 ).getString ("visual_url" , "" );
6664 }
6765
6866 @ Override
@@ -72,12 +70,12 @@ public String getFeedUrl() throws ParsingException {
7270
7371 @ Override
7472 public long getSubscriberCount () {
75- return user .optLong ("followers_count" );
73+ return user .getNumber ("followers_count" , 0 ). longValue ( );
7674 }
7775
7876 @ Override
7977 public String getDescription () throws ParsingException {
80- return user .optString ("description" );
78+ return user .getString ("description" , " " );
8179 }
8280
8381 @ Override
@@ -102,6 +100,6 @@ public NextItemsResult getNextStreams() throws IOException, ExtractionException
102100 StreamInfoItemCollector collector = new StreamInfoItemCollector (getServiceId ());
103101 nextStreamsUrl = SoundcloudParsingHelper .getStreamsFromApiMinItems (15 , collector , nextStreamsUrl );
104102
105- return new NextItemsResult (collector . getItemList () , nextStreamsUrl );
103+ return new NextItemsResult (collector , nextStreamsUrl );
106104 }
107105}
0 commit comments