style(eslint): add yarn lint and fix codestyle

This commit is contained in:
iam4x
2017-12-04 09:49:06 +01:00
parent 317e98bde0
commit e344fdd5f6
2 changed files with 14 additions and 21 deletions

View File

@@ -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",

View File

@@ -2,9 +2,7 @@
import he from 'he';
import axios from 'axios';
import {
find
} from 'lodash';
import { find } from 'lodash';
import striptags from 'striptags';
export async function getSubtitles({
@@ -14,9 +12,7 @@ export async function getSubtitles({
videoID: string,
lang: 'en',
}) {
const {
data
} = await axios.get(
const { data } = await axios.get(
`https://youtube.com/get_video_info?video_id=${videoID}`
);
@@ -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('<?xml version="1.0" encoding="utf-8" ?><transcript>', '')
.replace('</transcript>', '')
@@ -70,7 +62,7 @@ export async function getSubtitles({
return {
start,
dur,
text
text,
};
});