1
0
mirror of https://github.com/snobu/destreamer.git synced 2026-01-18 05:52:15 +00:00

- removed useless function/properties

- added filename property to Video type
This commit is contained in:
Luca Armaroli
2020-09-09 04:54:17 +02:00
parent a185f51eb5
commit 96f4c90277
2 changed files with 29 additions and 22 deletions

View File

@@ -6,6 +6,7 @@ export type Session = {
export type Video = {
// the following properties are all for the title template
title: string;
duration: string;
publishDate: string;
@@ -13,11 +14,16 @@ export type Video = {
author: string;
authorEmail: string;
uniqueId: string;
outPath: string;
totalChunks: number; // Abstraction of FFmpeg timemark
// the following properties are all the urls neede for the download
playbackUrl: string;
posterImageUrl: string;
captionsUrl?: string
// final filename, already sanitized and unique
filename: string;
// complete path to save the video
outPath: string;
}

View File

@@ -36,18 +36,11 @@ function isoDurationToString(time: string): string {
}
function durationToTotalChunks(duration: string): number {
const durationObj: any = parseDuration(duration);
const hrs: number = durationObj.hours ?? 0;
const mins: number = durationObj.minutes ?? 0;
const secs: number = Math.ceil(durationObj.seconds ?? 0);
export async function getVideosInfo(videoGuids: Array<string>,
session: Session, subtitles?: boolean): Promise<Array<Video>> {
return (hrs * 60) + mins + (secs / 60);
}
export async function getVideoInfo(videoGuids: Array<string>, session: Session, subtitles?: boolean): Promise<Array<Video>> {
let metadata: Array<Video> = [];
let title: string;
let duration: string;
let publishDate: string;
@@ -55,17 +48,18 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
let author: string;
let authorEmail: string;
let uniqueId: string;
const outPath = '';
let totalChunks: number;
let playbackUrl: string;
let posterImageUrl: string;
let captionsUrl: string | undefined;
const apiClient: ApiClient = ApiClient.getInstance(session);
/* TODO: change this to a single guid at a time to ease our footprint on the
/* TODO[MAYBE]: change this to a single guid at a time to ease our footprint on the
MSS servers or we get throttled after 10 sequential reqs */
for (const guid of videoGuids) {
let response: AxiosResponse<any> | undefined =
await apiClient.callApi('videos/' + guid + '?$expand=creator', 'get');
@@ -83,8 +77,6 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
uniqueId = '#' + guid.split('-')[0];
totalChunks = durationToTotalChunks(response?.data.media['duration']);
playbackUrl = response?.data['playbackUrls']
.filter((item: { [x: string]: string; }) =>
item['mimeType'] == 'application/vnd.apple.mpegurl')
@@ -120,11 +112,14 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
author: author,
authorEmail: authorEmail,
uniqueId: uniqueId,
outPath: outPath,
totalChunks: totalChunks, // Abstraction of FFmpeg timemark
// totalChunks: totalChunks, // Abstraction of FFmpeg timemark
playbackUrl: playbackUrl,
posterImageUrl: posterImageUrl,
captionsUrl: captionsUrl
captionsUrl: captionsUrl,
filename: '',
outPath: '',
});
}
@@ -132,7 +127,8 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
}
export function createUniquePath(videos: Array<Video>, outDirs: Array<string>, template: string, format: string, skip?: boolean): Array<Video> {
export function createUniquePaths(videos: Array<Video>, outDirs: Array<string>,
template: string, format: string, skip?: boolean): Array<Video> {
videos.forEach((video: Video, index: number) => {
let title: string = template;
@@ -156,9 +152,14 @@ export function createUniquePath(videos: Array<Video>, outDirs: Array<string>, t
const finalFileName = `${finalTitle}.${format}`;
const cleanFileName = sanitizeWindowsName(finalFileName, { replacement: '_' });
if (finalFileName !== cleanFileName) {
logger.warn(`Not a valid Windows file name: "${finalFileName}".\nReplacing invalid characters with underscores to preserve cross-platform consistency.`);
logger.warn(
`Not a valid Windows file name: "${finalFileName}"` +
'\nReplacing invalid characters with underscores to ' +
'preserve cross-platform consistency.');
}
video.filename = finalFileName;
video.outPath = path.join(outDirs[index], finalFileName);
});