diff --git a/src/batch.ts b/src/batch.ts index 7976b6c..d23b64f 100644 --- a/src/batch.ts +++ b/src/batch.ts @@ -32,7 +32,7 @@ export default function(args: string[], done: (err?: Error) => void) } catch (e) { - log.warn(`Invalid resolution ${config.resolution}p. Setting to 1080p`); + log.warn('Invalid resolution ' + config.resolution + 'p. Setting to 1080p'); config.video_format = resol_table['1080'].format; config.video_quality = resol_table['1080'].quality; } @@ -46,7 +46,10 @@ export default function(args: string[], done: (err?: Error) => void) tasks(config, batchPath, (err, tasksArr) => { - if (err) return done(err); + if (err) + { + return done(err); + } let i = 0; diff --git a/src/cli.ts b/src/cli.ts index 4e92f46..de57f88 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -8,6 +8,6 @@ batch(process.argv, (err: any) => console.error(err.stack || err); process.exit(-1); } - console.log('Done!'); + console.info('Done!'); process.exit(0); }); diff --git a/src/episode.ts b/src/episode.ts index cf82ff7..5950470 100644 --- a/src/episode.ts +++ b/src/episode.ts @@ -271,7 +271,7 @@ function scrapePage(config: IConfig, address: string, done: (err: Error, page?: const regexp = /\s*([^\n\r\t\f]+)\n?\s*[^0-9]*([0-9][\-0-9.]*)?,?\n?\s\s*[^0-9]*((PV )?[S0-9][P0-9.]*[a-fA-F]?)/; const look = $('#showmedia_about_media').text(); const seasonTitle = $('span[itemprop="title"]').text(); - let episodeTitle = $('#showmedia_about_name').text().replace(/[“”]/g, ''); + const episodeTitle = $('#showmedia_about_name').text().replace(/[“”]/g, ''); const data = regexp.exec(look); if (!swf || !data) diff --git a/src/my_request.ts b/src/my_request.ts index 66f0b72..2b1978b 100644 --- a/src/my_request.ts +++ b/src/my_request.ts @@ -13,33 +13,33 @@ const cloudscraper = require('cloudscraper'); let isAuthenticated = false; let isPremium = false; -const defaultHeaders: request.Headers = +const defaultHeaders: request.Headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 6.2; WOW64; x64; rv:58.0) Gecko/20100101 Firefox/58.0', 'Connection': 'keep-alive', 'Referer': 'https://www.crunchyroll.com/login', }; -function generateDeviceId(): string +function generateDeviceId(): string { let id = ''; const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; - for (let i = 0; i < 32; i++) + for (let i = 0; i < 32; i++) { - id += possible.charAt(Math.floor(Math.random() * possible.length)); + id += possible.charAt(Math.floor(Math.random() * possible.length)); } return id; } -function startSession(): Promise +function startSession(): Promise { return rp( { method: 'GET', url: 'CR_SESSION_URL', - qs: + qs: { device_id: generateDeviceId(), device_type: 'CR_DEVICE_TYPE', @@ -49,7 +49,7 @@ function startSession(): Promise }, json: true, }) - .then((response: any) => + .then((response: any) => { return response.data.session_id; }); @@ -61,7 +61,7 @@ function login(sessionId: string, user: string, pass: string): Promise { method: 'POST', url: 'CR_LOGIN_URL', - form: + form: { account: user, password: pass, @@ -210,10 +210,10 @@ function modify(options: string|request.Options, reqMethod: string): request.Opt options.method = reqMethod; return options; } - return { - jar: true, - headers: defaultHeaders, - url: options.toString(), - method: reqMethod + return { + jar: true, + headers: defaultHeaders, + url: options.toString(), + method: reqMethod }; } \ No newline at end of file diff --git a/src/series.ts b/src/series.ts index c3d0f08..1a59937 100644 --- a/src/series.ts +++ b/src/series.ts @@ -2,7 +2,7 @@ import cheerio = require('cheerio'); import episode from './episode'; import fs = require('fs'); -const fse = require('fs-extra'); +import fse = require('fs-extra'); import my_request = require('./my_request'); import path = require('path'); import url = require('url'); @@ -153,7 +153,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer episode: '', volume: 0, }); - done(null, {episodes: episodes.reverse(), series: ""}); + done(null, {episodes: episodes.reverse(), series: ''}); } else { @@ -195,7 +195,7 @@ function page(config: IConfig, address: string, done: (err: Error, result?: ISer }); if (episodeCount === 0) { - log.warn("No episodes found for " + title + ". Could it be a movie?"); + log.warn('No episodes found for ' + title + '. Could it be a movie?'); } done(null, {episodes: episodes.reverse(), series: title}); }); diff --git a/src/subtitle/formats/ass.ts b/src/subtitle/formats/ass.ts index 48f0836..4d9e977 100644 --- a/src/subtitle/formats/ass.ts +++ b/src/subtitle/formats/ass.ts @@ -33,10 +33,10 @@ export default function(input: string|Buffer, done: (err: Error, subtitle?: stri */ function event(block: ISubtitleEvent): string { - var format = 'Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text'; + const format = 'Layer,Start,End,Style,Name,MarginL,MarginR,MarginV,Effect,Text'; return '[Events]\n' + - 'Format: ' + format + '\n' + [].concat(block.event).map(style => ('Dialogue: 0,' + + 'Format: ' + format + '\n' + [].concat(block.event).map((style) => ('Dialogue: 0,' + style.$.start + ',' + style.$.end + ',' + style.$.style + ',' + @@ -70,13 +70,13 @@ function script(block: ISubtitle): string */ function style(block: ISubtitleStyle): string { - var format = 'Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,' + + const format = 'Name,Fontname,Fontsize,PrimaryColour,SecondaryColour,' + 'OutlineColour,BackColour,Bold,Italic,Underline,StrikeOut,ScaleX,' + 'ScaleY,Spacing,Angle,BorderStyle,Outline,Shadow,Alignment,' + 'MarginL,MarginR,MarginV,Encoding'; return '[V4+ Styles]\n' + - 'Format: ' + format + '\n' + [].concat(block.style).map(style => 'Style: ' + + 'Format: ' + format + '\n' + [].concat(block.style).map((style) => 'Style: ' + style.$.name + ',' + style.$.font_name + ',' + style.$.font_size + ',' + diff --git a/src/subtitle/formats/index.ts b/src/subtitle/formats/index.ts index 2d9affd..e52f432 100644 --- a/src/subtitle/formats/index.ts +++ b/src/subtitle/formats/index.ts @@ -2,7 +2,7 @@ import ass from './ass'; import srt from './srt'; -export default { - ass: ass, - srt: srt -}; +export default { + ass, + srt +} as IFormatterTable; diff --git a/src/video/merge.ts b/src/video/merge.ts index 5765238..25c2c8d 100644 --- a/src/video/merge.ts +++ b/src/video/merge.ts @@ -17,7 +17,7 @@ export default function(config: IConfig, isSubtitled: boolean, rtmpInputPath: st if (streamMode === 'RTMP') { - videoPath += path.extname(rtmpInputPath); + videoPath += path.extname(rtmpInputPath); } else { diff --git a/src/video/stream.ts b/src/video/stream.ts index 11d9a5d..77d498a 100644 --- a/src/video/stream.ts +++ b/src/video/stream.ts @@ -11,30 +11,31 @@ import log = require('../log'); export default function(rtmpUrl: string, rtmpInputPath: string, swfUrl: string, filePath: string, fileExt: string, mode: string, done: (err: Error) => void) { - if (mode === 'RTMP') - { - childProcess.exec(command('rtmpdump') + ' ' + - '-r "' + rtmpUrl + '" ' + - '-y "' + rtmpInputPath + '" ' + - '-W "' + swfUrl + '" ' + - '-o "' + filePath + fileExt + '"', { - maxBuffer: Infinity, - }, done); - } - else if (mode === 'HLS') - { - const cmd = command('ffmpeg') + ' ' + - '-i "' + rtmpInputPath + '" ' + - '-c copy -bsf:a aac_adtstoasc ' + - '"' + filePath + '.mp4"'; - childProcess.exec(cmd, { - maxBuffer: Infinity, - }, done); - } - else - { - log.error('No such mode: ' + mode); - } + if (mode === 'RTMP') + { + childProcess.exec(command('rtmpdump') + ' ' + + '-r "' + rtmpUrl + '" ' + + '-y "' + rtmpInputPath + '" ' + + '-W "' + swfUrl + '" ' + + '-o "' + filePath + fileExt + '"', { + maxBuffer: Infinity, + }, done); + } + else if (mode === 'HLS') + { + const cmd = command('ffmpeg') + ' ' + + '-i "' + rtmpInputPath + '" ' + + '-c copy -bsf:a aac_adtstoasc ' + + '"' + filePath + '.mp4"'; + childProcess.exec(cmd, + { + maxBuffer: Infinity, + }, done); + } + else + { + log.error('No such mode: ' + mode); + } } /** @@ -44,7 +45,7 @@ function command(exe: string): string { if (os.platform() !== 'win32') { - return exe; + return exe; } return '"' + path.join(__dirname, '../../bin/' + exe + '.exe') + '"'; diff --git a/tslint.json b/tslint.json index bb0d2b6..c4b4351 100644 --- a/tslint.json +++ b/tslint.json @@ -17,11 +17,12 @@ "member-ordering": false, "no-shadowed-variable": false, "array-type": [true, "array"], - "object-literal-sort-keys": false, "trailing-comma": false, "no-any": false, "no-arg": true, "no-bitwise": true, + "space-within-parens": false, + "no-object-literal-type-assertion": false, "no-console": [true, "debug", "time",