2018-07-13 18:02:40 +02:00
|
|
|
package org.schabi.newpipe.extractor.services.youtube.linkHandler;
|
2018-05-26 19:15:45 +02:00
|
|
|
|
2022-08-09 04:03:29 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.encodeUrlUtf8;
|
2022-07-28 04:19:21 +02:00
|
|
|
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
|
|
|
|
2018-05-26 19:15:45 +02:00
|
|
|
import org.schabi.newpipe.extractor.exceptions.ParsingException;
|
2018-07-13 18:02:40 +02:00
|
|
|
import org.schabi.newpipe.extractor.linkhandler.SearchQueryHandlerFactory;
|
2018-05-26 19:15:45 +02:00
|
|
|
|
|
|
|
import java.io.UnsupportedEncodingException;
|
2018-07-01 16:21:40 +02:00
|
|
|
import java.util.List;
|
2018-05-26 19:15:45 +02:00
|
|
|
|
2022-07-28 04:19:21 +02:00
|
|
|
import javax.annotation.Nonnull;
|
2021-02-07 22:12:22 +01:00
|
|
|
|
2022-03-18 15:09:06 +01:00
|
|
|
public final class YoutubeSearchQueryHandlerFactory extends SearchQueryHandlerFactory {
|
2018-05-26 19:15:45 +02:00
|
|
|
|
[YouTube] Add support for channel tabs and tags and age-restricted channels
Support of tags and videos, shorts, live, playlists and channels tabs has been
added for non-age restricted channels.
Age-restricted channels are now also supported and always returned the videos,
shorts and live tabs, accessible using system playlists. These tabs are the
only ones which can be accessed using YouTube's desktop website without being
logged-in.
The videos channel tab parameter has been updated to the one used by the
desktop website and when a channel extraction is fetched, this tab is returned
in the list of tabs as a cached one in the corresponding link handler.
Visitor data support per request has been added, as a valid visitor data is
required to fetch continuations with contents on the shorts tab. It is only
used in this case to enhance privacy.
A dedicated shorts UI elements (reelItemRenderers) extractor has been added,
YoutubeReelInfoItemExtractor. These elements do not provide the exact view
count, any uploader info (name, URL, avatar, verified status) and the upload
date.
All service's LinkHandlers are now using the singleton pattern and some code
has been also improved on the files changed.
Co-authored-by: ThetaDev <t.testboy@gmail.com>
Co-authored-by: Stypox <stypox@pm.me>
2023-07-14 23:46:48 +02:00
|
|
|
private static final YoutubeSearchQueryHandlerFactory INSTANCE =
|
|
|
|
new YoutubeSearchQueryHandlerFactory();
|
|
|
|
|
2020-03-17 11:33:39 +01:00
|
|
|
public static final String ALL = "all";
|
2018-07-19 16:06:44 +02:00
|
|
|
public static final String VIDEOS = "videos";
|
|
|
|
public static final String CHANNELS = "channels";
|
|
|
|
public static final String PLAYLISTS = "playlists";
|
2020-03-17 11:33:39 +01:00
|
|
|
|
|
|
|
public static final String MUSIC_SONGS = "music_songs";
|
|
|
|
public static final String MUSIC_VIDEOS = "music_videos";
|
|
|
|
public static final String MUSIC_ALBUMS = "music_albums";
|
|
|
|
public static final String MUSIC_PLAYLISTS = "music_playlists";
|
|
|
|
public static final String MUSIC_ARTISTS = "music_artists";
|
|
|
|
|
|
|
|
private static final String SEARCH_URL = "https://www.youtube.com/results?search_query=";
|
|
|
|
private static final String MUSIC_SEARCH_URL = "https://music.youtube.com/search?q=";
|
2018-05-26 19:15:45 +02:00
|
|
|
|
2021-07-09 18:23:46 +02:00
|
|
|
@Nonnull
|
2018-07-13 18:02:40 +02:00
|
|
|
public static YoutubeSearchQueryHandlerFactory getInstance() {
|
[YouTube] Add support for channel tabs and tags and age-restricted channels
Support of tags and videos, shorts, live, playlists and channels tabs has been
added for non-age restricted channels.
Age-restricted channels are now also supported and always returned the videos,
shorts and live tabs, accessible using system playlists. These tabs are the
only ones which can be accessed using YouTube's desktop website without being
logged-in.
The videos channel tab parameter has been updated to the one used by the
desktop website and when a channel extraction is fetched, this tab is returned
in the list of tabs as a cached one in the corresponding link handler.
Visitor data support per request has been added, as a valid visitor data is
required to fetch continuations with contents on the shorts tab. It is only
used in this case to enhance privacy.
A dedicated shorts UI elements (reelItemRenderers) extractor has been added,
YoutubeReelInfoItemExtractor. These elements do not provide the exact view
count, any uploader info (name, URL, avatar, verified status) and the upload
date.
All service's LinkHandlers are now using the singleton pattern and some code
has been also improved on the files changed.
Co-authored-by: ThetaDev <t.testboy@gmail.com>
Co-authored-by: Stypox <stypox@pm.me>
2023-07-14 23:46:48 +02:00
|
|
|
return INSTANCE;
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-07-09 18:23:46 +02:00
|
|
|
public String getUrl(final String searchString,
|
|
|
|
@Nonnull final List<String> contentFilters,
|
[YouTube] Add support for channel tabs and tags and age-restricted channels
Support of tags and videos, shorts, live, playlists and channels tabs has been
added for non-age restricted channels.
Age-restricted channels are now also supported and always returned the videos,
shorts and live tabs, accessible using system playlists. These tabs are the
only ones which can be accessed using YouTube's desktop website without being
logged-in.
The videos channel tab parameter has been updated to the one used by the
desktop website and when a channel extraction is fetched, this tab is returned
in the list of tabs as a cached one in the corresponding link handler.
Visitor data support per request has been added, as a valid visitor data is
required to fetch continuations with contents on the shorts tab. It is only
used in this case to enhance privacy.
A dedicated shorts UI elements (reelItemRenderers) extractor has been added,
YoutubeReelInfoItemExtractor. These elements do not provide the exact view
count, any uploader info (name, URL, avatar, verified status) and the upload
date.
All service's LinkHandlers are now using the singleton pattern and some code
has been also improved on the files changed.
Co-authored-by: ThetaDev <t.testboy@gmail.com>
Co-authored-by: Stypox <stypox@pm.me>
2023-07-14 23:46:48 +02:00
|
|
|
final String sortFilter)
|
|
|
|
throws ParsingException, UnsupportedOperationException {
|
2018-05-26 19:15:45 +02:00
|
|
|
try {
|
2021-03-14 00:43:57 +01:00
|
|
|
if (!contentFilters.isEmpty()) {
|
2021-07-09 18:23:46 +02:00
|
|
|
final String contentFilter = contentFilters.get(0);
|
2023-08-13 19:32:25 +02:00
|
|
|
if (contentFilter != null) {
|
|
|
|
switch (contentFilter) {
|
|
|
|
case VIDEOS:
|
|
|
|
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQAQ%253D%253D";
|
|
|
|
case CHANNELS:
|
|
|
|
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQAg%253D%253D";
|
|
|
|
case PLAYLISTS:
|
|
|
|
return SEARCH_URL + encodeUrlUtf8(searchString) + "&sp=EgIQAw%253D%253D";
|
|
|
|
case MUSIC_SONGS:
|
|
|
|
case MUSIC_VIDEOS:
|
|
|
|
case MUSIC_ALBUMS:
|
|
|
|
case MUSIC_PLAYLISTS:
|
|
|
|
case MUSIC_ARTISTS:
|
|
|
|
return MUSIC_SEARCH_URL + encodeUrlUtf8(searchString);
|
|
|
|
}
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-09 04:03:29 +02:00
|
|
|
return SEARCH_URL + encodeUrlUtf8(searchString);
|
2021-07-09 18:23:46 +02:00
|
|
|
} catch (final UnsupportedEncodingException e) {
|
2018-05-26 19:15:45 +02:00
|
|
|
throw new ParsingException("Could not encode query", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String[] getAvailableContentFilter() {
|
2020-02-08 23:58:46 +01:00
|
|
|
return new String[]{
|
2018-07-19 16:06:44 +02:00
|
|
|
ALL,
|
|
|
|
VIDEOS,
|
|
|
|
CHANNELS,
|
2020-03-17 11:33:39 +01:00
|
|
|
PLAYLISTS,
|
|
|
|
MUSIC_SONGS,
|
|
|
|
MUSIC_VIDEOS,
|
|
|
|
MUSIC_ALBUMS,
|
2020-04-01 10:28:55 +02:00
|
|
|
MUSIC_PLAYLISTS
|
2021-07-09 18:23:46 +02:00
|
|
|
// MUSIC_ARTISTS
|
2020-03-17 11:33:39 +01:00
|
|
|
};
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|
2021-04-09 17:00:38 +02:00
|
|
|
|
2021-07-09 18:23:46 +02:00
|
|
|
@Nonnull
|
2021-04-09 17:00:38 +02:00
|
|
|
public static String getSearchParameter(final String contentFilter) {
|
2022-03-18 15:09:06 +01:00
|
|
|
if (isNullOrEmpty(contentFilter)) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2021-06-06 15:40:45 +02:00
|
|
|
switch (contentFilter) {
|
2021-04-09 17:00:38 +02:00
|
|
|
case VIDEOS:
|
|
|
|
return "EgIQAQ%3D%3D";
|
|
|
|
case CHANNELS:
|
|
|
|
return "EgIQAg%3D%3D";
|
|
|
|
case PLAYLISTS:
|
|
|
|
return "EgIQAw%3D%3D";
|
|
|
|
case ALL:
|
|
|
|
case MUSIC_SONGS:
|
|
|
|
case MUSIC_VIDEOS:
|
|
|
|
case MUSIC_ALBUMS:
|
|
|
|
case MUSIC_PLAYLISTS:
|
|
|
|
case MUSIC_ARTISTS:
|
|
|
|
default:
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
2018-05-26 19:15:45 +02:00
|
|
|
}
|