mirror of
https://github.com/snobu/destreamer.git
synced 2026-02-27 08:48:23 +00:00
fixed linting errors
This commit is contained in:
@@ -224,7 +224,7 @@ function checkQualityValue(argv: any): boolean {
|
|||||||
|
|
||||||
|
|
||||||
export function promptUser(choices: Array<string>): number {
|
export function promptUser(choices: Array<string>): number {
|
||||||
let index: number = readlineSync.keyInSelect(choices, 'Which resolution/format do you prefer?');
|
const index: number = readlineSync.keyInSelect(choices, 'Which resolution/format do you prefer?');
|
||||||
|
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
process.exit(ERROR_CODE.CANCELLED_USER_INPUT);
|
process.exit(ERROR_CODE.CANCELLED_USER_INPUT);
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export class DownloadManager {
|
|||||||
* @param options object with key: value pairs
|
* @param options object with key: value pairs
|
||||||
*/
|
*/
|
||||||
private setOptions(options: {[option: string]: string}, guid?: string): void {
|
private setOptions(options: {[option: string]: string}, guid?: string): void {
|
||||||
let message: string = guid ?
|
const message: string = guid ?
|
||||||
this.createMessage('aria2.changeOption', [guid, options]) :
|
this.createMessage('aria2.changeOption', [guid, options]) :
|
||||||
this.createMessage('aria2.changeGlobalOption', [options]);
|
this.createMessage('aria2.changeGlobalOption', [options]);
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ export class DownloadManager {
|
|||||||
// TODO: test download error parsing, not had a chance to yet
|
// TODO: test download error parsing, not had a chance to yet
|
||||||
logger.error(JSON.stringify(parsed));
|
logger.error(JSON.stringify(parsed));
|
||||||
|
|
||||||
let errorGid: string = parsed.params.pop().gid.toString();
|
const errorGid: string = parsed.params.pop().gid.toString();
|
||||||
this.queue.delete(errorGid);
|
this.queue.delete(errorGid);
|
||||||
|
|
||||||
// TODO: add this to createMessage
|
// TODO: add this to createMessage
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { AxiosResponse } from 'axios';
|
|||||||
export async function drawThumbnail(posterImage: string, session: Session): Promise<void> {
|
export async function drawThumbnail(posterImage: string, session: Session): Promise<void> {
|
||||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
const apiClient: ApiClient = ApiClient.getInstance(session);
|
||||||
|
|
||||||
let thumbnail: Buffer = await apiClient.callUrl(posterImage, 'get', null, 'arraybuffer')
|
const thumbnail: Buffer = await apiClient.callUrl(posterImage, 'get', null, 'arraybuffer')
|
||||||
.then((response: AxiosResponse<any> | undefined) => response?.data);
|
.then((response: AxiosResponse<any> | undefined) => response?.data);
|
||||||
|
|
||||||
console.log(await terminalImage.buffer(thumbnail, { width: 70 } ));
|
console.log(await terminalImage.buffer(thumbnail, { width: 70 } ));
|
||||||
|
|||||||
@@ -19,16 +19,16 @@ export class TokenCache {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
let session: Session = JSON.parse(fs.readFileSync(this.tokenCacheFile, 'utf8'));
|
const session: Session = JSON.parse(fs.readFileSync(this.tokenCacheFile, 'utf8'));
|
||||||
|
|
||||||
type Jwt = {
|
type Jwt = {
|
||||||
[key: string]: any
|
[key: string]: any
|
||||||
}
|
}
|
||||||
const decodedJwt: Jwt = jwtDecode(session.AccessToken);
|
const decodedJwt: Jwt = jwtDecode(session.AccessToken);
|
||||||
|
|
||||||
let now: number = Math.floor(Date.now() / 1000);
|
const now: number = Math.floor(Date.now() / 1000);
|
||||||
let exp: number = decodedJwt['exp'];
|
const exp: number = decodedJwt['exp'];
|
||||||
let timeLeft: number = exp - now;
|
const timeLeft: number = exp - now;
|
||||||
|
|
||||||
if (timeLeft < 120) {
|
if (timeLeft < 120) {
|
||||||
logger.warn('Access token has expired! \n');
|
logger.warn('Access token has expired! \n');
|
||||||
@@ -42,7 +42,7 @@ export class TokenCache {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Write(session: Session): void {
|
public Write(session: Session): void {
|
||||||
let s: string = JSON.stringify(session, null, 4);
|
const s: string = JSON.stringify(session, null, 4);
|
||||||
fs.writeFile('.token_cache', s, (err: any) => {
|
fs.writeFile('.token_cache', s, (err: any) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
return logger.error(err);
|
return logger.error(err);
|
||||||
|
|||||||
10
src/Utils.ts
10
src/Utils.ts
@@ -23,7 +23,7 @@ async function extractGuids(url: string, client: ApiClient): Promise<Array<strin
|
|||||||
const videoNumber: number = await client.callApi(`groups/${groupMatch[1]}`, 'get')
|
const videoNumber: number = await client.callApi(`groups/${groupMatch[1]}`, 'get')
|
||||||
.then((response: AxiosResponse<any> | undefined) => response?.data.metrics.videos);
|
.then((response: AxiosResponse<any> | undefined) => response?.data.metrics.videos);
|
||||||
|
|
||||||
let result: Array<string> = await client.callApi(`groups/${groupMatch[1]}/videos?$top=${videoNumber}&$orderby=publishedDate asc`, 'get')
|
const result: Array<string> = await client.callApi(`groups/${groupMatch[1]}/videos?$top=${videoNumber}&$orderby=publishedDate asc`, 'get')
|
||||||
.then((response: AxiosResponse<any> | undefined) => response?.data.value.map((item: any) => item.id));
|
.then((response: AxiosResponse<any> | undefined) => response?.data.value.map((item: any) => item.id));
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@@ -48,7 +48,7 @@ export async function parseCLIinput(urlList: Array<string>, defaultOutDir: strin
|
|||||||
session: Session): Promise<Array<Array<string>>> {
|
session: Session): Promise<Array<Array<string>>> {
|
||||||
|
|
||||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
const apiClient: ApiClient = ApiClient.getInstance(session);
|
||||||
let guidList: Array<string> = [];
|
const guidList: Array<string> = [];
|
||||||
|
|
||||||
for (const url of urlList) {
|
for (const url of urlList) {
|
||||||
const guids: Array<string> | null = await extractGuids(url, apiClient);
|
const guids: Array<string> | null = await extractGuids(url, apiClient);
|
||||||
@@ -85,8 +85,8 @@ export async function parseInputFile(inputFile: string, defaultOutDir: string,
|
|||||||
.split(/\r?\n/);
|
.split(/\r?\n/);
|
||||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
const apiClient: ApiClient = ApiClient.getInstance(session);
|
||||||
|
|
||||||
let guidList: Array<string> = [];
|
const guidList: Array<string> = [];
|
||||||
let outDirList: Array<string> = [];
|
const outDirList: Array<string> = [];
|
||||||
// if the last line was an url set this
|
// if the last line was an url set this
|
||||||
let foundUrl = false;
|
let foundUrl = false;
|
||||||
|
|
||||||
@@ -101,7 +101,7 @@ export async function parseInputFile(inputFile: string, defaultOutDir: string,
|
|||||||
// parse if line is option
|
// parse if line is option
|
||||||
else if (line.includes('-dir')) {
|
else if (line.includes('-dir')) {
|
||||||
if (foundUrl) {
|
if (foundUrl) {
|
||||||
let outDir: string | null = parseOption('-dir', line);
|
const outDir: string | null = parseOption('-dir', line);
|
||||||
|
|
||||||
if (outDir && checkOutDir(outDir)) {
|
if (outDir && checkOutDir(outDir)) {
|
||||||
outDirList.push(...Array(guidList.length - outDirList.length)
|
outDirList.push(...Array(guidList.length - outDirList.length)
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ function isoDurationToString(time: string): string {
|
|||||||
export async function getVideosInfo(videoGuids: Array<string>,
|
export async function getVideosInfo(videoGuids: Array<string>,
|
||||||
session: Session, subtitles?: boolean): Promise<Array<Video>> {
|
session: Session, subtitles?: boolean): Promise<Array<Video>> {
|
||||||
|
|
||||||
let metadata: Array<Video> = [];
|
const metadata: Array<Video> = [];
|
||||||
|
|
||||||
let title: string;
|
let title: string;
|
||||||
let duration: string;
|
let duration: string;
|
||||||
@@ -60,7 +60,7 @@ export async function getVideosInfo(videoGuids: Array<string>,
|
|||||||
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 =
|
const response: AxiosResponse<any> | undefined =
|
||||||
await apiClient.callApi('videos/' + guid + '?$expand=creator', 'get');
|
await apiClient.callApi('videos/' + guid + '?$expand=creator', 'get');
|
||||||
|
|
||||||
title = sanitizeWindowsName(response?.data['name']);
|
title = sanitizeWindowsName(response?.data['name']);
|
||||||
@@ -87,7 +87,7 @@ export async function getVideosInfo(videoGuids: Array<string>,
|
|||||||
posterImageUrl = response?.data['posterImage']['medium']['url'];
|
posterImageUrl = response?.data['posterImage']['medium']['url'];
|
||||||
|
|
||||||
if (subtitles) {
|
if (subtitles) {
|
||||||
let captions: AxiosResponse<any> | undefined = await apiClient.callApi(`videos/${guid}/texttracks`, 'get');
|
const captions: AxiosResponse<any> | undefined = await apiClient.callApi(`videos/${guid}/texttracks`, 'get');
|
||||||
|
|
||||||
if (!captions?.data.value.length) {
|
if (!captions?.data.value.length) {
|
||||||
captionsUrl = undefined;
|
captionsUrl = undefined;
|
||||||
@@ -137,7 +137,7 @@ export function createUniquePaths(videos: Array<Video>, outDirs: Array<string>,
|
|||||||
let match = elementRegEx.exec(template);
|
let match = elementRegEx.exec(template);
|
||||||
|
|
||||||
while (match) {
|
while (match) {
|
||||||
let value = video[match[1] as keyof Video] as string;
|
const value = video[match[1] as keyof Video] as string;
|
||||||
title = title.replace(match[0], value);
|
title = title.replace(match[0], value);
|
||||||
match = elementRegEx.exec(template);
|
match = elementRegEx.exec(template);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
|
|
||||||
// video playlist url
|
// video playlist url
|
||||||
let videoPlaylistUrl: string;
|
let videoPlaylistUrl: string;
|
||||||
let videoPlaylists: Array<any> = (masterParser.manifest.playlists as Array<any>)
|
const videoPlaylists: Array<any> = (masterParser.manifest.playlists as Array<any>)
|
||||||
.filter(playlist =>
|
.filter(playlist =>
|
||||||
Object.prototype.hasOwnProperty.call(playlist.attributes, 'RESOLUTION'));
|
Object.prototype.hasOwnProperty.call(playlist.attributes, 'RESOLUTION'));
|
||||||
|
|
||||||
@@ -227,9 +227,10 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
|
|
||||||
// audio playlist url
|
// audio playlist url
|
||||||
// TODO: better audio playlists parsing? With language maybe?
|
// TODO: better audio playlists parsing? With language maybe?
|
||||||
let audioPlaylistUrl: string;
|
const audioPlaylists: Array<string> =
|
||||||
let audioPlaylists: Array<string> = Object.keys(masterParser.manifest.mediaGroups.AUDIO.audio);
|
Object.keys(masterParser.manifest.mediaGroups.AUDIO.audio);
|
||||||
audioPlaylistUrl = masterParser.manifest.mediaGroups.AUDIO.audio[audioPlaylists[0]].uri;
|
const audioPlaylistUrl: string =
|
||||||
|
masterParser.manifest.mediaGroups.AUDIO.audio[audioPlaylists[0]].uri;
|
||||||
// if (audioPlaylists.length === 1){
|
// if (audioPlaylists.length === 1){
|
||||||
// audioPlaylistUrl = masterParser.manifest.mediaGroups.AUDIO
|
// audioPlaylistUrl = masterParser.manifest.mediaGroups.AUDIO
|
||||||
// .audio[audioPlaylists[0]].uri;
|
// .audio[audioPlaylists[0]].uri;
|
||||||
@@ -342,8 +343,9 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
|||||||
async function main(): Promise<void> {
|
async function main(): Promise<void> {
|
||||||
await init(); // must be first
|
await init(); // must be first
|
||||||
|
|
||||||
let session: Session;
|
|
||||||
session = tokenCache.Read() ?? await DoInteractiveLogin('https://web.microsoftstream.com/', argv.username);
|
const session: Session = tokenCache.Read() ??
|
||||||
|
await DoInteractiveLogin('https://web.microsoftstream.com/', argv.username);
|
||||||
|
|
||||||
logger.verbose('Session and API info \n' +
|
logger.verbose('Session and API info \n' +
|
||||||
'\t API Gateway URL: '.cyan + session.ApiGatewayUri + '\n' +
|
'\t API Gateway URL: '.cyan + session.ApiGatewayUri + '\n' +
|
||||||
|
|||||||
Reference in New Issue
Block a user