Merge pull request #399 from TeamPiped/shorts-api

Add isShort field to StreamInfo.
This commit is contained in:
Kavin 2022-10-27 10:28:32 +01:00 committed by GitHub
commit 2cc9631856
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 9 deletions

View File

@ -16,7 +16,7 @@ dependencies {
implementation 'it.unimi.dsi:fastutil-core:8.5.9' implementation 'it.unimi.dsi:fastutil-core:8.5.9'
implementation 'commons-codec:commons-codec:1.15' implementation 'commons-codec:commons-codec:1.15'
implementation 'org.bouncycastle:bcprov-jdk15on:1.70' implementation 'org.bouncycastle:bcprov-jdk15on:1.70'
implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:2e9763d4d2e1e11a885c99291cb3c6cf2a349617' implementation 'com.github.FireMasterK.NewPipeExtractor:NewPipeExtractor:05987f18894d023b7f7f4c2556534971b2a8b810'
implementation 'com.github.FireMasterK:nanojson:5df3e81e87b791d01f132f376e4b7d4a1780f346' implementation 'com.github.FireMasterK:nanojson:5df3e81e87b791d01f132f376e4b7d4a1780f346'
implementation 'com.fasterxml.jackson.core:jackson-core:2.13.4' implementation 'com.fasterxml.jackson.core:jackson-core:2.13.4'
implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.4' implementation 'com.fasterxml.jackson.core:jackson-annotations:2.13.4'

View File

@ -384,7 +384,7 @@ public class ResponseHelper {
var channel = video.getChannel(); var channel = video.getChannel();
relatedStreams.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(), rewriteURL(video.getThumbnail()), channel.getUploader(), relatedStreams.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(), rewriteURL(video.getThumbnail()), channel.getUploader(),
"/channel/" + channel.getUploaderId(), rewriteURL(channel.getUploaderAvatar()), null, null, "/channel/" + channel.getUploaderId(), rewriteURL(channel.getUploaderAvatar()), null, null,
video.getDuration(), -1, -1, channel.isVerified())); video.getDuration(), -1, -1, channel.isVerified(), false));
} }
final Playlist playlist = new Playlist(pl.getName(), rewriteURL(pl.getThumbnail()), null, null, pl.getOwner().getUsername(), final Playlist playlist = new Playlist(pl.getName(), rewriteURL(pl.getThumbnail()), null, null, pl.getOwner().getUsername(),
@ -908,7 +908,7 @@ public class ResponseHelper {
feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(), feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(),
rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(), rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(),
rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(), rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(),
video.getUploaded(), channel.isVerified())); video.getUploaded(), channel.isVerified(), video.isShort()));
} }
return mapper.writeValueAsBytes(feedItems); return mapper.writeValueAsBytes(feedItems);
@ -1019,7 +1019,7 @@ public class ResponseHelper {
feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(), feedItems.add(new StreamItem("/watch?v=" + video.getId(), video.getTitle(),
rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(), rewriteURL(video.getThumbnail()), channel.getUploader(), "/channel/" + channel.getUploaderId(),
rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(), rewriteURL(channel.getUploaderAvatar()), null, null, video.getDuration(), video.getViews(),
video.getUploaded(), channel.isVerified())); video.getUploaded(), channel.isVerified(), video.isShort()));
} }
updateSubscribedTime(filtered); updateSubscribedTime(filtered);
@ -1608,7 +1608,7 @@ public class ResponseHelper {
&& (System.currentTimeMillis() - infoTime) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION)) { && (System.currentTimeMillis() - infoTime) < TimeUnit.DAYS.toMillis(Constants.FEED_RETENTION)) {
video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(), video = new Video(info.getId(), info.getName(), info.getViewCount(), info.getDuration(),
Math.max(infoTime, time), info.getThumbnailUrl(), channel); Math.max(infoTime, time), info.getThumbnailUrl(), info.isShortFormContent(), channel);
try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) { try (StatelessSession s = DatabaseSessionFactory.createStatelessSession()) {
var tr = s.beginTransaction(); var tr = s.beginTransaction();
@ -1786,6 +1786,6 @@ public class ResponseHelper {
return new StreamItem(substringYouTube(item.getUrl()), item.getName(), rewriteURL(item.getThumbnailUrl()), return new StreamItem(substringYouTube(item.getUrl()), item.getName(), rewriteURL(item.getThumbnailUrl()),
item.getUploaderName(), substringYouTube(item.getUploaderUrl()), item.getUploaderName(), substringYouTube(item.getUploaderUrl()),
rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getShortDescription(), item.getDuration(), rewriteURL(item.getUploaderAvatarUrl()), item.getTextualUploadDate(), item.getShortDescription(), item.getDuration(),
item.getViewCount(), item.getUploadDate() != null ? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli() : -1, item.isUploaderVerified()); item.getViewCount(), item.getUploadDate() != null ? item.getUploadDate().offsetDateTime().toInstant().toEpochMilli() : -1, item.isUploaderVerified(), item.isShortFormContent());
} }
} }

