adding support for "ago"
This commit is contained in:
parent
d4c125154b
commit
5c1f1bf24f
|
@ -4,6 +4,31 @@ const prisma = new PrismaClient()
|
||||||
const metadata = require('./metadata.js')
|
const metadata = require('./metadata.js')
|
||||||
const upload = require('./upload.js')
|
const upload = require('./upload.js')
|
||||||
|
|
||||||
|
function convertRelativeToDate(relativeTime) {
|
||||||
|
const parts = relativeTime.split(' ');
|
||||||
|
const amount = parseInt(parts[0]);
|
||||||
|
const unit = parts[1];
|
||||||
|
|
||||||
|
const currentDate = new Date();
|
||||||
|
|
||||||
|
switch (unit) {
|
||||||
|
case 'hour':
|
||||||
|
case 'hours':
|
||||||
|
currentDate.setHours(currentDate.getHours() - amount);
|
||||||
|
break;
|
||||||
|
case 'minute':
|
||||||
|
case 'minutes':
|
||||||
|
currentDate.setMinutes(currentDate.getMinutes() - amount);
|
||||||
|
break;
|
||||||
|
case 'day':
|
||||||
|
case 'days':
|
||||||
|
currentDate.setDate(currentDate.getDate() - amount);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentDate;
|
||||||
|
}
|
||||||
|
|
||||||
async function createDatabaseVideo(id, videoUrl, playlistId) {
|
async function createDatabaseVideo(id, videoUrl, playlistId) {
|
||||||
const data = await metadata.getVideoMetadata(id)
|
const data = await metadata.getVideoMetadata(id)
|
||||||
const channelData = await metadata.getChannel(data.basic_info.channel_id)
|
const channelData = await metadata.getChannel(data.basic_info.channel_id)
|
||||||
|
@ -21,8 +46,8 @@ async function createDatabaseVideo(id, videoUrl, playlistId) {
|
||||||
description: (data.basic_info.short_description).replaceAll('\n', '<br>'),
|
description: (data.basic_info.short_description).replaceAll('\n', '<br>'),
|
||||||
thumbnail: thumbnailUrl,
|
thumbnail: thumbnailUrl,
|
||||||
source: videoUrl,
|
source: videoUrl,
|
||||||
published: (new Date(data.primary_info.published.text)).toISOString().slice(0,10),
|
published: (data.primary_info.published.text.endsWith('ago') ? convertRelativeToDate(data.primary_info.published.text) : new Date(data.primary_info.published.text)).toISOString().slice(0, 10),
|
||||||
archived: (new Date()).toISOString().slice(0,10),
|
archived: (new Date()).toISOString().slice(0, 10),
|
||||||
channel: channelData.metadata.title,
|
channel: channelData.metadata.title,
|
||||||
channelId: channelData.metadata.external_id,
|
channelId: channelData.metadata.external_id,
|
||||||
channelAvatar: uploaderAvatar,
|
channelAvatar: uploaderAvatar,
|
||||||
|
|
Loading…
Reference in New Issue