Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YouTube] Fix the extraction of series playlists and don't return the view count as the stream count for learning playlists #811

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,45 @@

import javax.annotation.Nonnull;

import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;

public abstract class PlaylistExtractor extends ListExtractor<StreamInfoItem> {

public PlaylistExtractor(StreamingService service, ListLinkHandler linkHandler) {
public PlaylistExtractor(final StreamingService service, final ListLinkHandler linkHandler) {
super(service, linkHandler);
}

public abstract String getThumbnailUrl() throws ParsingException;
public abstract String getBannerUrl() throws ParsingException;

public abstract String getUploaderUrl() throws ParsingException;
public abstract String getUploaderName() throws ParsingException;
public abstract String getUploaderAvatarUrl() throws ParsingException;
public abstract boolean isUploaderVerified() throws ParsingException;

public abstract long getStreamCount() throws ParsingException;

@Nonnull public abstract String getSubChannelName() throws ParsingException;
@Nonnull public abstract String getSubChannelUrl() throws ParsingException;
@Nonnull public abstract String getSubChannelAvatarUrl() throws ParsingException;
@Nonnull
public String getThumbnailUrl() throws ParsingException {
return EMPTY_STRING;
}

@Nonnull
public String getBannerUrl() throws ParsingException {
// Banner can't be handled by frontend right now.
// Whoever is willing to implement this should also implement it in the frontend.
return EMPTY_STRING;
}

@Nonnull
public String getSubChannelName() throws ParsingException {
return EMPTY_STRING;
}

@Nonnull
public String getSubChannelUrl() throws ParsingException {
return EMPTY_STRING;
}

@Nonnull
public String getSubChannelAvatarUrl() throws ParsingException {
return EMPTY_STRING;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@

import javax.annotation.Nonnull;
import java.io.IOException;
import java.util.Objects;

import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampExtractorHelper.getImageUrl;
import static org.schabi.newpipe.extractor.utils.JsonUtils.getJsonData;
import static org.schabi.newpipe.extractor.services.bandcamp.extractors.BandcampStreamExtractor.getAlbumInfoJson;
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
import static org.schabi.newpipe.extractor.utils.Utils.HTTPS;

public class BandcampPlaylistExtractor extends PlaylistExtractor {

Expand Down Expand Up @@ -57,33 +60,27 @@ public void onFetchPage(@Nonnull final Downloader downloader) throws IOException
throw new ParsingException("JSON does not exist", e);
}



if (trackInfo.size() <= 0) {
if (trackInfo.isEmpty()) {
// Albums without trackInfo need to be purchased before they can be played
throw new ContentNotAvailableException("Album needs to be purchased");
}
}

@Nonnull
@Override
public String getThumbnailUrl() throws ParsingException {
if (albumJson.isNull("art_id")) {
return "";
return EMPTY_STRING;
} else {
return getImageUrl(albumJson.getLong("art_id"), true);
}
}

@Override
public String getBannerUrl() {
return "";
}

@Override
public String getUploaderUrl() throws ParsingException {
final String[] parts = getUrl().split("/");
// https: (/) (/) * .bandcamp.com (/) and leave out the rest
return "https://" + parts[2] + "/";
return HTTPS + parts[2] + "/";
}

@Override
Expand All @@ -94,9 +91,10 @@ public String getUploaderName() {
@Override
public String getUploaderAvatarUrl() {
try {
return document.getElementsByClass("band-photo").first().attr("src");
} catch (NullPointerException e) {
return "";
return Objects.requireNonNull(document.getElementsByClass("band-photo").first())
.attr("src");
} catch (final NullPointerException e) {
return EMPTY_STRING;
}
}

Expand All @@ -110,24 +108,6 @@ public long getStreamCount() {
return trackInfo.size();
}

@Nonnull
@Override
public String getSubChannelName() {
return "";
}

@Nonnull
@Override
public String getSubChannelUrl() {
return "";
}

@Nonnull
@Override
public String getSubChannelAvatarUrl() {
return "";
}

@Nonnull
@Override
public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException {
Expand All @@ -146,14 +126,13 @@ public InfoItemsPage<StreamInfoItem> getInitialPage() throws ExtractionException
collector.commit(new BandcampPlaylistStreamInfoItemExtractor(
track, getUploaderUrl(), getThumbnailUrl()));
}

}

return new InfoItemsPage<>(collector, null);
}

@Override
public InfoItemsPage<StreamInfoItem> getPage(Page page) {
public InfoItemsPage<StreamInfoItem> getPage(final Page page) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,12 @@ public PeertubePlaylistExtractor(final StreamingService service, final ListLinkH
super(service, linkHandler);
}

@Nonnull
@Override
public String getThumbnailUrl() throws ParsingException {
return getBaseUrl() + playlistInfo.getString("thumbnailPath");
}

@Override
public String getBannerUrl() {
return null;
}

@Override
public String getUploaderUrl() {
return playlistInfo.getObject("ownerAccount").getString("url");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import java.util.List;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import static org.schabi.newpipe.extractor.services.soundcloud.SoundcloudParsingHelper.SOUNDCLOUD_API_V2_URL;
import static org.schabi.newpipe.extractor.utils.Utils.EMPTY_STRING;
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;

public class SoundcloudPlaylistExtractor extends PlaylistExtractor {
Expand Down Expand Up @@ -67,7 +67,7 @@ public String getName() {
return playlist.getString("title");
}

@Nullable
@Nonnull
@Override
public String getThumbnailUrl() {
String artworkUrl = playlist.getString("artwork_url");
Expand All @@ -80,24 +80,21 @@ public String getThumbnailUrl() {

for (final StreamInfoItem item : infoItems.getItems()) {
artworkUrl = item.getThumbnailUrl();
if (!isNullOrEmpty(artworkUrl)) break;
if (!isNullOrEmpty(artworkUrl)) {
break;
}
}
} catch (final Exception ignored) {
}

if (artworkUrl == null) {
return null;
return EMPTY_STRING;
}
}

return artworkUrl.replace("large.jpg", "crop.jpg");
}

@Override
public String getBannerUrl() {
return null;
}

@Override
public String getUploaderUrl() {
return SoundcloudParsingHelper.getUploaderUrl(playlist);
Expand All @@ -123,44 +120,28 @@ public long getStreamCount() {
return playlist.getLong("track_count");
}

@Nonnull
@Override
public String getSubChannelName() {
return "";
}

@Nonnull
@Override
public String getSubChannelUrl() {
return "";
}

@Nonnull
@Override
public String getSubChannelAvatarUrl() {
return "";
}

@Nonnull
@Override
public InfoItemsPage<StreamInfoItem> getInitialPage() {
final StreamInfoItemsCollector streamInfoItemsCollector =
new StreamInfoItemsCollector(getServiceId());
final List<String> ids = new ArrayList<>();

final JsonArray tracks = playlist.getArray("tracks");
for (final Object o : tracks) {
if (o instanceof JsonObject) {
final JsonObject track = (JsonObject) o;
if (track.has("title")) { // i.e. if full info is available
streamInfoItemsCollector.commit(new SoundcloudStreamInfoItemExtractor(track));
} else {
// %09d would be enough, but a 0 before the number does not create problems, so
// let's be sure
ids.add(String.format("%010d", track.getInt("id")));
}
}
}
playlist.getArray("tracks")
.stream()
.filter(JsonObject.class::isInstance)
.map(JsonObject.class::cast)
.forEachOrdered(track -> {
// i.e. if full info is available
if (track.has("title")) {
streamInfoItemsCollector.commit(
new SoundcloudStreamInfoItemExtractor(track));
} else {
// %09d would be enough, but a 0 before the number does not create
// problems, so let's be sure
ids.add(String.format("%010d", track.getInt("id")));
}
});

return new InfoItemsPage<>(streamInfoItemsCollector, new Page(ids));
}
Expand Down
Loading