33package org .schabi .newpipe .extractor .services .bandcamp .extractors ;
44
55import static org .schabi .newpipe .extractor .services .bandcamp .extractors .BandcampExtractorHelper .getImageUrl ;
6+ import static org .schabi .newpipe .extractor .utils .Utils .EMPTY_STRING ;
7+ import static org .schabi .newpipe .extractor .utils .Utils .HTTPS ;
68
79import com .grack .nanojson .JsonObject ;
810import com .grack .nanojson .JsonParserException ;
911
1012import org .jsoup .Jsoup ;
1113import org .jsoup .nodes .Document ;
1214import org .jsoup .nodes .Element ;
13- import org .jsoup .select .Elements ;
1415import org .schabi .newpipe .extractor .MediaFormat ;
1516import org .schabi .newpipe .extractor .StreamingService ;
1617import org .schabi .newpipe .extractor .downloader .Downloader ;
2728import org .schabi .newpipe .extractor .utils .JsonUtils ;
2829import org .schabi .newpipe .extractor .utils .Utils ;
2930
31+ import javax .annotation .Nonnull ;
32+ import javax .annotation .Nullable ;
3033import java .io .IOException ;
3134import java .util .ArrayList ;
3235import java .util .Collections ;
3336import java .util .List ;
34-
35- import javax .annotation .Nonnull ;
36- import javax .annotation .Nullable ;
37+ import java .util .stream .Collectors ;
3738
3839public class BandcampStreamExtractor extends StreamExtractor {
39-
4040 private JsonObject albumJson ;
4141 private JsonObject current ;
4242 private Document document ;
@@ -88,7 +88,7 @@ public String getName() throws ParsingException {
8888 public String getUploaderUrl () throws ParsingException {
8989 final String [] parts = getUrl ().split ("/" );
9090 // https: (/) (/) * .bandcamp.com (/) and leave out the rest
91- return "https://" + parts [2 ] + "/" ;
91+ return HTTPS + parts [2 ] + "/" ;
9292 }
9393
9494 @ Nonnull
@@ -119,10 +119,10 @@ public DateWrapper getUploadDate() throws ParsingException {
119119 @ Override
120120 public String getThumbnailUrl () throws ParsingException {
121121 if (albumJson .isNull ("art_id" )) {
122- return Utils .EMPTY_STRING ;
123- } else {
124- return getImageUrl (albumJson .getLong ("art_id" ), true );
122+ return EMPTY_STRING ;
125123 }
124+
125+ return getImageUrl (albumJson .getLong ("art_id" ), true );
126126 }
127127
128128 @ Nonnull
@@ -139,24 +139,26 @@ public String getUploaderAvatarUrl() {
139139 public Description getDescription () {
140140 final String s = Utils .nonEmptyAndNullJoin (
141141 "\n \n " ,
142- new String []{
142+ new String [] {
143143 current .getString ("about" ),
144144 current .getString ("lyrics" ),
145145 current .getString ("credits" )
146- }
147- );
146+ });
148147 return new Description (s , Description .PLAIN_TEXT );
149148 }
150149
151150 @ Override
152151 public List <AudioStream > getAudioStreams () {
153152 final List <AudioStream > audioStreams = new ArrayList <>();
154-
155- audioStreams .add (new AudioStream (
156- albumJson .getArray ("trackinfo" ).getObject (0 )
157- .getObject ("file" ).getString ("mp3-128" ),
158- MediaFormat .MP3 , 128
159- ));
153+ audioStreams .add (new AudioStream .Builder ()
154+ .setId ("mp3-128" )
155+ .setContent (albumJson .getArray ("trackinfo" )
156+ .getObject (0 )
157+ .getObject ("file" )
158+ .getString ("mp3-128" ), true )
159+ .setMediaFormat (MediaFormat .MP3 )
160+ .setAverageBitrate (128 )
161+ .build ());
160162 return audioStreams ;
161163 }
162164
@@ -184,11 +186,11 @@ public StreamType getStreamType() {
184186 @ Override
185187 public PlaylistInfoItemsCollector getRelatedItems () {
186188 final PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector (getServiceId ());
187- final Elements recommendedAlbums = document .getElementsByClass ("recommended-album" );
189+ document .getElementsByClass ("recommended-album" )
190+ .stream ()
191+ .map (BandcampRelatedPlaylistInfoItemExtractor ::new )
192+ .forEach (collector ::commit );
188193
189- for (final Element album : recommendedAlbums ) {
190- collector .commit (new BandcampRelatedPlaylistInfoItemExtractor (album ));
191- }
192194 return collector ;
193195 }
194196
@@ -200,15 +202,17 @@ public String getCategory() {
200202 .flatMap (element -> element .getElementsByClass ("tag" ).stream ())
201203 .map (Element ::text )
202204 .findFirst ()
203- .orElse ("" );
205+ .orElse (EMPTY_STRING );
204206 }
205207
206208 @ Nonnull
207209 @ Override
208210 public String getLicence () {
209- /* Tests resulted in this mapping of ints to licence:
211+ /*
212+ Tests resulted in this mapping of ints to licence:
210213 https://cloud.disroot.org/s/ZTWBxbQ9fKRmRWJ/preview (screenshot from a Bandcamp artist's
211- account) */
214+ account)
215+ */
212216
213217 switch (current .getInt ("license_type" )) {
214218 case 1 :
@@ -233,14 +237,9 @@ public String getLicence() {
233237 @ Nonnull
234238 @ Override
235239 public List <String > getTags () {
236- final Elements tagElements = document .getElementsByAttributeValue ("itemprop" , "keywords" );
237-
238- final List <String > tags = new ArrayList <>();
239-
240- for (final Element e : tagElements ) {
241- tags .add (e .text ());
242- }
243-
244- return tags ;
240+ return document .getElementsByAttributeValue ("itemprop" , "keywords" )
241+ .stream ()
242+ .map (Element ::text )
243+ .collect (Collectors .toList ());
245244 }
246245}
0 commit comments