Skip to content

Commit

Permalink
rss fix: go back to v3 for RSS (#3023)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzarebczan authored Nov 16, 2023
1 parent f2eec14 commit c704568
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions web/src/rss.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
const { fetchStreamUrl } = require('./fetchStreamUrl');
const { lbryProxy: Lbry } = require('../lbry');
const { URL, SITE_NAME, PROXY_URL } = require('../../config.js');
const Mime = require('mime-types');
const Rss = require('rss');
const moment = require('moment');
const { generateContentUrl } = require('./fetchStreamUrl');
Lbry.setDaemonConnectionString(PROXY_URL);

const NUM_ENTRIES = 500;
Expand Down Expand Up @@ -76,37 +75,41 @@ function encodeWithSpecialCharEncode(string) {
* @param claims Array of freaking claims.
* @returns {Array<{status, value}> | null}
*/
async function fetchStreamUrls(claims) {
return Promise.allSettled(claims.map((c) => fetchStreamUrl(c.name, c.claim_id)))
.then((results) => results)
.catch(() => null);
function fetchStreamUrls(claims) {
try {
const results = claims.map((c) => generateContentUrl(c));
return results;
} catch (error) {
console.error(error); // eslint-disable-line no-console
return null;
}
}

async function generateEnclosureForClaimContent(claim, streamUrl) {
function generateEnclosureForClaimContent(claim, streamUrl) {
const value = claim.value;
if (!value || !value.stream_type) {
return undefined;
}

const fileExt = value.source && value.source.media_type && '.' + Mime.extension(value.source.media_type);
// const fileExt = value.source && value.source.media_type && '.' + Mime.extension(value.source.media_type);

switch (value.stream_type) {
case 'video':
return {
url: streamUrl + (streamUrl.endsWith('.mp4') ? '' : fileExt || '.mp4'),
url: streamUrl,
type: (value.source && value.source.media_type) || 'video/mp4',
size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback.
};

case 'audio':
return {
url: streamUrl + (streamUrl.endsWith('.mp3') ? '' : fileExt || '.mp3'),
url: streamUrl,
type: (value.source && value.source.media_type) || 'audio/mpeg',
size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback.
};
case 'image':
return {
url: streamUrl + (streamUrl.endsWith('.jpg') ? '' : fileExt || '.jpg'),
url: streamUrl,
type: (value.source && value.source.media_type) || 'image/jpeg',
size: (value.source && value.source.size) || 0, // Per spec, 0 is a valid fallback.
};
Expand Down Expand Up @@ -266,7 +269,7 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) {
});

// --- Parallel pre-fetch of stream url ---
const streamUrls = await fetchStreamUrls(claimsInChannel);
const streamUrls = fetchStreamUrls(claimsInChannel);

// --- Content ---
for (let i = 0; i < claimsInChannel.length; ++i) {
Expand All @@ -283,7 +286,6 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) {
c.value && c.value.release_time ? c.value.release_time * 1000 : c.meta && c.meta.creation_timestamp * 1000;

const claimStreamUrl = streamUrls ? streamUrls[i] : '';
const streamUrl = claimStreamUrl.status === 'fulfilled' ? claimStreamUrl.value : '';

feed.item({
title: title,
Expand All @@ -292,7 +294,7 @@ async function generateFeed(feedLink, channelClaim, claimsInChannel) {
guid: undefined, // defaults to 'url'
author: undefined, // defaults feed author property
date: new Date(date),
enclosure: await generateEnclosureForClaimContent(c, streamUrl),
enclosure: generateEnclosureForClaimContent(c, claimStreamUrl),
custom_elements: [
{ 'itunes:title': title },
{ 'itunes:author': channelTitle },
Expand Down

0 comments on commit c704568

Please sign in to comment.