Use ES6 modules

This commit is contained in:
Mattéo Delabre 2020-07-15 19:31:09 +02:00
parent e7d87e3bbd
commit e352cca4d8
Signed by: matteo
GPG Key ID: AE3FBD02DC583ABB
5 changed files with 17 additions and 175 deletions

View File

@ -1,17 +1,9 @@
'use strict'; import util from 'util';
import request from 'request';
const util = require('util');
const request = require('request');
const cheerio = require('cheerio');
const YOUTUBE_BASE = 'https://www.youtube.com/%s'; const YOUTUBE_BASE = 'https://www.youtube.com/%s';
const WATCH_BASE = util.format(YOUTUBE_BASE, 'watch?v=%s'); const WATCH_BASE = util.format(YOUTUBE_BASE, 'watch?v=%s');
const PLAYER_REGEX = /ytplayer\.config = (\{.*?\});/;
const VIDEO_ID_REGEX = /watch\?v=([^&]*)/i;
// const END_SCREEN_BASE = util.format(YOUTUBE_BASE, 'get_endscreen?v=%s');
// const CARD_BASE = util.format(YOUTUBE_BASE, 'annotations_invideo?video_id=%s');
const playerRegex = /ytplayer\.config = (\{.*?\});/;
/** /**
* Fetch the `ytplayer.config` object for a YouTube video. * Fetch the `ytplayer.config` object for a YouTube video.
@ -20,7 +12,7 @@ const playerRegex = /ytplayer\.config = (\{.*?\});/;
* @param videoId Identifier of the video to fetch. * @param videoId Identifier of the video to fetch.
* @return The player configuration object. * @return The player configuration object.
*/ */
const getPlayerConfig = videoId => export const getPlayerConfig = videoId =>
{ {
const url = util.format(WATCH_BASE, videoId); const url = util.format(WATCH_BASE, videoId);
@ -38,7 +30,7 @@ const getPlayerConfig = videoId =>
// and the player_response subobject // and the player_response subobject
try try
{ {
const playerConfig = JSON.parse(body.match(playerRegex)[1]); const playerConfig = JSON.parse(body.match(PLAYER_REGEX)[1]);
playerConfig.args.player_response playerConfig.args.player_response
= JSON.parse(playerConfig.args.player_response); = JSON.parse(playerConfig.args.player_response);
resolve(playerConfig); resolve(playerConfig);
@ -51,8 +43,6 @@ const getPlayerConfig = videoId =>
}); });
}; };
exports.getPlayerConfig = getPlayerConfig;
/** /**
* Get metadata about a YouTube video. * Get metadata about a YouTube video.
* *
@ -60,13 +50,11 @@ exports.getPlayerConfig = getPlayerConfig;
* YouTube video, as obtained from `getPlayerConfig`. * YouTube video, as obtained from `getPlayerConfig`.
* @return Object containing the video metadata. * @return Object containing the video metadata.
*/ */
const getVideoMeta = playerConfig => ({ export const getVideoMeta = playerConfig => ({
videoId: playerConfig.args.player_response.videoDetails.videoId, videoId: playerConfig.args.player_response.videoDetails.videoId,
title: playerConfig.args.player_response.videoDetails.title, title: playerConfig.args.player_response.videoDetails.title,
}); });
exports.getVideoMeta = getVideoMeta;
/** /**
* Find videos linked from the endscreen of a YouTube video. * Find videos linked from the endscreen of a YouTube video.
* *
@ -74,7 +62,7 @@ exports.getVideoMeta = getVideoMeta;
* YouTube video, as obtained from `getPlayerConfig`. * YouTube video, as obtained from `getPlayerConfig`.
* @return List of identifiers of linked videos. * @return List of identifiers of linked videos.
*/ */
const getEndScreenVideos = playerConfig => export const getEndScreenVideos = playerConfig =>
{ {
const response = playerConfig.args.player_response; const response = playerConfig.args.player_response;
@ -89,8 +77,6 @@ const getEndScreenVideos = playerConfig =>
.map(rdr => rdr.endpoint.watchEndpoint.videoId); .map(rdr => rdr.endpoint.watchEndpoint.videoId);
}; };
exports.getEndScreenVideos = getEndScreenVideos;
/** /**
* Find videos linked from as cards from a YouTube video. * Find videos linked from as cards from a YouTube video.
* *
@ -98,7 +84,7 @@ exports.getEndScreenVideos = getEndScreenVideos;
* YouTube video, as obtained from `getPlayerConfig`. * YouTube video, as obtained from `getPlayerConfig`.
* @return List of identifiers of linked videos. * @return List of identifiers of linked videos.
*/ */
const getCardVideos = playerConfig => export const getCardVideos = playerConfig =>
{ {
const response = playerConfig.args.player_response; const response = playerConfig.args.player_response;
@ -113,5 +99,3 @@ const getCardVideos = playerConfig =>
.map(content => content.videoInfoCardContentRenderer) .map(content => content.videoInfoCardContentRenderer)
.map(rdr => rdr.action.watchEndpoint.videoId); .map(rdr => rdr.action.watchEndpoint.videoId);
}; };
exports.getCardVideos = getCardVideos;

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
const util = require('util'); import util from 'util';
const GRAPH_NODE = ' "%s" [label="%s"]'; const GRAPH_NODE = ' "%s" [label="%s"]';
const GRAPH_NODE_URL = ' "%s" [label="%s", URL="%s", fontcolor=blue]'; const GRAPH_NODE_URL = ' "%s" [label="%s", URL="%s", fontcolor=blue]';
@ -15,7 +15,7 @@ const GRAPH_LINK = ' "%s" -> "%s"';
* if a node has no URL. * if a node has no URL.
* @return DOT representation of the graph. * @return DOT representation of the graph.
*/ */
const graphToDOT = (graph, title = id => id, url = () => '') => export const graphToDOT = (graph, title = id => id, url = () => '') =>
{ {
const ser = graph.serialize(); const ser = graph.serialize();
@ -49,5 +49,3 @@ const graphToDOT = (graph, title = id => id, url = () => '') =>
+ '\n}' + '\n}'
); );
}; };
exports.graphToDOT = graphToDOT;

