mirror of
https://github.com/TeamPiped/Piped-Backend.git
synced 2024-12-13 05:40:30 +05:30
Small Java 17 improvements. (#337)
This commit is contained in:
parent
cca5441402
commit
adbd2b347f
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java: [ 11, 17 ]
|
java: [ 17 ]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
@ -57,5 +57,5 @@ jar {
|
|||||||
|
|
||||||
group = 'me.kavin.piped'
|
group = 'me.kavin.piped'
|
||||||
version = '1.0'
|
version = '1.0'
|
||||||
sourceCompatibility = JavaVersion.VERSION_11
|
sourceCompatibility = JavaVersion.VERSION_17
|
||||||
targetCompatibility = JavaVersion.VERSION_11
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
|
@ -8,6 +8,7 @@ import me.kavin.piped.utils.obj.db.*;
|
|||||||
import org.hibernate.SharedSessionContract;
|
import org.hibernate.SharedSessionContract;
|
||||||
import org.hibernate.StatelessSession;
|
import org.hibernate.StatelessSession;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
@ -55,7 +56,7 @@ public class DatabaseHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<Channel> getChannelsFromIds(SharedSessionContract s, List<String> id) {
|
public static List<Channel> getChannelsFromIds(SharedSessionContract s, Collection<String> id) {
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
CriteriaQuery<Channel> cr = cb.createQuery(Channel.class);
|
CriteriaQuery<Channel> cr = cb.createQuery(Channel.class);
|
||||||
Root<Channel> root = cr.from(Channel.class);
|
Root<Channel> root = cr.from(Channel.class);
|
||||||
@ -97,7 +98,7 @@ public class DatabaseHelper {
|
|||||||
return s.createQuery(cr).uniqueResult();
|
return s.createQuery(cr).uniqueResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<PlaylistVideo> getPlaylistVideosFromIds(SharedSessionContract s, List<String> id) {
|
public static List<PlaylistVideo> getPlaylistVideosFromIds(SharedSessionContract s, Collection<String> id) {
|
||||||
CriteriaBuilder cb = s.getCriteriaBuilder();
|
CriteriaBuilder cb = s.getCriteriaBuilder();
|
||||||
CriteriaQuery<PlaylistVideo> cr = cb.createQuery(PlaylistVideo.class);
|
CriteriaQuery<PlaylistVideo> cr = cb.createQuery(PlaylistVideo.class);
|
||||||
Root<PlaylistVideo> root = cr.from(PlaylistVideo.class);
|
Root<PlaylistVideo> root = cr.from(PlaylistVideo.class);
|
||||||
|
@ -116,7 +116,7 @@ public class ResponseHelper {
|
|||||||
segment.getStartTimeSeconds())));
|
segment.getStartTimeSeconds())));
|
||||||
|
|
||||||
info.getSubtitles()
|
info.getSubtitles()
|
||||||
.forEach(subtitle -> subtitles.add(new Subtitle(rewriteURL(subtitle.getUrl()),
|
.forEach(subtitle -> subtitles.add(new Subtitle(rewriteURL(subtitle.getContent()),
|
||||||
subtitle.getFormat().getMimeType(), subtitle.getDisplayLanguageName(),
|
subtitle.getFormat().getMimeType(), subtitle.getDisplayLanguageName(),
|
||||||
subtitle.getLanguageTag(), subtitle.isAutoGenerated())));
|
subtitle.getLanguageTag(), subtitle.isAutoGenerated())));
|
||||||
|
|
||||||
@ -137,17 +137,17 @@ public class ResponseHelper {
|
|||||||
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
boolean livestream = info.getStreamType() == StreamType.LIVE_STREAM;
|
||||||
|
|
||||||
if (!livestream) {
|
if (!livestream) {
|
||||||
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteVideoURL(stream.getUrl()),
|
info.getVideoOnlyStreams().forEach(stream -> videoStreams.add(new PipedStream(rewriteVideoURL(stream.getContent()),
|
||||||
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,
|
String.valueOf(stream.getFormat()), stream.getResolution(), stream.getFormat().getMimeType(), true,
|
||||||
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
|
stream.getBitrate(), stream.getInitStart(), stream.getInitEnd(), stream.getIndexStart(),
|
||||||
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), 30)));
|
stream.getIndexEnd(), stream.getCodec(), stream.getWidth(), stream.getHeight(), 30)));
|
||||||
info.getVideoStreams()
|
info.getVideoStreams()
|
||||||
.forEach(stream -> videoStreams
|
.forEach(stream -> videoStreams
|
||||||
.add(new PipedStream(rewriteVideoURL(stream.getUrl()), String.valueOf(stream.getFormat()),
|
.add(new PipedStream(rewriteVideoURL(stream.getContent()), String.valueOf(stream.getFormat()),
|
||||||
stream.getResolution(), stream.getFormat().getMimeType(), false)));
|
stream.getResolution(), stream.getFormat().getMimeType(), false)));
|
||||||
|
|
||||||
info.getAudioStreams()
|
info.getAudioStreams()
|
||||||
.forEach(stream -> audioStreams.add(new PipedStream(rewriteVideoURL(stream.getUrl()),
|
.forEach(stream -> audioStreams.add(new PipedStream(rewriteVideoURL(stream.getContent()),
|
||||||
String.valueOf(stream.getFormat()), stream.getAverageBitrate() + " kbps",
|
String.valueOf(stream.getFormat()), stream.getAverageBitrate() + " kbps",
|
||||||
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
|
stream.getFormat().getMimeType(), false, stream.getBitrate(), stream.getInitStart(),
|
||||||
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getCodec())));
|
stream.getInitEnd(), stream.getIndexStart(), stream.getIndexEnd(), stream.getCodec())));
|
||||||
@ -528,22 +528,18 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
info.getRelatedItems().forEach(item -> {
|
info.getRelatedItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM -> items.add(collectRelatedStream(item));
|
||||||
items.add(collectRelatedStream(item));
|
case CHANNEL -> {
|
||||||
break;
|
|
||||||
case CHANNEL:
|
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
substringYouTube(item.getUrl()), channel.getDescription(), channel.getSubscriberCount(),
|
substringYouTube(item.getUrl()), channel.getDescription(), channel.getSubscriberCount(),
|
||||||
channel.getStreamCount(), channel.isVerified()));
|
channel.getStreamCount(), channel.isVerified()));
|
||||||
break;
|
}
|
||||||
case PLAYLIST:
|
case PLAYLIST -> {
|
||||||
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
||||||
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
substringYouTube(item.getUrl()), playlist.getUploaderName(), playlist.getStreamCount()));
|
substringYouTube(item.getUrl()), playlist.getUploaderName(), playlist.getStreamCount()));
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -569,22 +565,18 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
pages.getItems().forEach(item -> {
|
pages.getItems().forEach(item -> {
|
||||||
switch (item.getInfoType()) {
|
switch (item.getInfoType()) {
|
||||||
case STREAM:
|
case STREAM -> items.add(collectRelatedStream(item));
|
||||||
items.add(collectRelatedStream(item));
|
case CHANNEL -> {
|
||||||
break;
|
|
||||||
case CHANNEL:
|
|
||||||
ChannelInfoItem channel = (ChannelInfoItem) item;
|
ChannelInfoItem channel = (ChannelInfoItem) item;
|
||||||
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchChannel(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
substringYouTube(item.getUrl()), channel.getDescription(), channel.getSubscriberCount(),
|
substringYouTube(item.getUrl()), channel.getDescription(), channel.getSubscriberCount(),
|
||||||
channel.getStreamCount(), channel.isVerified()));
|
channel.getStreamCount(), channel.isVerified()));
|
||||||
break;
|
}
|
||||||
case PLAYLIST:
|
case PLAYLIST -> {
|
||||||
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
PlaylistInfoItem playlist = (PlaylistInfoItem) item;
|
||||||
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
items.add(new SearchPlaylist(item.getName(), rewriteURL(item.getThumbnailUrl()),
|
||||||
substringYouTube(item.getUrl()), playlist.getUploaderName(), playlist.getStreamCount()));
|
substringYouTube(item.getUrl()), playlist.getUploaderName(), playlist.getStreamCount()));
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -1031,8 +1023,6 @@ public class ResponseHelper {
|
|||||||
))
|
))
|
||||||
.orderBy(cb.desc(root.get("uploaded")));
|
.orderBy(cb.desc(root.get("uploaded")));
|
||||||
|
|
||||||
List<StreamItem> feedItems = new ObjectArrayList<>();
|
|
||||||
|
|
||||||
List<Video> videos = s.createQuery(criteria)
|
List<Video> videos = s.createQuery(criteria)
|
||||||
.setTimeout(20)
|
.setTimeout(20)
|
||||||
.setMaxResults(100)
|
.setMaxResults(100)
|
||||||
@ -1123,9 +1113,7 @@ public class ResponseHelper {
|
|||||||
|
|
||||||
channelIds.stream()
|
channelIds.stream()
|
||||||
.filter(id -> !existing.contains(id))
|
.filter(id -> !existing.contains(id))
|
||||||
.forEach(id -> Multithreading.runAsyncLimited(() -> {
|
.forEach(id -> Multithreading.runAsyncLimited(() -> saveChannel(id)));
|
||||||
saveChannel(id);
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1209,7 +1197,7 @@ public class ResponseHelper {
|
|||||||
.sorted(Comparator.comparing(me.kavin.piped.utils.obj.db.Channel::getUploader, String.CASE_INSENSITIVE_ORDER))
|
.sorted(Comparator.comparing(me.kavin.piped.utils.obj.db.Channel::getUploader, String.CASE_INSENSITIVE_ORDER))
|
||||||
.map(channel -> new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
.map(channel -> new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
||||||
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified()))
|
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified()))
|
||||||
.collect(Collectors.toUnmodifiableList());
|
.toList();
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(subscriptionItems);
|
return mapper.writeValueAsBytes(subscriptionItems);
|
||||||
}
|
}
|
||||||
@ -1242,7 +1230,7 @@ public class ResponseHelper {
|
|||||||
.sorted(Comparator.comparing(me.kavin.piped.utils.obj.db.Channel::getUploader, String.CASE_INSENSITIVE_ORDER))
|
.sorted(Comparator.comparing(me.kavin.piped.utils.obj.db.Channel::getUploader, String.CASE_INSENSITIVE_ORDER))
|
||||||
.map(channel -> new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
.map(channel -> new SubscriptionChannel("/channel/" + channel.getUploaderId(),
|
||||||
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified()))
|
channel.getUploader(), rewriteURL(channel.getUploaderAvatar()), channel.isVerified()))
|
||||||
.collect(Collectors.toUnmodifiableList());
|
.toList();
|
||||||
|
|
||||||
return mapper.writeValueAsBytes(subscriptionItems);
|
return mapper.writeValueAsBytes(subscriptionItems);
|
||||||
}
|
}
|
||||||
@ -1353,18 +1341,16 @@ public class ResponseHelper {
|
|||||||
nextpage = page.getNextPage();
|
nextpage = page.getNextPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> channelIds = videos.stream()
|
Set<String> channelIds = videos.stream()
|
||||||
.map(StreamInfoItem::getUploaderUrl)
|
.map(StreamInfoItem::getUploaderUrl)
|
||||||
.map(URLUtils::substringYouTube)
|
.map(URLUtils::substringYouTube)
|
||||||
.map(s -> s.substring("/channel/".length()))
|
.map(s -> s.substring("/channel/".length()))
|
||||||
.collect(Collectors.toUnmodifiableSet())
|
.collect(Collectors.toUnmodifiableSet());
|
||||||
.stream()
|
|
||||||
.collect(Collectors.toUnmodifiableList());
|
|
||||||
List<String> videoIds = videos.stream()
|
List<String> videoIds = videos.stream()
|
||||||
.map(StreamInfoItem::getUrl)
|
.map(StreamInfoItem::getUrl)
|
||||||
.map(URLUtils::substringYouTube)
|
.map(URLUtils::substringYouTube)
|
||||||
.map(s -> s.substring("/watch?v=".length()))
|
.map(s -> s.substring("/watch?v=".length()))
|
||||||
.collect(Collectors.toUnmodifiableList());
|
.toList();
|
||||||
|
|
||||||
try (Session s = DatabaseSessionFactory.createSession()) {
|
try (Session s = DatabaseSessionFactory.createSession()) {
|
||||||
|
|
||||||
@ -1380,10 +1366,10 @@ public class ResponseHelper {
|
|||||||
Map<String, PlaylistVideo> videoMap = new Object2ObjectOpenHashMap<>();
|
Map<String, PlaylistVideo> videoMap = new Object2ObjectOpenHashMap<>();
|
||||||
|
|
||||||
var playlistVideos = DatabaseHelper.getPlaylistVideosFromIds(s, videoIds);
|
var playlistVideos = DatabaseHelper.getPlaylistVideosFromIds(s, videoIds);
|
||||||
videoIds.forEach(id -> {
|
videoIds.forEach(id ->
|
||||||
playlistVideos.stream().filter(video -> video.getId().equals(id)).findFirst()
|
playlistVideos.stream().filter(video -> video.getId().equals(id)).findFirst()
|
||||||
.ifPresent(playlistVideo -> videoMap.put(id, playlistVideo));
|
.ifPresent(playlistVideo -> videoMap.put(id, playlistVideo))
|
||||||
});
|
);
|
||||||
|
|
||||||
videos.forEach(video -> {
|
videos.forEach(video -> {
|
||||||
var channelId = substringYouTube(video.getUploaderUrl()).substring("/channel/".length());
|
var channelId = substringYouTube(video.getUploaderUrl()).substring("/channel/".length());
|
||||||
|
Loading…
Reference in New Issue
Block a user