Skip to content

Commit

Permalink
Update NewPipeExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
gzsombor committed Apr 6, 2024
1 parent 8d81303 commit fa1ce39
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ dependencies {

// implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:818745b7e4'
// implementation 'com.github.TeamNewPipe.NewPipeExtractor:NewPipeExtractor:v0.22.6'
implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:a473ed1be8'
implementation 'com.github.SkyTubeTeam.NewPipeExtractor:NewPipeExtractor:skytube-2024-04-06'

implementation ('com.github.SkyTubeTeam.components:okhttp-client:0.0.7') {
exclude group: 'com.github.SkyTubeTeam.NewPipeExtractor', module: 'extractor'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private List<YouTubePlaylist> getNextPlaylists() throws ExtractionException, IOE
return infoItems.stream()
.filter(PlaylistInfoItem.class::isInstance)
.map(PlaylistInfoItem.class::cast).map(item ->
new YouTubePlaylist(item.getUrl(), item.getName(), "", null, item.getStreamCount(), item.getThumbnailUrl(),
new YouTubePlaylist(item.getUrl(), item.getName(), "", null, item.getStreamCount(), NewPipeUtils.getThumbnailUrl(item),
channel)
).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ private YouTubeChannel createInternalChannel(ChannelExtractor extractor) throws
extractor.getId(),
extractor.getName(),
NewPipeUtils.filterHtml(extractor.getDescription()),
callParser(() -> extractor.getAvatarUrl(), null),
callParser(() -> extractor.getBannerUrl(), null),
callParser(() -> NewPipeUtils.getThumbnailUrl(extractor.getAvatars()), null),
callParser(() -> NewPipeUtils.getThumbnailUrl(extractor.getBanners()), null),
callParser(() -> extractor.getSubscriberCount(), -1L),
false,
0,
Expand Down Expand Up @@ -422,7 +422,7 @@ public YouTubeVideo getDetails(String videoId) throws ExtractionException, IOExc

YouTubeVideo video = new YouTubeVideo(extractor.getId(), extractor.getName(), NewPipeUtils.filterHtml(extractor.getDescription()),
extractor.getLength(), new YouTubeChannel(extractor.getUploaderUrl(), extractor.getUploaderName()),
viewCount, uploadDate.instant, uploadDate.exact, extractor.getThumbnailUrl());
viewCount, uploadDate.instant, uploadDate.exact, NewPipeUtils.getThumbnailUrl(extractor.getThumbnails()));
try {
video.setLikeDislikeCount(extractor.getLikeCount(), getDislikeCount(extractor, videoId));
} catch (ParsingException pe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@
*/
package free.rm.skytube.businessobjects.YouTube.newpipe;

import androidx.annotation.Nullable;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.safety.Safelist;
import org.schabi.newpipe.extractor.Image;
import org.schabi.newpipe.extractor.InfoItem;
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
import org.schabi.newpipe.extractor.stream.Description;

import java.util.Comparator;
import java.util.List;

public class NewPipeUtils {
private NewPipeUtils() {}

Expand All @@ -38,4 +46,13 @@ public static String filterHtml(Description description) {
return result;
}

@Nullable
public static String getThumbnailUrl(List<Image> images) {
return images.stream().max(Comparator.comparing(Image::getWidth)).map(Image::getUrl).orElse(null);
}

@Nullable
public static String getThumbnailUrl(InfoItem comment) {
return getThumbnailUrl(comment.getThumbnails());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected List<CardData> extract(ListExtractor.InfoItemsPage<? extends InfoItem>
"" /* description */,
null /* publishDate */,
playlistExtractor.getStreamCount(),
playlistExtractor.getThumbnailUrl(),
NewPipeUtils.getThumbnailUrl(playlistExtractor.getThumbnails()),
new YouTubeChannel(channelId, playlistExtractor.getUploaderName())
);
} catch (ParsingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ protected YouTubeVideo convert(StreamInfoItem item, String id) {
}

private CardData convert(PlaylistInfoItem playlistInfoItem, String id) {
return new YouTubePlaylist(id, playlistInfoItem.getName(), "", null, playlistInfoItem.getStreamCount(), playlistInfoItem.getThumbnailUrl(),
return new YouTubePlaylist(id, playlistInfoItem.getName(), "", null, playlistInfoItem.getStreamCount(), NewPipeUtils.getThumbnailUrl(playlistInfoItem),
null);
}

private CardData convert(ChannelInfoItem channelInfoItem) {
String url = channelInfoItem.getUrl();
String id = getId(url);
return new YouTubeChannel(id, channelInfoItem.getName(), channelInfoItem.getDescription(), channelInfoItem.getThumbnailUrl(), null,
return new YouTubeChannel(id, channelInfoItem.getName(), channelInfoItem.getDescription(), NewPipeUtils.getThumbnailUrl(channelInfoItem), null,
channelInfoItem.getSubscriberCount(), false, -1, System.currentTimeMillis(), null, Collections.emptyList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import free.rm.skytube.businessobjects.YouTube.newpipe.CommentPager;
import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeException;
import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeService;
import free.rm.skytube.businessobjects.YouTube.newpipe.NewPipeUtils;
import free.rm.skytube.databinding.CommentBinding;
import free.rm.skytube.gui.businessobjects.views.Linker;

Expand Down Expand Up @@ -281,7 +282,7 @@ protected void updateInfo(final CommentsInfoItem comment, boolean isTopLevelComm
binding.commentDateTextView.setText(comment.getTextualUploadDate());
binding.commentUpvotesTextView.setText(String.valueOf(comment.getLikeCount()));
Glide.with(context)
.load(comment.getThumbnailUrl())
.load(NewPipeUtils.getThumbnailUrl(comment))
.apply(new RequestOptions().placeholder(R.drawable.channel_thumbnail_default))
.into(binding.commentThumbnailImageView);

Expand Down

0 comments on commit fa1ce39

Please sign in to comment.