vdj 1.4.7 → 1.6.0

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.
@@ -1,8 +1,8 @@
1
- import { SearchType, Song, SongInfo, Logger } from '.';
2
- export interface IService {
3
- canSearch: boolean;
4
- fetch(targets: string[], logger?: Logger): Promise<Song[]>;
5
- search(queries: string[], searchType: SearchType, logger?: Logger): Promise<Song[]>;
6
- canFetch(content: string, logger?: Logger): Promise<boolean>;
7
- getSongInfo(songUrl: string, logger?: Logger): Promise<SongInfo>;
8
- }
1
+ import { SearchType, Song, SongInfo, Logger } from '.';
2
+ export interface IService {
3
+ canSearch: boolean;
4
+ fetch(targets: string[], logger?: Logger): Promise<Song[]>;
5
+ search(queries: string[], searchType: SearchType, logger?: Logger): Promise<Song[]>;
6
+ canFetch(content: string, logger?: Logger): Promise<boolean>;
7
+ getSongInfo(songUrl: string, logger?: Logger): Promise<SongInfo>;
8
+ }
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,5 @@
1
- import Playlist from './playlist';
2
- import Song from './song';
3
- import { IService } from './iService';
4
- import { SongInfo, SearchType, PlaylistSettings, PlaylistAddType, PlaylistAddResult, Logger } from './types';
5
- export { Playlist, IService, Song, PlaylistSettings, PlaylistAddType, PlaylistAddResult, SearchType, SongInfo, Logger };
1
+ import Playlist from './playlist';
2
+ import Song from './song';
3
+ import { IService } from './iService';
4
+ import { SongInfo, SearchType, PlaylistSettings, PlaylistAddType, PlaylistAddResult, Logger } from './types';
5
+ export { Playlist, IService, Song, PlaylistSettings, PlaylistAddType, PlaylistAddResult, SearchType, SongInfo, Logger };
@@ -1,10 +1,10 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Song = exports.Playlist = void 0;
7
- const playlist_1 = __importDefault(require("./playlist"));
8
- exports.Playlist = playlist_1.default;
9
- const song_1 = __importDefault(require("./song"));
10
- exports.Song = song_1.default;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Song = exports.Playlist = void 0;
7
+ const playlist_1 = __importDefault(require("./playlist"));
8
+ exports.Playlist = playlist_1.default;
9
+ const song_1 = __importDefault(require("./song"));
10
+ exports.Song = song_1.default;
@@ -1,24 +1,24 @@
1
- import { IService, Song, SearchType, PlaylistSettings, PlaylistAddType, PlaylistAddResult, Logger } from '.';
2
- export default class Playlist extends Array<Song> {
3
- private _pos;
4
- loop: boolean;
5
- autoplay: boolean;
6
- services: IService[];
7
- fallBackService?: IService;
8
- logger?: Logger;
9
- constructor(settings: PlaylistSettings);
10
- get pos(): number;
11
- get current(): Song;
12
- clear(): void;
13
- hasPrev(): boolean;
14
- prev(): boolean;
15
- hasNext(): boolean;
16
- next(): Promise<boolean>;
17
- shuffle(): this;
18
- add(input: string[], { service, position, playlistAddType, searchType, }?: {
19
- service?: IService;
20
- position?: number;
21
- playlistAddType?: PlaylistAddType;
22
- searchType?: SearchType;
23
- }): Promise<PlaylistAddResult>;
24
- }
1
+ import { IService, Song, SearchType, PlaylistSettings, PlaylistAddType, PlaylistAddResult, Logger } from '.';
2
+ export default class Playlist extends Array<Song> {
3
+ private _pos;
4
+ loop: boolean;
5
+ autoplay: boolean;
6
+ services: IService[];
7
+ fallBackService?: IService;
8
+ logger?: Logger;
9
+ constructor(settings: PlaylistSettings);
10
+ get pos(): number;
11
+ get current(): Song;
12
+ clear(): void;
13
+ hasPrev(): boolean;
14
+ prev(): boolean;
15
+ hasNext(): boolean;
16
+ next(): Promise<boolean>;
17
+ shuffle(): this;
18
+ add(input: string[], { service, position, playlistAddType, searchType, }?: {
19
+ service?: IService;
20
+ position?: number;
21
+ playlistAddType?: PlaylistAddType;
22
+ searchType?: SearchType;
23
+ }): Promise<PlaylistAddResult>;
24
+ }
@@ -1,126 +1,126 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- class Playlist extends Array {
13
- constructor(settings) {
14
- super();
15
- this._pos = 0;
16
- if (settings) {
17
- this.loop = settings.loop || false;
18
- this.autoplay = settings.autoplay || false;
19
- this.services = settings.services;
20
- this.fallBackService = settings.fallBackService;
21
- this.logger = settings.logger;
22
- }
23
- else {
24
- this.loop = false;
25
- this.autoplay = false;
26
- this.services = [];
27
- }
28
- }
29
- get pos() {
30
- return this._pos;
31
- }
32
- get current() {
33
- return this[this._pos];
34
- }
35
- clear() {
36
- this.splice(0, this.length);
37
- this._pos = 0;
38
- }
39
- hasPrev() {
40
- return this._pos > 0;
41
- }
42
- prev() {
43
- if (this.hasPrev()) {
44
- this._pos -= 1;
45
- return true;
46
- }
47
- if (this.loop) {
48
- this._pos = this.length - 1;
49
- return true;
50
- }
51
- return false;
52
- }
53
- hasNext() {
54
- return this._pos < this.length - 1;
55
- }
56
- next() {
57
- return __awaiter(this, void 0, void 0, function* () {
58
- if (this.current && this.current.loop)
59
- return true;
60
- if (this.hasNext()) {
61
- this._pos += 1;
62
- return true;
63
- }
64
- if (this.loop) {
65
- this._pos = 0;
66
- return true;
67
- }
68
- return false;
69
- });
70
- }
71
- shuffle() {
72
- for (let i = this.length - 1; i > 0; i--) {
73
- const j = Math.floor(Math.random() * (i + 1));
74
- const temp = this[i];
75
- this[i] = this[j];
76
- this[j] = temp;
77
- }
78
- return this;
79
- }
80
- add(input, { service = undefined, position = Infinity, playlistAddType = 'urls', searchType = 'song', } = {}) {
81
- return __awaiter(this, void 0, void 0, function* () {
82
- const services = service ? [service] : this.services;
83
- var added = [];
84
- var notFound = [];
85
- if (playlistAddType != 'searches') {
86
- for (const url of input) {
87
- var fetched = [];
88
- for (const service of services) {
89
- if (yield service.canFetch(url, this.logger)) {
90
- fetched = yield service.fetch([url], this.logger);
91
- if (fetched.length)
92
- break;
93
- }
94
- }
95
- if (!fetched.length && this.fallBackService) {
96
- if (typeof (this.logger) == 'function')
97
- this.logger("Couldn't fetch with services, using fallbackService.");
98
- fetched = yield this.fallBackService.fetch([url]);
99
- }
100
- if (!fetched.length)
101
- notFound.push(url);
102
- added = added.concat(fetched);
103
- }
104
- }
105
- else {
106
- for (const query of input) {
107
- for (const service of services) {
108
- if (service.canSearch) {
109
- var found = yield service.search([query], searchType, this.logger);
110
- if (!found.length)
111
- continue;
112
- added = added.concat(found);
113
- break;
114
- }
115
- }
116
- }
117
- }
118
- this.splice(position, 0, ...added);
119
- return {
120
- added: added,
121
- notFound: notFound
122
- };
123
- });
124
- }
125
- }
126
- exports.default = Playlist;
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ class Playlist extends Array {
13
+ constructor(settings) {
14
+ super();
15
+ this._pos = 0;
16
+ if (settings) {
17
+ this.loop = settings.loop || false;
18
+ this.autoplay = settings.autoplay || false;
19
+ this.services = settings.services;
20
+ this.fallBackService = settings.fallBackService;
21
+ this.logger = settings.logger;
22
+ }
23
+ else {
24
+ this.loop = false;
25
+ this.autoplay = false;
26
+ this.services = [];
27
+ }
28
+ }
29
+ get pos() {
30
+ return this._pos;
31
+ }
32
+ get current() {
33
+ return this[this._pos];
34
+ }
35
+ clear() {
36
+ this.splice(0, this.length);
37
+ this._pos = 0;
38
+ }
39
+ hasPrev() {
40
+ return this._pos > 0;
41
+ }
42
+ prev() {
43
+ if (this.hasPrev()) {
44
+ this._pos -= 1;
45
+ return true;
46
+ }
47
+ if (this.loop) {
48
+ this._pos = this.length - 1;
49
+ return true;
50
+ }
51
+ return false;
52
+ }
53
+ hasNext() {
54
+ return this._pos < this.length - 1;
55
+ }
56
+ next() {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (this.current && this.current.loop)
59
+ return true;
60
+ if (this.hasNext()) {
61
+ this._pos += 1;
62
+ return true;
63
+ }
64
+ if (this.loop) {
65
+ this._pos = 0;
66
+ return true;
67
+ }
68
+ return false;
69
+ });
70
+ }
71
+ shuffle() {
72
+ for (let i = this.length - 1; i > 0; i--) {
73
+ const j = Math.floor(Math.random() * (i + 1));
74
+ const temp = this[i];
75
+ this[i] = this[j];
76
+ this[j] = temp;
77
+ }
78
+ return this;
79
+ }
80
+ add(input_1) {
81
+ return __awaiter(this, arguments, void 0, function* (input, { service = undefined, position = Infinity, playlistAddType = 'urls', searchType = 'song', } = {}) {
82
+ const services = service ? [service] : this.services;
83
+ var added = [];
84
+ var notFound = [];
85
+ if (playlistAddType != 'searches') {
86
+ for (const url of input) {
87
+ var fetched = [];
88
+ for (const service of services) {
89
+ if (yield service.canFetch(url, this.logger)) {
90
+ fetched = yield service.fetch([url], this.logger);
91
+ if (fetched.length)
92
+ break;
93
+ }
94
+ }
95
+ if (!fetched.length && this.fallBackService) {
96
+ if (typeof (this.logger) == 'function')
97
+ this.logger("Couldn't fetch with services, using fallbackService.");
98
+ fetched = yield this.fallBackService.fetch([url]);
99
+ }
100
+ if (!fetched.length)
101
+ notFound.push(url);
102
+ added = added.concat(fetched);
103
+ }
104
+ }
105
+ else {
106
+ for (const query of input) {
107
+ for (const service of services) {
108
+ if (service.canSearch) {
109
+ var found = yield service.search([query], searchType, this.logger);
110
+ if (!found.length)
111
+ continue;
112
+ added = added.concat(found);
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ }
118
+ this.splice(position, 0, ...added);
119
+ return {
120
+ added: added,
121
+ notFound: notFound
122
+ };
123
+ });
124
+ }
125
+ }
126
+ exports.default = Playlist;
@@ -1,19 +1,18 @@
1
- /// <reference types="node" />
2
- import { Readable as ReadableStream } from 'stream';
3
- import { IService, SongInfo } from '.';
4
- export default abstract class Song {
5
- readonly service: IService;
6
- loop: boolean;
7
- live: boolean;
8
- seek: number;
9
- abstract readonly type: string;
10
- abstract readonly streamURL: string;
11
- abstract readonly URL: string;
12
- abstract info?: SongInfo;
13
- readonly title?: string;
14
- readonly playlistID?: string | number;
15
- constructor(service: IService);
16
- abstract getSongInfo(): Promise<SongInfo>;
17
- abstract stream(): Promise<ReadableStream> | ReadableStream | null;
18
- toggleLoop(): boolean;
19
- }
1
+ import { Readable as ReadableStream } from 'stream';
2
+ import { IService, SongInfo } from '.';
3
+ export default abstract class Song {
4
+ readonly service: IService;
5
+ loop: boolean;
6
+ live: boolean;
7
+ seek: number;
8
+ abstract readonly type: string;
9
+ abstract readonly streamURL: string;
10
+ abstract readonly URL: string;
11
+ abstract info?: SongInfo;
12
+ readonly title?: string;
13
+ readonly playlistID?: string | number;
14
+ constructor(service: IService);
15
+ abstract getSongInfo(): Promise<SongInfo>;
16
+ abstract stream(): Promise<ReadableStream> | ReadableStream | null;
17
+ toggleLoop(): boolean;
18
+ }
package/dist/core/song.js CHANGED
@@ -1,16 +1,16 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Song {
4
- constructor(service) {
5
- this.loop = false;
6
- this.live = false;
7
- this.seek = 0;
8
- this.service = service;
9
- Object.defineProperty(this, 'service', { value: service });
10
- }
11
- toggleLoop() {
12
- return this.loop = !this.loop;
13
- }
14
- ;
15
- }
16
- exports.default = Song;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class Song {
4
+ constructor(service) {
5
+ this.loop = false;
6
+ this.live = false;
7
+ this.seek = 0;
8
+ this.service = service;
9
+ Object.defineProperty(this, 'service', { value: service });
10
+ }
11
+ toggleLoop() {
12
+ return this.loop = !this.loop;
13
+ }
14
+ ;
15
+ }
16
+ exports.default = Song;
@@ -1,40 +1,39 @@
1
- /// <reference types="node" />
2
- import { IService, Song } from ".";
3
- export declare type SongInfo = {
4
- full: boolean;
5
- metadataType: string;
6
- url: string;
7
- custom?: any;
8
- title?: string;
9
- duration?: number;
10
- artist?: string[];
11
- album?: string;
12
- albumartist?: string[];
13
- disk?: {
14
- no: number;
15
- of: number;
16
- };
17
- track?: {
18
- no: number;
19
- of: number;
20
- };
21
- date?: Date | string;
22
- genre?: string[];
23
- img?: Buffer;
24
- imgURL?: string;
25
- imgFormat?: string;
26
- };
27
- export declare type Logger = (x: string) => any;
28
- export declare type SearchType = 'song' | 'playlist';
29
- export declare type PlaylistAddType = 'searches' | 'urls';
30
- export declare type PlaylistAddResult = {
31
- added: Song[];
32
- notFound: string[];
33
- };
34
- export declare type PlaylistSettings = {
35
- services: IService[];
36
- loop?: boolean;
37
- autoplay?: boolean;
38
- fallBackService?: IService;
39
- logger?: Logger;
40
- };
1
+ import { IService, Song } from ".";
2
+ export type SongInfo = {
3
+ full: boolean;
4
+ metadataType: string;
5
+ url: string;
6
+ custom?: any;
7
+ title?: string;
8
+ duration?: number;
9
+ artist?: string[];
10
+ album?: string;
11
+ albumartist?: string[];
12
+ disk?: {
13
+ no: number;
14
+ of: number;
15
+ };
16
+ track?: {
17
+ no: number;
18
+ of: number;
19
+ };
20
+ date?: Date | string;
21
+ genre?: string[];
22
+ img?: Buffer;
23
+ imgURL?: string;
24
+ imgFormat?: string;
25
+ };
26
+ export type Logger = (x: string) => any;
27
+ export type SearchType = 'song' | 'playlist';
28
+ export type PlaylistAddType = 'searches' | 'urls';
29
+ export type PlaylistAddResult = {
30
+ added: Song[];
31
+ notFound: string[];
32
+ };
33
+ export type PlaylistSettings = {
34
+ services: IService[];
35
+ loop?: boolean;
36
+ autoplay?: boolean;
37
+ fallBackService?: IService;
38
+ logger?: Logger;
39
+ };
@@ -1,2 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,13 +1,13 @@
1
- import API = require('simple-youtube-api');
2
- import { IService, SearchType, SongInfo, Logger } from '../../core/';
3
- import YouTubeSong from './song';
4
- export default class YouTubeService implements IService {
5
- readonly api: API;
6
- canSearch: boolean;
7
- type: string;
8
- constructor(key: string);
9
- fetch(targets: string[], logger?: Logger): Promise<YouTubeSong[]>;
10
- search(queries: string[], searchType: SearchType, logger?: Logger): Promise<YouTubeSong[]>;
11
- canFetch(target: string, logger?: Logger): Promise<boolean>;
12
- getSongInfo(url: string, logger?: Logger): Promise<SongInfo>;
13
- }
1
+ import API = require('simple-youtube-api');
2
+ import { IService, SearchType, SongInfo, Logger } from '../../core/';
3
+ import YouTubeSong from './song';
4
+ export default class YouTubeService implements IService {
5
+ readonly api: API;
6
+ canSearch: boolean;
7
+ type: string;
8
+ constructor(key: string);
9
+ fetch(targets: string[], logger?: Logger): Promise<YouTubeSong[]>;
10
+ search(queries: string[], searchType: SearchType, logger?: Logger): Promise<YouTubeSong[]>;
11
+ canFetch(target: string, logger?: Logger): Promise<boolean>;
12
+ getSongInfo(url: string, logger?: Logger): Promise<SongInfo>;
13
+ }