mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-24 15:28:26 +00:00
Fixes and clean up (#51)
* Simplify main * Fix init * Cleaner output for the end user * Fix extractVideoGuid after sync with dev * TokenCache: Make variable private nit: switch to import * Add option to disable video thumbnails * Create a unique file name to avoid overwrite * Remove os dependency * Reimplement simulate * Update README Co-authored-by: @kylon Co-authored-by: @snobu
This commit is contained in:
20
Metadata.ts
20
Metadata.ts
@@ -1,16 +1,28 @@
|
||||
import axios from 'axios';
|
||||
import { Metadata, Session } from './Types';
|
||||
|
||||
import axios from 'axios';
|
||||
|
||||
export async function getVideoMetadata(videoGuids: string[], session: Session): Promise<Metadata[]> {
|
||||
function publishedDateToString(date: string) {
|
||||
const dateJs = new Date(date);
|
||||
const day = dateJs.getDate().toString().padStart(2, '0');
|
||||
const month = (dateJs.getMonth() + 1).toString(10).padStart(2, '0');
|
||||
|
||||
return day+'-'+month+'-'+dateJs.getFullYear();
|
||||
}
|
||||
|
||||
export async function getVideoMetadata(videoGuids: string[], session: Session, verbose: boolean): Promise<Metadata[]> {
|
||||
let metadata: Metadata[] = [];
|
||||
let title: string;
|
||||
let date: string;
|
||||
let playbackUrl: string;
|
||||
let posterImage: string;
|
||||
|
||||
await Promise.all(videoGuids.map(async guid => {
|
||||
let apiUrl = `${session.ApiGatewayUri}videos/${guid}?api-version=${session.ApiGatewayVersion}`;
|
||||
console.log(`Calling ${apiUrl}`);
|
||||
|
||||
if (verbose)
|
||||
console.info(`Calling ${apiUrl}`);
|
||||
|
||||
let response = await axios.get(apiUrl,
|
||||
{
|
||||
headers: {
|
||||
@@ -25,8 +37,10 @@ export async function getVideoMetadata(videoGuids: string[], session: Session):
|
||||
.map((item: { [x: string]: string }) => { return item['playbackUrl']; })[0];
|
||||
|
||||
posterImage = response.data['posterImage']['medium']['url'];
|
||||
date = publishedDateToString(response.data['publishedDate']);
|
||||
|
||||
metadata.push({
|
||||
date: date,
|
||||
title: title,
|
||||
playbackUrl: playbackUrl,
|
||||
posterImage: posterImage
|
||||
|
||||
Reference in New Issue
Block a user