mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-10 16:49:42 +00:00
- removed useless function/properties
- added filename property to Video type
This commit is contained in:
10
src/Types.ts
10
src/Types.ts
@@ -6,6 +6,7 @@ export type Session = {
|
|||||||
|
|
||||||
|
|
||||||
export type Video = {
|
export type Video = {
|
||||||
|
// the following properties are all for the title template
|
||||||
title: string;
|
title: string;
|
||||||
duration: string;
|
duration: string;
|
||||||
publishDate: string;
|
publishDate: string;
|
||||||
@@ -13,11 +14,16 @@ export type Video = {
|
|||||||
author: string;
|
author: string;
|
||||||
authorEmail: string;
|
authorEmail: string;
|
||||||
uniqueId: string;
|
uniqueId: string;
|
||||||
outPath: string;
|
|
||||||
totalChunks: number; // Abstraction of FFmpeg timemark
|
// the following properties are all the urls neede for the download
|
||||||
playbackUrl: string;
|
playbackUrl: string;
|
||||||
posterImageUrl: string;
|
posterImageUrl: string;
|
||||||
captionsUrl?: string
|
captionsUrl?: string
|
||||||
|
|
||||||
|
// final filename, already sanitized and unique
|
||||||
|
filename: string;
|
||||||
|
// complete path to save the video
|
||||||
|
outPath: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,18 +36,11 @@ function isoDurationToString(time: string): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function durationToTotalChunks(duration: string): number {
|
export async function getVideosInfo(videoGuids: Array<string>,
|
||||||
const durationObj: any = parseDuration(duration);
|
session: Session, subtitles?: boolean): Promise<Array<Video>> {
|
||||||
const hrs: number = durationObj.hours ?? 0;
|
|
||||||
const mins: number = durationObj.minutes ?? 0;
|
|
||||||
const secs: number = Math.ceil(durationObj.seconds ?? 0);
|
|
||||||
|
|
||||||
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 metadata: Array<Video> = [];
|
||||||
|
|
||||||
let title: string;
|
let title: string;
|
||||||
let duration: string;
|
let duration: string;
|
||||||
let publishDate: string;
|
let publishDate: string;
|
||||||
@@ -55,17 +48,18 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
|
|||||||
let author: string;
|
let author: string;
|
||||||
let authorEmail: string;
|
let authorEmail: string;
|
||||||
let uniqueId: string;
|
let uniqueId: string;
|
||||||
const outPath = '';
|
|
||||||
let totalChunks: number;
|
|
||||||
let playbackUrl: string;
|
let playbackUrl: string;
|
||||||
let posterImageUrl: string;
|
let posterImageUrl: string;
|
||||||
let captionsUrl: string | undefined;
|
let captionsUrl: string | undefined;
|
||||||
|
|
||||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
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 */
|
MSS servers or we get throttled after 10 sequential reqs */
|
||||||
for (const guid of videoGuids) {
|
for (const guid of videoGuids) {
|
||||||
|
|
||||||
let response: AxiosResponse<any> | undefined =
|
let response: AxiosResponse<any> | undefined =
|
||||||
await apiClient.callApi('videos/' + guid + '?$expand=creator', 'get');
|
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];
|
uniqueId = '#' + guid.split('-')[0];
|
||||||
|
|
||||||
totalChunks = durationToTotalChunks(response?.data.media['duration']);
|
|
||||||
|
|
||||||
playbackUrl = response?.data['playbackUrls']
|
playbackUrl = response?.data['playbackUrls']
|
||||||
.filter((item: { [x: string]: string; }) =>
|
.filter((item: { [x: string]: string; }) =>
|
||||||
item['mimeType'] == 'application/vnd.apple.mpegurl')
|
item['mimeType'] == 'application/vnd.apple.mpegurl')
|
||||||
@@ -120,11 +112,14 @@ export async function getVideoInfo(videoGuids: Array<string>, session: Session,
|
|||||||
author: author,
|
author: author,
|
||||||
authorEmail: authorEmail,
|
authorEmail: authorEmail,
|
||||||
uniqueId: uniqueId,
|
uniqueId: uniqueId,
|
||||||
outPath: outPath,
|
|
||||||
totalChunks: totalChunks, // Abstraction of FFmpeg timemark
|
// totalChunks: totalChunks, // Abstraction of FFmpeg timemark
|
||||||
playbackUrl: playbackUrl,
|
playbackUrl: playbackUrl,
|
||||||
posterImageUrl: posterImageUrl,
|
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) => {
|
videos.forEach((video: Video, index: number) => {
|
||||||
let title: string = template;
|
let title: string = template;
|
||||||
@@ -156,9 +152,14 @@ export function createUniquePath(videos: Array<Video>, outDirs: Array<string>, t
|
|||||||
const finalFileName = `${finalTitle}.${format}`;
|
const finalFileName = `${finalTitle}.${format}`;
|
||||||
const cleanFileName = sanitizeWindowsName(finalFileName, { replacement: '_' });
|
const cleanFileName = sanitizeWindowsName(finalFileName, { replacement: '_' });
|
||||||
if (finalFileName !== cleanFileName) {
|
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);
|
video.outPath = path.join(outDirs[index], finalFileName);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user