Skip to content

Commit

Permalink
Merge pull request #610 from TeamNewPipe/bandcamp_related_items
Browse files Browse the repository at this point in the history
Extract related bandcamp items
  • Loading branch information
TobiGr authored Apr 13, 2021
2 parents 82d1138 + 3671876 commit c14f6db
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.AudioStream;
import org.schabi.newpipe.extractor.stream.Description;
import org.schabi.newpipe.extractor.stream.StreamSegment;
Expand Down Expand Up @@ -165,4 +166,10 @@ public List<String> getTags() {
public Privacy getPrivacy() {
return Privacy.PUBLIC;
}

@Override
public PlaylistInfoItemsCollector getRelatedItems() {
// Contrary to other Bandcamp streams, radio streams don't have related items
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Created by Fynn Godau 2021, licensed GNU GPL version 3 or later

package org.schabi.newpipe.extractor.services.bandcamp.extractors;

import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemExtractor;

import javax.annotation.Nonnull;

/**
* Extracts recommended albums from tracks' website
*/
public class BandcampRelatedPlaylistInfoItemExtractor implements PlaylistInfoItemExtractor {
private final Element relatedAlbum;

public BandcampRelatedPlaylistInfoItemExtractor(@Nonnull Element relatedAlbum) {
this.relatedAlbum = relatedAlbum;
}

@Override
public String getName() throws ParsingException {
return relatedAlbum.getElementsByClass("release-title").text();
}

@Override
public String getUrl() throws ParsingException {
return relatedAlbum.getElementsByClass("title-and-artist").attr("abs:href");
}

@Override
public String getThumbnailUrl() throws ParsingException {
return relatedAlbum.getElementsByClass("album-art").attr("src");
}

@Override
public String getUploaderName() throws ParsingException {
return relatedAlbum.getElementsByClass("by-artist").text().replace("by ", "");
}

@Override
public long getStreamCount() throws ParsingException {
return -1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
import org.schabi.newpipe.extractor.localization.DateWrapper;
import org.schabi.newpipe.extractor.playlist.PlaylistInfoItemsCollector;
import org.schabi.newpipe.extractor.stream.*;
import org.schabi.newpipe.extractor.utils.JsonUtils;
import org.schabi.newpipe.extractor.utils.Utils;
Expand Down Expand Up @@ -245,8 +246,17 @@ public StreamType getStreamType() {
}

@Override
public StreamInfoItemsCollector getRelatedItems() {
return null;
public PlaylistInfoItemsCollector getRelatedItems() {

PlaylistInfoItemsCollector collector = new PlaylistInfoItemsCollector(getServiceId());

Elements recommendedAlbums = document.getElementsByClass("recommended-album");

for (Element album : recommendedAlbums) {
collector.commit(new BandcampRelatedPlaylistInfoItemExtractor(album));
}

return collector;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public boolean expectedHasVideoStreams() {

@Override
public boolean expectedHasRelatedItems() {
return false;
return true;
}

@Override
Expand Down

0 comments on commit c14f6db

Please sign in to comment.