From e344fdd5f6b45ca3eb656d583d124442b0bf0bab Mon Sep 17 00:00:00 2001 From: iam4x Date: Mon, 4 Dec 2017 09:49:06 +0100 Subject: [PATCH] style(eslint): add `yarn lint` and fix codestyle --- package.json | 3 ++- src/index.js | 32 ++++++++++++-------------------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index ab6e231..a8e5bec 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "license": "MIT", "scripts": { "build": "rm -rf dist && babel src -d dist", - "prepublish": "npm run build" + "prepublish": "npm run build", + "lint": "eslint src" }, "devDependencies": { "babel-cli": "^6.26.0", diff --git a/src/index.js b/src/index.js index 2999335..74f87ab 100644 --- a/src/index.js +++ b/src/index.js @@ -2,23 +2,19 @@ import he from 'he'; import axios from 'axios'; -import { - find -} from 'lodash'; +import { find } from 'lodash'; import striptags from 'striptags'; export async function getSubtitles({ videoID, lang = 'en', }: { - videoID: string, - lang: 'en', - }) { - const { - data - } = await axios.get( - `https://youtube.com/get_video_info?video_id=${videoID}` - ); + videoID: string, + lang: 'en', +}) { + const { data } = await axios.get( + `https://youtube.com/get_video_info?video_id=${videoID}` + ); const decodedData = decodeURIComponent(data); @@ -28,25 +24,21 @@ export async function getSubtitles({ const regex = /({"captionTracks":.*isTranslatable":(true|false)}])/; const [match] = regex.exec(decodedData); - const { - captionTracks - } = JSON.parse(`${match}}`); + const { captionTracks } = JSON.parse(`${match}}`); const subtitle = find(captionTracks, { - vssId: `.${lang}` + vssId: `.${lang}`, }) || find(captionTracks, { - vssId: `a.${lang}` + vssId: `a.${lang}`, }); // * ensure we have found the correct subtitle lang if (!subtitle || (subtitle && !subtitle.baseUrl)) throw new Error(`Could not find ${lang} captions for ${videoID}`); - const { - data: transcript - } = await axios.get(subtitle.baseUrl); + const { data: transcript } = await axios.get(subtitle.baseUrl); const lines = transcript .replace('', '') .replace('', '') @@ -70,7 +62,7 @@ export async function getSubtitles({ return { start, dur, - text + text, }; });