summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--README.md11
-rw-r--r--config.example3
-rw-r--r--package-lock.json507
-rw-r--r--package.json16
-rwxr-xr-xyta170
6 files changed, 709 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..0fcd8d5
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+config
+node_modules
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7737cd5
--- /dev/null
+++ b/README.md
@@ -0,0 +1,11 @@
+# YT Audio Player
+Command line player to listen to YT videos written in node
+Saves bandwidth and streams only the audio part of the videos
+
+# Requirements
+Node.js and npm installed
+
+# Before use
+1. Install node packages with `npm i`
+2. Copy `config.example` as `example` and put your YT API key inside.
+3. Run it with `./yta`
diff --git a/config.example b/config.example
new file mode 100644
index 0000000..52a4b00
--- /dev/null
+++ b/config.example
@@ -0,0 +1,3 @@
+module.exports = {
+ YTKEY: ""
+};
diff --git a/package-lock.json b/package-lock.json
new file mode 100644
index 0000000..d530c34
--- /dev/null
+++ b/package-lock.json
@@ -0,0 +1,507 @@
+{
+ "name": "yta",
+ "version": "1.0.0",
+ "lockfileVersion": 2,
+ "requires": true,
+ "packages": {
+ "": {
+ "name": "yta",
+ "version": "1.0.0",
+ "license": "ISC",
+ "dependencies": {
+ "colors": "^1.4.0",
+ "node-fetch": "^2.6.1",
+ "prompt": "^1.1.0"
+ }
+ },
+ "node_modules/async": {
+ "version": "0.9.2",
+ "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
+ "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
+ },
+ "node_modules/balanced-match": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
+ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
+ },
+ "node_modules/brace-expansion": {
+ "version": "1.1.11",
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
+ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+ "dependencies": {
+ "balanced-match": "^1.0.0",
+ "concat-map": "0.0.1"
+ }
+ },
+ "node_modules/colors": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
+ "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA==",
+ "engines": {
+ "node": ">=0.1.90"
+ }
+ },
+ "node_modules/concat-map": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
+ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+ },
+ "node_modules/cycle": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
+ "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI=",
+ "engines": {
+ "node": ">=0.4.0"
+ }
+ },
+ "node_modules/deep-equal": {
+ "version": "0.2.2",
+ "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz",
+ "integrity": "sha1-hLdFiW80xoTpjyzg5Cq69Du6AX0="
+ },
+ "node_modules/eyes": {
+ "version": "0.1.8",
+ "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
+ "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A=",
+ "engines": {
+ "node": "> 0.1.90"
+ }
+ },
+ "node_modules/fs.realpath": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
+ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
+ },
+ "node_modules/glob": {
+ "version": "7.1.7",
+ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz",
+ "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==",
+ "dependencies": {
+ "fs.realpath": "^1.0.0",
+ "inflight": "^1.0.4",
+ "inherits": "2",
+ "minimatch": "^3.0.4",
+ "once": "^1.3.0",
+ "path-is-absolute": "^1.0.0"
+ },
+ "engines": {
+ "node": "*"
+ },
+ "funding": {
+ "url": "https://github.com/sponsors/isaacs"
+ }
+ },
+ "node_modules/i": {
+ "version": "0.3.6",
+ "resolved": "https://registry.npmjs.org/i/-/i-0.3.6.tgz",
+ "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0=",
+ "engines": {
+ "node": ">=0.4"
+ }
+ },
+ "node_modules/inflight": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
+ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
+ "dependencies": {
+ "once": "^1.3.0",
+ "wrappy": "1"
+ }
+ },
+ "node_modules/inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
+ },
+ "node_modules/isstream": {
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
+ "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
+ },
+ "node_modules/minimatch": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
+ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+ "dependencies": {
+ "brace-expansion": "^1.1.7"
+ },
+ "engines": {
+ "node": "*"
+ }
+ },
+ "node_modules/minimist": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
+ },
+ "node_modules/mkdirp": {
+ "version": "0.5.5",
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
+ "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
+ "dependencies": {
+ "minimist": "^1.2.5"
+ },
+ "bin": {
+ "mkdirp": "bin/cmd.js"
+ }
+ },
+ "node_modules/mute-stream": {
+ "version": "0.0.8",
+ "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
+ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
+ },
+ "node_modules/ncp": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz",
+ "integrity": "sha1-0VNn5cuHQyuhF9K/gP30Wuz7QkY=",
+ "bin": {
+ "ncp": "bin/ncp"
+ }
+ },
+ "node_modules/node-fetch": {
+ "version": "2.6.1",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
+ "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw==",
+ "engines": {
+ "node": "4.x || >=6.0.0"
+ }
+ },
+ "node_modules/once": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
+ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
+ "dependencies": {
+ "wrappy": "1"
+ }
+ },
+ "node_modules/path-is-absolute": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
+ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=",
+ "engines": {
+ "node": ">=0.10.0"
+ }
+ },
+ "node_modules/prompt": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.1.0.tgz",
+ "integrity": "sha512-ec1vUPXCplDBDUVD8uPa3XGA+OzLrO40Vxv3F1uxoiZGkZhdctlK2JotcHq5X6ExjocDOGwGdCSXloGNyU5L1Q==",
+ "dependencies": {
+ "colors": "^1.1.2",
+ "read": "1.0.x",
+ "revalidator": "0.1.x",
+ "utile": "0.3.x",
+ "winston": "2.x"
+ },
+ "engines": {
+ "node": ">= 0.6.6"
+ }
+ },
+ "node_modules/read": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
+ "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
+ "dependencies": {
+ "mute-stream": "~0.0.4"
+ },
+ "engines": {
+ "node": ">=0.8"
+ }
+ },
+ "node_modules/revalidator": {
+ "version": "0.1.8",
+ "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
+ "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs=",
+ "engines": {
+ "node": ">= 0.4.0"
+ }
+ },
+ "node_modules/rimraf": {
+ "version": "2.7.1",
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
+ "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
+ "dependencies": {
+ "glob": "^7.1.3"
+ },
+ "bin": {
+ "rimraf": "bin.js"
+ }
+ },
+ "node_modules/stack-trace": {
+ "version": "0.0.10",
+ "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
+ "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA=",
+ "engines": {
+ "node": "*"
+ }
+ },
+ "node_modules/utile": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/utile/-/utile-0.3.0.tgz",
+ "integrity": "sha1-E1LDQOuCDk2N26A5pPv6oy7U7zo=",
+ "dependencies": {
+ "async": "~0.9.0",
+ "deep-equal": "~0.2.1",
+ "i": "0.3.x",
+ "mkdirp": "0.x.x",
+ "ncp": "1.0.x",
+ "rimraf": "2.x.x"
+ },
+ "engines": {
+ "node": ">= 0.8.0"
+ }
+ },
+ "node_modules/winston": {
+ "version": "2.4.5",
+ "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz",
+ "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==",
+ "dependencies": {
+ "async": "~1.0.0",
+ "colors": "1.0.x",
+ "cycle": "1.0.x",
+ "eyes": "0.1.x",
+ "isstream": "0.1.x",
+ "stack-trace": "0.0.x"
+ },
+ "engines": {
+ "node": ">= 0.10.0"
+ }
+ },
+ "node_modules/winston/node_modules/async": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
+ "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
+ },
+ "node_modules/winston/node_modules/colors": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
+ "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs=",
+ "engines": {
+ "node": ">=0.1.90"
+ }
+ },
+ "node_modules/wrappy": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
+ }
+ },
+ "dependencies": {
+ "async": {
+ "version": "0.9.2",
+ "resolved": "https://registry.npmjs.org/async/-/async-0.9.2.tgz",
+ "integrity": "sha1-rqdNXmHB+JlhO/ZL2mbUx48v0X0="
+ },
+ "balanced-match": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
+ "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
+ },
+ "brace-expansion": {
+ "version": "1.1.11",
+ "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
+ "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
+ "requires": {
+ "balanced-match": "^1.0.0",
+ "concat-map": "0.0.1"
+ }
+ },
+ "colors": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/colors/-/colors-1.4.0.tgz",
+ "integrity": "sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA=="
+ },
+ "concat-map": {
+ "version": "0.0.1",
+ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
+ "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s="
+ },
+ "cycle": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/cycle/-/cycle-1.0.3.tgz",
+ "integrity": "sha1-IegLK+hYD5i0aPN5QwZisEbDStI="
+ },
+ "deep-equal": {
+ "version": "0.2.2",
+ "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-0.2.2.tgz",
+ "integrity": "sha1-hLdFiW80xoTpjyzg5Cq69Du6AX0="
+ },
+ "eyes": {
+ "version": "0.1.8",
+ "resolved": "https://registry.npmjs.org/eyes/-/eyes-0.1.8.tgz",
+ "integrity": "sha1-Ys8SAjTGg3hdkCNIqADvPgzCC8A="
+ },
+ "fs.realpath": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz",
+ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8="
+ },
+ "glob": {
+ "version": "7.1.7",
+ "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.7.tgz",
+ "integrity": "sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==",
+ "requires": {
+ "fs.realpath": "^1.0.0",
+ "inflight": "^1.0.4",
+ "inherits": "2",
+ "minimatch": "^3.0.4",
+ "once": "^1.3.0",
+ "path-is-absolute": "^1.0.0"
+ }
+ },
+ "i": {
+ "version": "0.3.6",
+ "resolved": "https://registry.npmjs.org/i/-/i-0.3.6.tgz",
+ "integrity": "sha1-2WyScyB28HJxG2sQ/X1PZa2O4j0="
+ },
+ "inflight": {
+ "version": "1.0.6",
+ "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz",
+ "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=",
+ "requires": {
+ "once": "^1.3.0",
+ "wrappy": "1"
+ }
+ },
+ "inherits": {
+ "version": "2.0.4",
+ "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz",
+ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ=="
+ },
+ "isstream": {
+ "version": "0.1.2",
+ "resolved": "https://registry.npmjs.org/isstream/-/isstream-0.1.2.tgz",
+ "integrity": "sha1-R+Y/evVa+m+S4VAOaQ64uFKcCZo="
+ },
+ "minimatch": {
+ "version": "3.0.4",
+ "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
+ "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
+ "requires": {
+ "brace-expansion": "^1.1.7"
+ }
+ },
+ "minimist": {
+ "version": "1.2.5",
+ "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz",
+ "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw=="
+ },
+ "mkdirp": {
+ "version": "0.5.5",
+ "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-0.5.5.tgz",
+ "integrity": "sha512-NKmAlESf6jMGym1++R0Ra7wvhV+wFW63FaSOFPwRahvea0gMUcGUhVeAg/0BC0wiv9ih5NYPB1Wn1UEI1/L+xQ==",
+ "requires": {
+ "minimist": "^1.2.5"
+ }
+ },
+ "mute-stream": {
+ "version": "0.0.8",
+ "resolved": "https://registry.npmjs.org/mute-stream/-/mute-stream-0.0.8.tgz",
+ "integrity": "sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA=="
+ },
+ "ncp": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/ncp/-/ncp-1.0.1.tgz",
+ "integrity": "sha1-0VNn5cuHQyuhF9K/gP30Wuz7QkY="
+ },
+ "node-fetch": {
+ "version": "2.6.1",
+ "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.1.tgz",
+ "integrity": "sha512-V4aYg89jEoVRxRb2fJdAg8FHvI7cEyYdVAh94HH0UIK8oJxUfkjlDQN9RbMx+bEjP7+ggMiFRprSti032Oipxw=="
+ },
+ "once": {
+ "version": "1.4.0",
+ "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz",
+ "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=",
+ "requires": {
+ "wrappy": "1"
+ }
+ },
+ "path-is-absolute": {
+ "version": "1.0.1",
+ "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
+ "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18="
+ },
+ "prompt": {
+ "version": "1.1.0",
+ "resolved": "https://registry.npmjs.org/prompt/-/prompt-1.1.0.tgz",
+ "integrity": "sha512-ec1vUPXCplDBDUVD8uPa3XGA+OzLrO40Vxv3F1uxoiZGkZhdctlK2JotcHq5X6ExjocDOGwGdCSXloGNyU5L1Q==",
+ "requires": {
+ "colors": "^1.1.2",
+ "read": "1.0.x",
+ "revalidator": "0.1.x",
+ "utile": "0.3.x",
+ "winston": "2.x"
+ }
+ },
+ "read": {
+ "version": "1.0.7",
+ "resolved": "https://registry.npmjs.org/read/-/read-1.0.7.tgz",
+ "integrity": "sha1-s9oZvQUkMal2cdRKQmNK33ELQMQ=",
+ "requires": {
+ "mute-stream": "~0.0.4"
+ }
+ },
+ "revalidator": {
+ "version": "0.1.8",
+ "resolved": "https://registry.npmjs.org/revalidator/-/revalidator-0.1.8.tgz",
+ "integrity": "sha1-/s5hv6DBtSoga9axgZgYS91SOjs="
+ },
+ "rimraf": {
+ "version": "2.7.1",
+ "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-2.7.1.tgz",
+ "integrity": "sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w==",
+ "requires": {
+ "glob": "^7.1.3"
+ }
+ },
+ "stack-trace": {
+ "version": "0.0.10",
+ "resolved": "https://registry.npmjs.org/stack-trace/-/stack-trace-0.0.10.tgz",
+ "integrity": "sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA="
+ },
+ "utile": {
+ "version": "0.3.0",
+ "resolved": "https://registry.npmjs.org/utile/-/utile-0.3.0.tgz",
+ "integrity": "sha1-E1LDQOuCDk2N26A5pPv6oy7U7zo=",
+ "requires": {
+ "async": "~0.9.0",
+ "deep-equal": "~0.2.1",
+ "i": "0.3.x",
+ "mkdirp": "0.x.x",
+ "ncp": "1.0.x",
+ "rimraf": "2.x.x"
+ }
+ },
+ "winston": {
+ "version": "2.4.5",
+ "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.5.tgz",
+ "integrity": "sha512-TWoamHt5yYvsMarGlGEQE59SbJHqGsZV8/lwC+iCcGeAe0vUaOh+Lv6SYM17ouzC/a/LB1/hz/7sxFBtlu1l4A==",
+ "requires": {
+ "async": "~1.0.0",
+ "colors": "1.0.x",
+ "cycle": "1.0.x",
+ "eyes": "0.1.x",
+ "isstream": "0.1.x",
+ "stack-trace": "0.0.x"
+ },
+ "dependencies": {
+ "async": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/async/-/async-1.0.0.tgz",
+ "integrity": "sha1-+PwEyjoTeErenhZBr5hXjPvWR6k="
+ },
+ "colors": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/colors/-/colors-1.0.3.tgz",
+ "integrity": "sha1-BDP0TYCWgP3rYO0mDxsMJi6CpAs="
+ }
+ }
+ },
+ "wrappy": {
+ "version": "1.0.2",
+ "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
+ "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
+ }
+ }
+}
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..9ace161
--- /dev/null
+++ b/package.json
@@ -0,0 +1,16 @@
+{
+ "name": "yta",
+ "version": "1.0.0",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "author": "",
+ "license": "ISC",
+ "description": "",
+ "dependencies": {
+ "colors": "^1.4.0",
+ "node-fetch": "^2.6.1",
+ "prompt": "^1.1.0"
+ }
+}
diff --git a/yta b/yta
new file mode 100755
index 0000000..851e849
--- /dev/null
+++ b/yta
@@ -0,0 +1,170 @@
+#!/usr/bin/env node
+const spawn = require('child_process').spawn;
+const colors = require('colors');
+const prompt = require('prompt');
+const fetch = require('node-fetch');
+const { YTKEY } = require('./config');
+
+let data = {ids: [], titles: [], descriptions: [], channels: [], durations: []};
+
+const clearOutput = () => console.clear();
+
+const showError = (msg) => console.log(colors.red('Error'), ' - ', msg);
+
+const showMsg = (msg) => console.log(colors.green(msg));
+
+const showOsd = () => {
+ data.ids.forEach((id, i) => {
+ console.log(`${colors.yellow(i+1)}. ${colors.cyan(data.titles[i])} ${colors.green('['+data.durations[i]+']')} ${colors.red(data.channels[i])}`);
+ });
+ console.log('');
+};
+
+const showPlaying = (n) => console.log(`${colors.green('Currently playing:\n------------------')}\n${colors.yellow('Title:')} ${colors.cyan(data.titles[n])}\n${colors.yellow('Description:')} ${colors.cyan(data.descriptions[n])}\n${colors.yellow('Channel:')} ${colors.cyan(data.channels[n])}\n${colors.yellow('Length:')} ${colors.cyan(data.durations[n])}\n`);
+
+const showPlaylist = (r,n) => console.log(r.map(x=>x===n?(colors.yellow(x+'. '+data.titles[x-1])):(colors.cyan(x+'. '+data.titles[x-1]))).join('\n'),'\n');
+
+const showHelp = () => console.log(colors.green('YT audio player\n---------------\n1. Type song name and press [ENTER] to search it in YT\n2. Type result number and press [ENTER] to play the song\n3. Type a range of songs (ex. [2-5]) to play them in a row\n4. Type "h" and press [ENTER] to see this help page\n5. Type "q" and press [ENTER] to quit YT audio player\n'));
+
+const searchUrl = (q) => `https://www.googleapis.com/youtube/v3/search?part=snippet&partcontentDetails&maxResults=20&q=${q}&type=video&key=${YTKEY}`;
+
+const detailsUrl = (a) => `https://www.googleapis.com/youtube/v3/videos?part=contentDetails&id=${a.join(',')}&key=${YTKEY}`;
+
+const isSongRange = q => q.match(/^[0-9]+-[0-9]+$/);
+
+const isSongName = q => q.match(/.{3,}/);
+
+const isSongNumber = q => q.match(/^[0-9]+$/) && parseInt(q) <= data.ids.length;
+
+const playNr = (n) => spawn('mpv', ['--no-video', '--msg-level=all=no,statusline=status', `https://www.youtube.com/watch?v=${data.ids[parseInt(n)]}`], { stdio: 'inherit' });
+
+const playNext = (r, n) => {
+ clearOutput();
+ showMsg('Playlist:\n---------');
+ showPlaylist(r, n);
+ showPlaying(n-1);
+
+ const player = playNr(n-1);
+
+ player.on('close', () => {
+ if (n < r[r.length-1]){
+ playNext(r, n+1);
+ } else {
+ clearOutput();
+ showOsd();
+ showPrompt();
+ }
+ });
+};
+
+const handleSongRange = (q) => {
+ if (data.ids.length > 0) {
+ const [a,b] = q.split('-').map(n=>parseInt(n));
+ if (a<b){
+ const range = [...Array(b-a+1).keys()].map(n=>n+a);
+ playNext(range, range[0]);
+ } else {
+ clearOutput();
+ showOsd();
+ showError('invalid range, try again');
+ showPrompt();
+ }
+ } else {
+ clearOutput();
+ showError('first search for the videos');
+ showPrompt();
+ }
+};
+
+const handleSongName = (q) => (
+ fetch(searchUrl(q))
+ .then(res => res.json())
+ .then(json => presentResults(json))
+ .catch(e => console.log(e))
+);
+
+const handleSongNumber = (q) => {
+ const nr = parseInt(q) - 1;
+ clearOutput();
+ showPlaying(nr);
+ const player = playNr(nr);
+ player.on('close', () => {
+ clearOutput();
+ showOsd();
+ showPrompt();
+ });
+};
+
+const handleHelp = () => {
+ clearOutput();
+ showHelp();
+ showPrompt();
+};
+
+const handleQuit = () => {
+ clearOutput();
+ showMsg('Quiting YT audio player...');
+ return 0;
+};
+
+const handleWrongInput = () => {
+ clearOutput();
+ showOsd();
+ showError('wrong input');
+ showPrompt();
+};
+
+const getDurations = (ids) => (
+ fetch(detailsUrl(ids))
+ .then(res => res.json())
+ .then(json => json.items.map(i => i.contentDetails.duration.replace(/(PT|S)/g,'').split(/[A-Z]/g).map(d => d.padStart(2, '0')).join(':')))
+ .catch(e => console.log(e))
+);
+
+const presentResults = (results) => {
+ data.titles = results.items.map(result => result.snippet.title);
+ data.descriptions = results.items.map(result => result.snippet.description);
+ data.channels = results.items.map(result => result.snippet.channelTitle);
+ data.ids = results.items.map(result => result.id.videoId);
+ getDurations(data.ids).then(durations => {
+ data.durations = durations;
+ clearOutput();
+ showOsd();
+ showPrompt();
+ });
+};
+
+const handlePrompt = (err, { query }) => {
+ if (err) {
+ console.log(err);
+ return 1;
+ }
+
+ if (isSongRange(query)) {
+ handleSongRange(query);
+ } else if (isSongName(query)) {
+ handleSongName(query);
+ } else if (isSongNumber(query)) {
+ handleSongNumber(query);
+ } else if (query === 'h') {
+ handleHelp();
+ } else if (query === 'q') {
+ handleQuit();
+ } else {
+ handleWrongInput();
+ }
+};
+
+const showPrompt = () => {
+ prompt.message = "";
+ prompt.delimiter = "";
+ prompt.start();
+ prompt.get({
+ name: 'query',
+ description: 'YT Search ([h]elp, [q]uit):',
+ required: true,
+ }, handlePrompt);
+}
+
+clearOutput();
+showPrompt();