2222import org .apache .commons .lang3 .StringUtils ;
2323import org .hibernate .Session ;
2424import org .hibernate .StatelessSession ;
25+ import org .schabi .newpipe .extractor .channel .ChannelInfo ;
2526
2627import java .io .IOException ;
2728import java .util .*;
@@ -236,11 +237,11 @@ public static byte[] unauthenticatedFeedResponse(String[] channelIds) throws Exc
236237
237238 public static byte [] unauthenticatedFeedResponseRSS (String [] channelIds ) throws Exception {
238239
239- Set <String > filtered = Arrays .stream (channelIds )
240+ Set <String > filteredChannels = Arrays .stream (channelIds )
240241 .filter (ChannelHelpers ::isValidId )
241242 .collect (Collectors .toUnmodifiableSet ());
242243
243- if (filtered .isEmpty ())
244+ if (filteredChannels .isEmpty ())
244245 ExceptionHandler .throwErrorResponse (new InvalidRequestResponse ("No valid channel IDs provided" ));
245246
246247 try (StatelessSession s = DatabaseSessionFactory .createStatelessSession ()) {
@@ -254,7 +255,7 @@ public static byte[] unauthenticatedFeedResponseRSS(String[] channelIds) throws
254255
255256 criteria .select (root )
256257 .where (cb .and (
257- root .get ("channel" ).get ("id" ).in (filtered )
258+ root .get ("channel" ).get ("id" ).in (filteredChannels )
258259 ))
259260 .orderBy (cb .desc (root .get ("uploaded" )));
260261
@@ -276,22 +277,28 @@ public static byte[] unauthenticatedFeedResponseRSS(String[] channelIds) throws
276277 var channel = video .getChannel ();
277278 SyndEntry entry = ChannelHelpers .createEntry (video , channel );
278279 entries .add (entry );
280+ }
281+
282+ if (filteredChannels .size () == 1 ) {
283+ if (!videos .isEmpty ()) {
284+ ChannelHelpers .addChannelInformation (feed , videos .get (0 ).getChannel ());
285+ } else {
286+ String channelId = filteredChannels .stream ().findFirst ().get ();
287+ final ChannelInfo info = ChannelInfo .getInfo ("https://youtube.com/channel/" + channelId );
288+ var channel = DatabaseHelper .getChannelFromId (channelId );
279289
280- if (filtered .size () == 1 ) {
281- feed .setTitle ("Piped - " + channel .getUploader ());
282- SyndImage channelIcon = new SyndImageImpl ();
283- channelIcon .setLink (Constants .FRONTEND_URL + "/channel/" + channel .getUploaderId ());
284- channelIcon .setTitle (channel .getUploader ());
285- channelIcon .setUrl (rewriteURL (channel .getUploaderAvatar ()));
286- feed .setIcon (channelIcon );
287- feed .setImage (channelIcon );
290+ if (channel == null ) channel = new Channel ();
291+
292+ ChannelHelpers .updateChannel (s , channel , StringUtils .abbreviate (info .getName (), 100 ), info .getAvatars ().isEmpty () ? null : info .getAvatars ().getLast ().getUrl (), info .isVerified ());
293+
294+ ChannelHelpers .addChannelInformation (feed , channel );
288295 }
289296 }
290297
291298 feed .setEntries (entries );
292299
293- updateSubscribedTime (filtered );
294- addMissingChannels (filtered );
300+ updateSubscribedTime (filteredChannels );
301+ addMissingChannels (filteredChannels );
295302
296303 return new SyndFeedOutput ().outputString (feed ).getBytes (UTF_8 );
297304 }
0 commit comments