GoogleVideo: generate instead of fetch the content url (#1691)
Seeing performance issues.
This commit is contained in:
parent
bd9a6ac2bb
commit
b9af50dede
4 changed files with 30 additions and 6 deletions
|
@ -29,6 +29,7 @@ THUMBNAIL_WIDTH=390
|
||||||
THUMBNAIL_WIDTH_MOBILE=900
|
THUMBNAIL_WIDTH_MOBILE=900
|
||||||
THUMBNAIL_QUALITY=85
|
THUMBNAIL_QUALITY=85
|
||||||
THUMBNAIL_CDN_SIZE_LIMIT_BYTES=5242880
|
THUMBNAIL_CDN_SIZE_LIMIT_BYTES=5242880
|
||||||
|
PLAYER_SERVER=https://player.odycdn.com
|
||||||
WELCOME_VERSION=1.0
|
WELCOME_VERSION=1.0
|
||||||
|
|
||||||
# --- Stripe ---
|
# --- Stripe ---
|
||||||
|
|
|
@ -31,6 +31,7 @@ const config = {
|
||||||
THUMBNAIL_WIDTH_MOBILE: process.env.THUMBNAIL_WIDTH_MOBILE,
|
THUMBNAIL_WIDTH_MOBILE: process.env.THUMBNAIL_WIDTH_MOBILE,
|
||||||
THUMBNAIL_QUALITY: process.env.THUMBNAIL_QUALITY,
|
THUMBNAIL_QUALITY: process.env.THUMBNAIL_QUALITY,
|
||||||
THUMBNAIL_CDN_SIZE_LIMIT_BYTES: process.env.THUMBNAIL_CDN_SIZE_LIMIT_BYTES,
|
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_TITLE: process.env.SITE_TITLE,
|
||||||
SITE_NAME: process.env.SITE_NAME,
|
SITE_NAME: process.env.SITE_NAME,
|
||||||
SITE_DESCRIPTION: process.env.SITE_DESCRIPTION,
|
SITE_DESCRIPTION: process.env.SITE_DESCRIPTION,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
const Mime = require('mime-types');
|
||||||
|
const { PLAYER_SERVER } = require('../../config.js');
|
||||||
const { lbryProxy: Lbry } = require('../lbry');
|
const { lbryProxy: Lbry } = require('../lbry');
|
||||||
const { buildURI } = require('./lbryURI');
|
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 = {
|
module.exports = {
|
||||||
fetchStreamUrl,
|
fetchStreamUrl,
|
||||||
|
generateContentUrl,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
const Mime = require('mime-types');
|
|
||||||
const moment = require('moment');
|
const moment = require('moment');
|
||||||
const removeMd = require('remove-markdown');
|
const removeMd = require('remove-markdown');
|
||||||
|
|
||||||
// TODO: fix relative path for server
|
// TODO: fix relative path for server
|
||||||
const { fetchStreamUrl } = require('../fetchStreamUrl');
|
const { generateContentUrl } = require('../fetchStreamUrl');
|
||||||
const { parseURI } = require('../lbryURI');
|
const { parseURI } = require('../lbryURI');
|
||||||
const { OG_IMAGE_URL, SITE_NAME, URL } = require('../../../config.js');
|
const { OG_IMAGE_URL, SITE_NAME, URL } = require('../../../config.js');
|
||||||
const { generateEmbedUrl, getThumbnailCdnUrl, escapeHtmlProperty } = require('../../../ui/util/web');
|
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 claimThumbnail = escapeHtmlProperty(thumbnail) || getThumbnailCdnUrl(OG_IMAGE_URL) || `${URL}/public/v2-og.png`;
|
||||||
|
const claimStreamUrl = generateContentUrl(claim);
|
||||||
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;
|
|
||||||
|
|
||||||
// https://developers.google.com/search/docs/data-types/video
|
// https://developers.google.com/search/docs/data-types/video
|
||||||
const googleVideoMetadata = {
|
const googleVideoMetadata = {
|
||||||
|
|
Loading…
Reference in a new issue