Music Kiosk is added but does not display trending music. just trending
This commit is contained in:
parent
1129653896
commit
b5bb05da18
|
@ -27,6 +27,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeCommentsE
|
|||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeFeedExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMixPlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMusicSearchExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeMusicTrendingExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubePlaylistExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSearchExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeStreamExtractor;
|
||||
|
@ -35,6 +36,7 @@ import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeSuggestio
|
|||
import org.schabi.newpipe.extractor.services.youtube.extractors.YoutubeTrendingExtractor;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeChannelLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeCommentsLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeMusicTrendingLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubePlaylistLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeSearchQueryHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeStreamLinkHandlerFactory;
|
||||
|
@ -140,6 +142,16 @@ public class YoutubeService extends StreamingService {
|
|||
|
||||
// add kiosks here e.g.:
|
||||
try {
|
||||
list.addKioskEntry(
|
||||
(streamingService, url, id) -> new YoutubeMusicTrendingExtractor(
|
||||
YoutubeService.this,
|
||||
new YoutubeMusicTrendingLinkHandlerFactory().fromUrl(url),
|
||||
id
|
||||
),
|
||||
new YoutubeMusicTrendingLinkHandlerFactory(),
|
||||
"Trending Music"
|
||||
);
|
||||
|
||||
list.addKioskEntry(
|
||||
(streamingService, url, id) -> new YoutubeTrendingExtractor(
|
||||
YoutubeService.this,
|
||||
|
@ -155,6 +167,7 @@ public class YoutubeService extends StreamingService {
|
|||
}
|
||||
|
||||
return list;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -59,7 +59,7 @@ public class YoutubeMusicTrendingExtractor extends KioskExtractor<StreamInfoItem
|
|||
// @formatter:off
|
||||
final byte[] body = JsonWriter.string(prepareDesktopJsonBuilder(getExtractorLocalization(),
|
||||
getExtractorContentCountry())
|
||||
.value("browseId", "FEtrending")
|
||||
.value("browseId", "MUtrending")
|
||||
.done())
|
||||
.getBytes(UTF_8);
|
||||
// @formatter:on
|
||||
|
@ -104,6 +104,7 @@ public class YoutubeMusicTrendingExtractor extends KioskExtractor<StreamInfoItem
|
|||
.map(JsonObject.class::cast)
|
||||
// Filter Trending shorts and Recently trending sections
|
||||
.filter(content -> content.has("richItemRenderer"))
|
||||
// .filter(shelfRenderer -> !shelfRenderer.has("music"))
|
||||
.map(content -> content.getObject("richItemRenderer")
|
||||
.getObject("content")
|
||||
.getObject("videoRenderer"))
|
||||
|
@ -124,6 +125,7 @@ public class YoutubeMusicTrendingExtractor extends KioskExtractor<StreamInfoItem
|
|||
// Filter Trending shorts and Recently trending sections which have a title,
|
||||
// contrary to normal trends
|
||||
.filter(shelfRenderer -> !shelfRenderer.has("title"))
|
||||
// .filter(shelfRenderer -> !shelfRenderer.has("music"))
|
||||
.flatMap(shelfRenderer -> shelfRenderer.getObject("content")
|
||||
.getObject("expandedShelfContentsRenderer")
|
||||
.getArray("items")
|
||||
|
|
|
@ -0,0 +1,107 @@
|
|||
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import org.schabi.newpipe.extractor.exceptions.ContentNotSupportedException;
|
||||
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
||||
import org.schabi.newpipe.extractor.linkhandler.LinkHandler;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
|
||||
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandlerFactory;
|
||||
import org.schabi.newpipe.extractor.services.youtube.YoutubeParsingHelper;
|
||||
import org.schabi.newpipe.extractor.utils.Utils;
|
||||
|
||||
public final class YoutubeMusicTrendingLinkHandlerFactory extends ListLinkHandlerFactory {
|
||||
|
||||
private static final YoutubeMusicTrendingLinkHandlerFactory INSTANCE =
|
||||
new YoutubeMusicTrendingLinkHandlerFactory();
|
||||
|
||||
public YoutubeMusicTrendingLinkHandlerFactory() {
|
||||
}
|
||||
|
||||
public static YoutubeMusicTrendingLinkHandlerFactory getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUrl(final String id, final List<String> contentFilters,
|
||||
final String sortFilter) {
|
||||
return "https://www.youtube.com/feed/trending?bp=4gINGgt5dG1hX2NoYXJ0cw%3D%3D";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId(final String url) throws ParsingException {
|
||||
try {
|
||||
final URL urlObj = Utils.stringToURL(url);
|
||||
|
||||
if (!Utils.isHTTP(urlObj) || !(YoutubeParsingHelper.isYoutubeURL(urlObj)
|
||||
|| YoutubeParsingHelper.isInvidioURL(urlObj))) {
|
||||
throw new ParsingException("the url given is not a YouTube-URL");
|
||||
}
|
||||
|
||||
final String path = urlObj.getPath();
|
||||
if (!path.equals("/watch") && !path.equals("/playlist") && !path.equals("/feed/trending")) {
|
||||
throw new ParsingException("the url given is neither a video nor a playlist URL");
|
||||
}
|
||||
|
||||
final String listID = Utils.getQueryValue(urlObj, "list");
|
||||
|
||||
if (listID == null) {
|
||||
throw new ParsingException("the URL given does not include a playlist");
|
||||
}
|
||||
|
||||
if (!listID.matches("[a-zA-Z0-9_-]{10,}")) {
|
||||
throw new ParsingException(
|
||||
"the list-ID given in the URL does not match the list pattern");
|
||||
}
|
||||
|
||||
if (YoutubeParsingHelper.isYoutubeChannelMixId(listID)
|
||||
&& Utils.getQueryValue(urlObj, "v") == null) {
|
||||
// Video id can't be determined from the channel mix id.
|
||||
// See YoutubeParsingHelper#extractVideoIdFromMixId
|
||||
throw new ContentNotSupportedException(
|
||||
"Channel Mix without a video id are not supported");
|
||||
}
|
||||
|
||||
return listID;
|
||||
} catch (final Exception exception) {
|
||||
throw new ParsingException("Error could not parse URL: " + exception.getMessage(),
|
||||
exception);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onAcceptUrl(final String url) {
|
||||
try {
|
||||
getId(url);
|
||||
} catch (final ParsingException e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* If it is a mix (auto-generated playlist) URL, return a {@link LinkHandler} where the URL is
|
||||
* like {@code https://youtube.com/watch?v=videoId&list=playlistId}
|
||||
* <p>Otherwise use super</p>
|
||||
*/
|
||||
@Override
|
||||
public ListLinkHandler fromUrl(final String url) throws ParsingException {
|
||||
try {
|
||||
final URL urlObj = Utils.stringToURL(url);
|
||||
final String listID = Utils.getQueryValue(urlObj, "list");
|
||||
if (listID != null && YoutubeParsingHelper.isYoutubeMixId(listID)) {
|
||||
String videoID = Utils.getQueryValue(urlObj, "v");
|
||||
if (videoID == null) {
|
||||
videoID = YoutubeParsingHelper.extractVideoIdFromMixId(listID);
|
||||
}
|
||||
final String newUrl = "https://www.youtube.com/feed/trending?bp=4gINGgt5dG1hX2NoYXJ0cw%3D%3D";
|
||||
return new ListLinkHandler(new LinkHandler(url, newUrl, listID));
|
||||
}
|
||||
} catch (final MalformedURLException exception) {
|
||||
throw new ParsingException("Error could not parse URL: " + exception.getMessage(),
|
||||
exception);
|
||||
}
|
||||
return super.fromUrl(url);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue