@inner-dj/common 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cory Sanin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ import type express from 'express';
2
+ import { Payload } from './index.js';
3
+ import type { ClientInterface, Method } from './ireceiver.js';
4
+ export declare class DebugClientInterface implements ClientInterface {
5
+ sendPayload(payload: Payload): Promise<boolean>;
6
+ registerRoute(method: Method, route: string, _fn: (req: express.Request, res: express.Response) => any): void;
7
+ registerGuide(html: string): number;
8
+ }
@@ -0,0 +1,14 @@
1
+ export class DebugClientInterface {
2
+ async sendPayload(payload) {
3
+ console.log(`Receiver requested the following:\n`, payload);
4
+ return true;
5
+ }
6
+ registerRoute(method, route, _fn) {
7
+ console.log(`method: ${method} route: ${route}`);
8
+ }
9
+ registerGuide(html) {
10
+ console.log('registered guide:\n', html);
11
+ return 1;
12
+ }
13
+ }
14
+ //# sourceMappingURL=debug-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug-interface.js","sourceRoot":"","sources":["../../src/debug-interface.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,oBAAoB;IAC7B,KAAK,CAAC,WAAW,CAAC,OAAgB;QAC9B,OAAO,CAAC,GAAG,CAAC,qCAAqC,EAAE,OAAO,CAAC,CAAC;QAC5D,OAAO,IAAI,CAAC;IAChB,CAAC;IAED,aAAa,CAAC,MAAc,EAAE,KAAa,EAAE,GAAyD;QAClG,OAAO,CAAC,GAAG,CAAC,WAAW,MAAM,WAAW,KAAK,EAAE,CAAC,CAAC;IACrD,CAAC;IAED,aAAa,CAAC,IAAY;QACtB,OAAO,CAAC,GAAG,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QACzC,OAAO,CAAC,CAAC;IACb,CAAC;CACJ"}
@@ -0,0 +1,61 @@
1
+ import { type ytdlpOptions, type sponsorblock, ytdlpDefaults, ytdlpExec, ytdlp } from './yt-dlp.js';
2
+ import { iReceiver, type iReceiverConfig, type iReceiverStatic, type ClientInterface, type Method } from './ireceiver.js';
3
+ import { DebugClientInterface } from './debug-interface.js';
4
+ export type YouTubeVideoID = string;
5
+ export type { ytdlpOptions, sponsorblock };
6
+ export { ytdlpDefaults, ytdlpExec, ytdlp };
7
+ export type { iReceiverConfig, iReceiverStatic, ClientInterface, Method };
8
+ export { iReceiver };
9
+ export { DebugClientInterface };
10
+ /**
11
+ * Encodes a payload to be sent over a socket
12
+ * @param payload any valid payload
13
+ * @param jwtSecret the JWT secret for signing
14
+ * @returns string ready to be sent
15
+ */
16
+ export declare function encodePayload(payload: Payload, jwtSecret: string): string;
17
+ /**
18
+ * parseint with wider range of accepted input types
19
+ * @param v input to parse
20
+ * @returns a number (or not a number)
21
+ */
22
+ export declare function notStupidParseInt(v: string | number | undefined): number;
23
+ /**
24
+ * Get a boolean config value
25
+ * @param envname environment variable to check
26
+ * @param cfg object that might have $key
27
+ * @param key key from the input object
28
+ * @param fallback the default value
29
+ * @returns computed boolean from the given sources
30
+ */
31
+ export declare function getBoolean<T>(envname: string, cfg: Partial<T> | undefined, key: keyof T, fallback: boolean): boolean;
32
+ /**
33
+ * Throw an error inline
34
+ * @param msg error message
35
+ */
36
+ export declare function throwNewError<T>(msg: string): T;
37
+ export type Payload = RegistrationPayload | AckPayload | NowPlayingPayload | SkipPayload | QueuePayload;
38
+ export interface PayloadBase {
39
+ type: string;
40
+ body?: any;
41
+ }
42
+ export interface AckPayload extends PayloadBase {
43
+ type: 'ack';
44
+ body?: never;
45
+ }
46
+ export interface RegistrationPayload extends PayloadBase {
47
+ type: 'reg';
48
+ body: string;
49
+ }
50
+ export interface NowPlayingPayload extends PayloadBase {
51
+ type: 'nowPlaying';
52
+ body: string;
53
+ }
54
+ export interface SkipPayload extends PayloadBase {
55
+ type: 'skip';
56
+ body?: never;
57
+ }
58
+ export interface QueuePayload extends PayloadBase {
59
+ type: 'queue';
60
+ body: string;
61
+ }
@@ -0,0 +1,46 @@
1
+ import { ytdlpDefaults, ytdlpExec, ytdlp } from './yt-dlp.js';
2
+ import jwt from 'jsonwebtoken';
3
+ import { iReceiver } from './ireceiver.js';
4
+ import { DebugClientInterface } from './debug-interface.js';
5
+ export { ytdlpDefaults, ytdlpExec, ytdlp };
6
+ export { iReceiver };
7
+ export { DebugClientInterface };
8
+ /**
9
+ * Encodes a payload to be sent over a socket
10
+ * @param payload any valid payload
11
+ * @param jwtSecret the JWT secret for signing
12
+ * @returns string ready to be sent
13
+ */
14
+ export function encodePayload(payload, jwtSecret) {
15
+ return jwt.sign(JSON.stringify(payload), jwtSecret);
16
+ }
17
+ /**
18
+ * parseint with wider range of accepted input types
19
+ * @param v input to parse
20
+ * @returns a number (or not a number)
21
+ */
22
+ export function notStupidParseInt(v) {
23
+ if (typeof v === 'number') {
24
+ return v;
25
+ }
26
+ return v === undefined ? NaN : parseInt(v);
27
+ }
28
+ /**
29
+ * Get a boolean config value
30
+ * @param envname environment variable to check
31
+ * @param cfg object that might have $key
32
+ * @param key key from the input object
33
+ * @param fallback the default value
34
+ * @returns computed boolean from the given sources
35
+ */
36
+ export function getBoolean(envname, cfg, key, fallback) {
37
+ return (process.env[envname] ?? `${cfg?.[key] ?? fallback}`) === 'true';
38
+ }
39
+ /**
40
+ * Throw an error inline
41
+ * @param msg error message
42
+ */
43
+ export function throwNewError(msg) {
44
+ throw new Error(msg);
45
+ }
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpG,OAAO,GAAG,MAAM,cAAc,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAiF,MAAM,gBAAgB,CAAC;AAC1H,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAI5D,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,CAAC;AACrB,OAAO,EAAE,oBAAoB,EAAE,CAAC;AAEhC;;;;;GAKG;AACH,MAAM,UAAU,aAAa,CAAC,OAAgB,EAAE,SAAiB;IAC7D,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,CAA8B;IAC5D,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;QACxB,OAAO,CAAC,CAAC;IACb,CAAC;IACD,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAI,OAAe,EAAE,GAA2B,EAAE,GAAY,EAAE,QAAiB;IACvG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,IAAI,QAAQ,EAAE,CAAC,KAAK,MAAM,CAAC;AAC5E,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAI,GAAW;IACxC,MAAM,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type express from 'express';
2
+ import type { Payload } from "./index.js";
3
+ export type Method = "all" | "get" | "post" | "put" | "delete" | "patch" | "options" | "head";
4
+ export interface ClientInterface {
5
+ sendPayload(payload: Payload): Promise<boolean>;
6
+ registerRoute(method: Method, route: string, fn: (req: express.Request, res: express.Response, next?: express.NextFunction) => any): any;
7
+ registerGuide(html: string): number;
8
+ }
9
+ export interface iReceiverConfig {
10
+ enabled: boolean;
11
+ }
12
+ export interface iReceiverStatic<T extends iReceiverConfig> {
13
+ new (config: T, web: ClientInterface): iReceiver<T>;
14
+ getConfig(cfg?: Partial<T>): T;
15
+ }
16
+ export declare abstract class iReceiver<T extends iReceiverConfig> {
17
+ protected config: T;
18
+ private web;
19
+ constructor(config: T, web: ClientInterface);
20
+ request: (url: string) => Promise<boolean>;
21
+ registerRoute: (method: Method, route: string, handler: (req: express.Request, res: express.Response, next?: express.NextFunction) => any) => void;
22
+ registerGuide: (html: string) => number;
23
+ start: () => void;
24
+ close: () => void;
25
+ }
@@ -0,0 +1,24 @@
1
+ ;
2
+ export class iReceiver {
3
+ config;
4
+ web;
5
+ constructor(config, web) {
6
+ this.config = config;
7
+ this.web = web;
8
+ }
9
+ request = (url) => {
10
+ return this.web.sendPayload({
11
+ type: 'queue',
12
+ body: url
13
+ });
14
+ };
15
+ registerRoute = (method, route, handler) => {
16
+ this.web.registerRoute(method, route, handler);
17
+ };
18
+ registerGuide = (html) => {
19
+ return this.web.registerGuide(html);
20
+ };
21
+ start = () => { };
22
+ close = () => { };
23
+ }
24
+ //# sourceMappingURL=ireceiver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ireceiver.js","sourceRoot":"","sources":["../../src/ireceiver.ts"],"names":[],"mappings":"AAaC,CAAC;AAOF,MAAM,OAAgB,SAAS;IACjB,MAAM,CAAI;IACZ,GAAG,CAAkB;IAE7B,YAAY,MAAS,EAAE,GAAoB;QACvC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED,OAAO,GAAG,CAAC,GAAW,EAAE,EAAE;QACtB,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;YACxB,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,GAAG;SACZ,CAAC,CAAC;IACP,CAAC,CAAA;IAED,aAAa,GAAG,CAAC,MAAc,EAAE,KAAa,EAAE,OAA0F,EAAE,EAAE;QAC1I,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;IACnD,CAAC,CAAA;IAED,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE;QAC7B,OAAO,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;IACxC,CAAC,CAAA;IAED,KAAK,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;IAClB,KAAK,GAAG,GAAG,EAAE,GAAG,CAAC,CAAC;CACrB"}
@@ -0,0 +1,17 @@
1
+ export type sponsorblock = 'sponsor' | 'selfpromo' | 'interaction' | 'intro' | 'outro' | 'preview' | 'hook' | 'filler' | 'music_offtopic';
2
+ export interface ytdlpOptions {
3
+ sponsorblock?: sponsorblock[];
4
+ sponsorblockAPI?: string;
5
+ optput?: string;
6
+ audioOnly?: boolean;
7
+ audioFormat?: string;
8
+ audioQuality?: number;
9
+ restrictFilenames?: boolean;
10
+ }
11
+ export declare const ytdlpDefaults: ytdlpOptions;
12
+ export declare function ytdlpExec(options: ytdlpOptions, url: string): Promise<void>;
13
+ export declare class ytdlp {
14
+ private options;
15
+ constructor(options: ytdlpOptions);
16
+ exec(url: string): Promise<void>;
17
+ }
@@ -0,0 +1,44 @@
1
+ import { spawn } from 'spawn-but-with-promises';
2
+ ;
3
+ export const ytdlpDefaults = {
4
+ sponsorblock: ['sponsor', 'selfpromo', 'interaction', 'music_offtopic'],
5
+ optput: '%(id)s.%(title)s.%(ext)s',
6
+ audioOnly: true,
7
+ restrictFilenames: true,
8
+ };
9
+ export async function ytdlpExec(options, url) {
10
+ const args = [];
11
+ if (options.sponsorblock?.length) {
12
+ args.push('--sponsorblock-remove', options.sponsorblock.join(','));
13
+ }
14
+ if (options.sponsorblockAPI) {
15
+ args.push('--sponsorblock-api', options.sponsorblockAPI);
16
+ }
17
+ if (options.restrictFilenames) {
18
+ args.push('--restrict-filenames');
19
+ }
20
+ if (options.optput) {
21
+ args.push('-o', options.optput);
22
+ }
23
+ if (options.audioOnly) {
24
+ args.push('-x');
25
+ if (options.audioFormat) {
26
+ args.push('--audio-format', options.audioFormat);
27
+ }
28
+ if (typeof options.audioQuality === 'number') {
29
+ args.push('--audio-quality', `${options.audioQuality}`);
30
+ }
31
+ }
32
+ args.push(url);
33
+ await spawn('yt-dlp', args, { rejectOnNonZero: true });
34
+ }
35
+ export class ytdlp {
36
+ options;
37
+ constructor(options) {
38
+ this.options = options;
39
+ }
40
+ exec(url) {
41
+ return ytdlpExec(this.options, url);
42
+ }
43
+ }
44
+ //# sourceMappingURL=yt-dlp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yt-dlp.js","sourceRoot":"","sources":["../../src/yt-dlp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAY/C,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAiB;IACvC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Ef,MAAM,KAAK,CAAC,QAAQ,EAAE,IAAI,EAAE,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,OAAO,KAAK;IACN,OAAO,CAAe;IAE9B,YAAY,OAAqB;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IAC3B,CAAC;IAED,IAAI,CAAC,GAAW;QACZ,OAAO,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;IACxC,CAAC;CACJ"}
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@inner-dj/common",
3
+ "version": "0.0.3",
4
+ "description": "common component of inner-dj",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://codeberg.org/sanin/inner-dj.git"
8
+ },
9
+ "license": "MIT",
10
+ "author": "Cory Sanin",
11
+ "type": "module",
12
+ "exports": {
13
+ ".": {
14
+ "types": "./lib/src/index.d.ts",
15
+ "import": "./lib/src/index.js"
16
+ }
17
+ },
18
+ "main": "./lib/src/index.js",
19
+ "types": "./lib/src/index.d.ts",
20
+ "files": [
21
+ "lib/src",
22
+ "!lib/**/*.js.map"
23
+ ],
24
+ "dependencies": {
25
+ "jsonwebtoken": "9.0.3",
26
+ "spawn-but-with-promises": "^1.0.4"
27
+ },
28
+ "devDependencies": {
29
+ "@sindresorhus/tsconfig": "8.1.0",
30
+ "@types/express": "^5.0.6",
31
+ "@types/jsonwebtoken": "^9.0.10",
32
+ "@types/node": "^24.12.4",
33
+ "express": "^5.2.1",
34
+ "typescript": "^6.0.3"
35
+ },
36
+ "scripts": {
37
+ "build": "tsc"
38
+ }
39
+ }