View File

@ -2,12 +2,14 @@ package me.kavin.piped.utils.obj;
public class StreamItem { public class StreamItem {
private final String type = "video";
public String url, title, thumbnail, uploaderName, uploaderUrl, uploaderAvatar, uploadedDate, shortDescription; public String url, title, thumbnail, uploaderName, uploaderUrl, uploaderAvatar, uploadedDate, shortDescription;
public long duration, views, uploaded; public long duration, views, uploaded;
public boolean uploaderVerified; public boolean uploaderVerified, isShort;
public StreamItem(String url, String title, String thumbnail, String uploaderName, String uploaderUrl, public StreamItem(String url, String title, String thumbnail, String uploaderName, String uploaderUrl,
String uploaderAvatar, String uploadedDate, String shortDescription, long duration, long views, long uploaded, boolean uploaderVerified) { String uploaderAvatar, String uploadedDate, String shortDescription, long duration, long views, long uploaded, boolean uploaderVerified, boolean isShort) {
this.url = url; this.url = url;
this.title = title; this.title = title;
this.thumbnail = thumbnail; this.thumbnail = thumbnail;
@ -20,5 +22,6 @@ public class StreamItem {
this.views = views; this.views = views;
this.uploaded = uploaded; this.uploaded = uploaded;
this.uploaderVerified = uploaderVerified; this.uploaderVerified = uploaderVerified;
this.isShort = isShort;
} }
} }

View File

@ -27,6 +27,9 @@ public class Video {
@Column(name = "thumbnail", length = 400) @Column(name = "thumbnail", length = 400)
private String thumbnail; private String thumbnail;
@Column(name = "is_short", nullable = false, columnDefinition = "boolean default false")
private boolean isShort;
@ManyToOne(fetch = FetchType.LAZY) @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "uploader_id", nullable = false) @JoinColumn(name = "uploader_id", nullable = false)
private Channel channel; private Channel channel;
@ -34,13 +37,14 @@ public class Video {
public Video() { public Video() {
} }
public Video(String id, String title, long views, long duration, long uploaded, String thumbnail, Channel channel) { public Video(String id, String title, long views, long duration, long uploaded, String thumbnail, boolean isShort, Channel channel) {
this.id = id; this.id = id;
this.title = title; this.title = title;
this.views = views; this.views = views;
this.duration = duration; this.duration = duration;
this.uploaded = uploaded; this.uploaded = uploaded;
this.thumbnail = thumbnail; this.thumbnail = thumbnail;
this.isShort = isShort;
this.channel = channel; this.channel = channel;
} }
@ -92,6 +96,14 @@ public class Video {
this.thumbnail = thumbnail; this.thumbnail = thumbnail;
} }
public boolean isShort() {
return isShort;
}
public void setShort(boolean aShort) {
isShort = aShort;
}
public Channel getChannel() { public Channel getChannel() {
return channel; return channel;
} }