View File

@ -1,12 +1,10 @@
'use strict'; import Graph from 'graph-data-structure';
import fs from 'fs';
import path from 'path';
import util from 'util';
const Graph = require('graph-data-structure'); import * as api from './api.mjs';
const fs = require('fs'); import {graphToDOT} from './graph.mjs';
const path = require('path');
const util = require('util');
const api = require('./api');
const {graphToDOT} = require('./graph');
const YOUTUBE_WATCH = 'https://youtu.be/%s'; const YOUTUBE_WATCH = 'https://youtu.be/%s';

137
package-lock.json generated
View File

@ -4,11 +4,6 @@
"lockfileVersion": 1, "lockfileVersion": 1,
"requires": true, "requires": true,
"dependencies": { "dependencies": {
"@types/node": {
"version": "12.0.12",
"resolved": "https://registry.npmjs.org/@types/node/-/node-12.0.12.tgz",
"integrity": "sha512-Uy0PN4R5vgBUXFoJrKryf5aTk3kJ8Rv3PdlHjl6UaX+Cqp1QE0yPQ68MPXGrZOfG7gZVNDIJZYyot0B9ubXUrQ=="
},
"ajv": { "ajv": {
"version": "6.12.3", "version": "6.12.3",
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz", "resolved": "https://registry.npmjs.org/ajv/-/ajv-6.12.3.tgz",
@ -56,29 +51,11 @@
"tweetnacl": "^0.14.3" "tweetnacl": "^0.14.3"
} }
}, },
"boolbase": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/boolbase/-/boolbase-1.0.0.tgz",
"integrity": "sha1-aN/1++YMUes3cl6p4+0xDcwed24="
},
"caseless": { "caseless": {
"version": "0.12.0", "version": "0.12.0",
"resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz", "resolved": "https://registry.npmjs.org/caseless/-/caseless-0.12.0.tgz",
"integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw=" "integrity": "sha1-G2gcIf+EAzyCZUMJBolCDRhxUdw="
}, },
"cheerio": {
"version": "1.0.0-rc.3",
"resolved": "https://registry.npmjs.org/cheerio/-/cheerio-1.0.0-rc.3.tgz",
"integrity": "sha512-0td5ijfUPuubwLUu0OBoe98gZj8C/AA+RW3v67GPlGOrvxWjZmBXiBCRU+I8VEiNyJzjth40POfHiz2RB3gImA==",
"requires": {
"css-select": "~1.2.0",
"dom-serializer": "~0.1.1",
"entities": "~1.1.1",
"htmlparser2": "^3.9.1",
"lodash": "^4.15.0",
"parse5": "^3.0.1"
}
},
"combined-stream": { "combined-stream": {
"version": "1.0.8", "version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
@ -92,22 +69,6 @@
"resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz", "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.2.tgz",
"integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac=" "integrity": "sha1-tf1UIgqivFq1eqtxQMlAdUUDwac="
}, },
"css-select": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/css-select/-/css-select-1.2.0.tgz",
"integrity": "sha1-KzoRBTnFNV8c2NMUYj6HCxIeyFg=",
"requires": {
"boolbase": "~1.0.0",
"css-what": "2.1",
"domutils": "1.5.1",
"nth-check": "~1.0.1"
}
},
"css-what": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/css-what/-/css-what-2.1.3.tgz",
"integrity": "sha512-a+EPoD+uZiNfh+5fxw2nO9QwFa6nJe2Or35fGY6Ipw1R3R4AGz1d1TEZrCegvw2YTmZ0jXirGYlzxxpYSHwpEg=="
},
"dashdash": { "dashdash": {
"version": "1.14.1", "version": "1.14.1",
"resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz",
@ -121,37 +82,6 @@
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"dom-serializer": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-0.1.1.tgz",
"integrity": "sha512-l0IU0pPzLWSHBcieZbpOKgkIn3ts3vAh7ZuFyXNwJxJXk/c4Gwj9xaTJwIDVQCXawWD0qb3IzMGH5rglQaO0XA==",
"requires": {
"domelementtype": "^1.3.0",
"entities": "^1.1.1"
}
},
"domelementtype": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz",
"integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w=="
},
"domhandler": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz",
"integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==",
"requires": {
"domelementtype": "1"
}
},
"domutils": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/domutils/-/domutils-1.5.1.tgz",
"integrity": "sha1-3NhIiib1Y9YQeeSMn3t+Mjc2gs8=",
"requires": {
"dom-serializer": "0",
"domelementtype": "1"
}
},
"ecc-jsbn": { "ecc-jsbn": {
"version": "0.1.2", "version": "0.1.2",
"resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz", "resolved": "https://registry.npmjs.org/ecc-jsbn/-/ecc-jsbn-0.1.2.tgz",
@ -161,11 +91,6 @@
"safer-buffer": "^2.1.0" "safer-buffer": "^2.1.0"
} }
}, },
"entities": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/entities/-/entities-1.1.2.tgz",
"integrity": "sha512-f2LZMYl1Fzu7YSBKg+RoROelpOaNrcGmE9AZubeDfrCEia483oW4MI4VyFd5VNHIgQ/7qm1I0wUHK1eJnn2y2w=="
},
"extend": { "extend": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz",
@ -228,19 +153,6 @@
"har-schema": "^2.0.0" "har-schema": "^2.0.0"
} }
}, },
"htmlparser2": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
"integrity": "sha512-IgieNijUMbkDovyoKObU1DUhm1iwNYE/fuifEoEHfd1oZKZDaONBSkal7Y01shxsM49R4XaMdGez3WnF9UfiCQ==",
"requires": {
"domelementtype": "^1.3.1",
"domhandler": "^2.3.0",
"domutils": "^1.5.1",
"entities": "^1.1.1",
"inherits": "^2.0.1",
"readable-stream": "^3.1.1"
}
},
"http-signature": { "http-signature": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz", "resolved": "https://registry.npmjs.org/http-signature/-/http-signature-1.2.0.tgz",
@ -251,11 +163,6 @@
"sshpk": "^1.7.0" "sshpk": "^1.7.0"
} }
}, },
"inherits": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
"integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
},
"is-typedarray": { "is-typedarray": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
@ -297,11 +204,6 @@
"verror": "1.10.0" "verror": "1.10.0"
} }
}, },
"lodash": {
"version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
},
"mime-db": { "mime-db": {
"version": "1.44.0", "version": "1.44.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz",
@ -315,27 +217,11 @@
"mime-db": "1.44.0" "mime-db": "1.44.0"
} }
}, },
"nth-check": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/nth-check/-/nth-check-1.0.2.tgz",
"integrity": "sha512-WeBOdju8SnzPN5vTUJYxYUxLeXpCaVP5i5e0LF8fg7WORF2Wd7wFX/pk0tYZk7s8T+J7VLy0Da6J1+wCT0AtHg==",
"requires": {
"boolbase": "~1.0.0"
}
},
"oauth-sign": { "oauth-sign": {
"version": "0.9.0", "version": "0.9.0",
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz", "resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
"integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ==" "integrity": "sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ=="
}, },
"parse5": {
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/parse5/-/parse5-3.0.3.tgz",
"integrity": "sha512-rgO9Zg5LLLkfJF9E6CCmXlSE4UVceloys8JrFqCcHloC3usd/kJCyPDwH2SOlzix2j3xaP9sUX3e8+kvkuleAA==",
"requires": {
"@types/node": "*"
}
},
"performance-now": { "performance-now": {
"version": "2.1.0", "version": "2.1.0",
"resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz", "resolved": "https://registry.npmjs.org/performance-now/-/performance-now-2.1.0.tgz",
@ -356,16 +242,6 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.5.2.tgz",
"integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA==" "integrity": "sha512-N5ZAX4/LxJmF+7wN74pUD6qAh9/wnvdQcjq9TZjevvXzSUo7bfmw91saqMjzGS2xq91/odN2dW/WOl7qQHNDGA=="
}, },
"readable-stream": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.4.0.tgz",
"integrity": "sha512-jItXPLmrSR8jmTRmRWJXCnGJsfy85mB3Wd/uINMXA65yrnFo0cPClFIUWzo2najVNSl+mx7/4W8ttlLWJe99pQ==",
"requires": {
"inherits": "^2.0.3",
"string_decoder": "^1.1.1",
"util-deprecate": "^1.0.1"
}
},
"request": { "request": {
"version": "2.88.2", "version": "2.88.2",
"resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz", "resolved": "https://registry.npmjs.org/request/-/request-2.88.2.tgz",
@ -419,14 +295,6 @@
"tweetnacl": "~0.14.0" "tweetnacl": "~0.14.0"
} }
}, },
"string_decoder": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.2.0.tgz",
"integrity": "sha512-6YqyX6ZWEYguAxgZzHGL7SsCeGx3V2TtOTqZz1xSTSWnqsbWwbptafNyvf/ACquZUXV3DANr5BDIwNYe1mN42w==",
"requires": {
"safe-buffer": "~5.1.0"
}
},
"tough-cookie": { "tough-cookie": {
"version": "2.5.0", "version": "2.5.0",
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz", "resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.5.0.tgz",
@ -457,11 +325,6 @@
"punycode": "^2.1.0" "punycode": "^2.1.0"
} }
}, },
"util-deprecate": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
"integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8="
},
"uuid": { "uuid": {
"version": "3.4.0", "version": "3.4.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz", "resolved": "https://registry.npmjs.org/uuid/-/uuid-3.4.0.tgz",

View File

@ -5,10 +5,9 @@
"main": "src/index.js", "main": "src/index.js",
"license": "CC0", "license": "CC0",
"scripts": { "scripts": {
"build": "mkdir -p build && node explore build/maze.dot && dot -Tsvg build/maze.dot -o build/maze.svg" "build": "mkdir -p build && node explore/index.mjs build/maze.dot && dot -Tsvg build/maze.dot -o build/maze.svg"
}, },
"dependencies": { "dependencies": {
"cheerio": "1.0.0-rc.3",
"graph-data-structure": "^1.12.1", "graph-data-structure": "^1.12.1",
"request": "^2.88.2" "request": "^2.88.2"
} }