mirror of
https://github.com/snobu/destreamer.git
synced 2026-01-21 15:32:16 +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 {
|
||||
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) {
|
||||
process.exit(ERROR_CODE.CANCELLED_USER_INPUT);
|
||||
|
||||
@@ -135,7 +135,7 @@ export class DownloadManager {
|
||||
* @param options object with key: value pairs
|
||||
*/
|
||||
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.changeGlobalOption', [options]);
|
||||
|
||||
@@ -186,7 +186,7 @@ export class DownloadManager {
|
||||
// TODO: test download error parsing, not had a chance to yet
|
||||
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);
|
||||
|
||||
// TODO: add this to createMessage
|
||||
|
||||
@@ -8,7 +8,7 @@ import { AxiosResponse } from 'axios';
|
||||
export async function drawThumbnail(posterImage: string, session: Session): Promise<void> {
|
||||
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);
|
||||
|
||||
console.log(await terminalImage.buffer(thumbnail, { width: 70 } ));
|
||||
|
||||
@@ -19,16 +19,16 @@ export class TokenCache {
|
||||
return null;
|
||||
}
|
||||
|
||||
let session: Session = JSON.parse(fs.readFileSync(this.tokenCacheFile, 'utf8'));
|
||||
const session: Session = JSON.parse(fs.readFileSync(this.tokenCacheFile, 'utf8'));
|
||||
|
||||
type Jwt = {
|
||||
[key: string]: any
|
||||
}
|
||||
const decodedJwt: Jwt = jwtDecode(session.AccessToken);
|
||||
|
||||
let now: number = Math.floor(Date.now() / 1000);
|
||||
let exp: number = decodedJwt['exp'];
|
||||
let timeLeft: number = exp - now;
|
||||
const now: number = Math.floor(Date.now() / 1000);
|
||||
const exp: number = decodedJwt['exp'];
|
||||
const timeLeft: number = exp - now;
|
||||
|
||||
if (timeLeft < 120) {
|
||||
logger.warn('Access token has expired! \n');
|
||||
@@ -42,7 +42,7 @@ export class TokenCache {
|
||||
}
|
||||
|
||||
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) => {
|
||||
if (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')
|
||||
.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));
|
||||
|
||||
return result;
|
||||
@@ -48,7 +48,7 @@ export async function parseCLIinput(urlList: Array<string>, defaultOutDir: strin
|
||||
session: Session): Promise<Array<Array<string>>> {
|
||||
|
||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
||||
let guidList: Array<string> = [];
|
||||
const guidList: Array<string> = [];
|
||||
|
||||
for (const url of urlList) {
|
||||
const guids: Array<string> | null = await extractGuids(url, apiClient);
|
||||
@@ -85,8 +85,8 @@ export async function parseInputFile(inputFile: string, defaultOutDir: string,
|
||||
.split(/\r?\n/);
|
||||
const apiClient: ApiClient = ApiClient.getInstance(session);
|
||||
|
||||
let guidList: Array<string> = [];
|
||||
let outDirList: Array<string> = [];
|
||||
const guidList: Array<string> = [];
|
||||
const outDirList: Array<string> = [];
|
||||
// if the last line was an url set this
|
||||
let foundUrl = false;
|
||||
|
||||
@@ -101,7 +101,7 @@ export async function parseInputFile(inputFile: string, defaultOutDir: string,
|
||||
// parse if line is option
|
||||
else if (line.includes('-dir')) {
|
||||
if (foundUrl) {
|
||||
let outDir: string | null = parseOption('-dir', line);
|
||||
const outDir: string | null = parseOption('-dir', line);
|
||||
|
||||
if (outDir && checkOutDir(outDir)) {
|
||||
outDirList.push(...Array(guidList.length - outDirList.length)
|
||||
|
||||
@@ -39,7 +39,7 @@ function isoDurationToString(time: string): string {
|
||||
export async function getVideosInfo(videoGuids: Array<string>,
|
||||
session: Session, subtitles?: boolean): Promise<Array<Video>> {
|
||||
|
||||
let metadata: Array<Video> = [];
|
||||
const metadata: Array<Video> = [];
|
||||
|
||||
let title: 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 */
|
||||
for (const guid of videoGuids) {
|
||||
|
||||
let response: AxiosResponse<any> | undefined =
|
||||
const response: AxiosResponse<any> | undefined =
|
||||
await apiClient.callApi('videos/' + guid + '?$expand=creator', 'get');
|
||||
|
||||
title = sanitizeWindowsName(response?.data['name']);
|
||||
@@ -87,7 +87,7 @@ export async function getVideosInfo(videoGuids: Array<string>,
|
||||
posterImageUrl = response?.data['posterImage']['medium']['url'];
|
||||
|
||||
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) {
|
||||
captionsUrl = undefined;
|
||||
@@ -137,7 +137,7 @@ export function createUniquePaths(videos: Array<Video>, outDirs: Array<string>,
|
||||
let match = elementRegEx.exec(template);
|
||||
|
||||
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);
|
||||
match = elementRegEx.exec(template);
|
||||
}
|
||||
|
||||
@@ -201,7 +201,7 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
||||
|
||||
// video playlist url
|
||||
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 =>
|
||||
Object.prototype.hasOwnProperty.call(playlist.attributes, 'RESOLUTION'));
|
||||
|
||||
@@ -227,9 +227,10 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
||||
|
||||
// audio playlist url
|
||||
// TODO: better audio playlists parsing? With language maybe?
|
||||
let audioPlaylistUrl: string;
|
||||
let audioPlaylists: Array<string> = Object.keys(masterParser.manifest.mediaGroups.AUDIO.audio);
|
||||
audioPlaylistUrl = masterParser.manifest.mediaGroups.AUDIO.audio[audioPlaylists[0]].uri;
|
||||
const audioPlaylists: Array<string> =
|
||||
Object.keys(masterParser.manifest.mediaGroups.AUDIO.audio);
|
||||
const audioPlaylistUrl: string =
|
||||
masterParser.manifest.mediaGroups.AUDIO.audio[audioPlaylists[0]].uri;
|
||||
// if (audioPlaylists.length === 1){
|
||||
// audioPlaylistUrl = masterParser.manifest.mediaGroups.AUDIO
|
||||
// .audio[audioPlaylists[0]].uri;
|
||||
@@ -342,8 +343,9 @@ async function downloadVideo(videoGUIDs: Array<string>,
|
||||
async function main(): Promise<void> {
|
||||
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' +
|
||||
'\t API Gateway URL: '.cyan + session.ApiGatewayUri + '\n' +
|
||||
|
||||
Reference in New Issue
Block a user