GoogleVideo: generate instead of fetch the content url (#1691)

Seeing performance issues.
This commit is contained in:
infinite-persistence 2022-06-15 18:54:53 +08:00 committed by GitHub
parent bd9a6ac2bb
commit b9af50dede
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 30 additions and 6 deletions

View file

@ -29,6 +29,7 @@ THUMBNAIL_WIDTH=390
THUMBNAIL_WIDTH_MOBILE=900
THUMBNAIL_QUALITY=85
THUMBNAIL_CDN_SIZE_LIMIT_BYTES=5242880
PLAYER_SERVER=https://player.odycdn.com
WELCOME_VERSION=1.0
# --- Stripe ---

View file

@ -31,6 +31,7 @@ const config = {
THUMBNAIL_WIDTH_MOBILE: process.env.THUMBNAIL_WIDTH_MOBILE,
THUMBNAIL_QUALITY: process.env.THUMBNAIL_QUALITY,
THUMBNAIL_CDN_SIZE_LIMIT_BYTES: process.env.THUMBNAIL_CDN_SIZE_LIMIT_BYTES,
PLAYER_SERVER: process.env.PLAYER_SERVER,
SITE_TITLE: process.env.SITE_TITLE,
SITE_NAME: process.env.SITE_NAME,
SITE_DESCRIPTION: process.env.SITE_DESCRIPTION,

View file

@ -1,3 +1,5 @@
const Mime = require('mime-types');
const { PLAYER_SERVER } = require('../../config.js');
const { lbryProxy: Lbry } = require('../lbry');
const { buildURI } = require('./lbryURI');
@ -10,6 +12,30 @@ async function fetchStreamUrl(claimName, claimId) {
});
}
/**
* Direct URL to the content's bits without redirects.
*
* Move back to 'utils/web' when `fetchStreamUrl` is no longer needed.
*
* @param claim
*/
function generateContentUrl(claim) {
const streamUrl = (claim) => {
// Hardcoded version of fetchStreamUrl().
return `${PLAYER_SERVER}/api/v3/streams/free/${claim.name}/${claim.claim_id}`;
};
const value = claim?.value;
if (value?.source?.media_type && value?.source?.sd_hash) {
const fileExt = `.${Mime.extension(value.source.media_type)}`;
const sdHash = value.source.sd_hash.slice(0, 6);
return `${streamUrl(claim)}/${sdHash}${fileExt}`;
}
return streamUrl(claim);
}
module.exports = {
fetchStreamUrl,
generateContentUrl,
};

View file

@ -1,9 +1,8 @@
const Mime = require('mime-types');
const moment = require('moment');
const removeMd = require('remove-markdown');
// TODO: fix relative path for server
const { fetchStreamUrl } = require('../fetchStreamUrl');
const { generateContentUrl } = require('../fetchStreamUrl');
const { parseURI } = require('../lbryURI');
const { OG_IMAGE_URL, SITE_NAME, URL } = require('../../../config.js');
const { generateEmbedUrl, getThumbnailCdnUrl, escapeHtmlProperty } = require('../../../ui/util/web');
@ -98,10 +97,7 @@ async function buildGoogleVideoMetadata(uri, claim) {
}
const claimThumbnail = escapeHtmlProperty(thumbnail) || getThumbnailCdnUrl(OG_IMAGE_URL) || `${URL}/public/v2-og.png`;
const fileExt = value.source && value.source.media_type && '.' + Mime.extension(value.source.media_type);
const claimStreamUrl =
(await fetchStreamUrl(claim.name, claim.claim_id)).replace('/v4/', '/v3/') + (fileExt || '.mp4'); // v3 = mp4 always, v4 may redirect to m3u8;
const claimStreamUrl = generateContentUrl(claim);
// https://developers.google.com/search/docs/data-types/video
const googleVideoMetadata = {