@supasayan/ytm 1.0.1 → 1.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/bin/cli.js CHANGED
@@ -3,28 +3,49 @@
3
3
  const path = require('path');
4
4
  const { spawn } = require('child_process');
5
5
 
6
+ const net = require('net');
7
+
6
8
  console.log('Starting YTM Downloader...');
7
9
 
8
10
  // Path to Express server index.js
9
11
  const serverPath = path.join(__dirname, '../server/index.js');
10
12
 
11
- const port = process.env.PORT || '3001';
12
-
13
- // Spawn the backend server as a child process of Node.
14
- // This preserves the ESM package type requirements of the server directory.
15
- const server = spawn('node', [serverPath], {
16
- env: {
17
- ...process.env,
18
- NODE_ENV: 'production',
19
- PORT: port
20
- },
21
- stdio: 'inherit'
22
- });
13
+ function getFreePort(startPort) {
14
+ return new Promise((resolve) => {
15
+ const server = net.createServer();
16
+ server.once('error', (err) => {
17
+ if (err.code === 'EADDRINUSE') {
18
+ resolve(getFreePort(startPort + 1));
19
+ }
20
+ });
21
+ server.once('listening', () => {
22
+ server.close(() => {
23
+ resolve(startPort);
24
+ });
25
+ });
26
+ server.listen(startPort, '127.0.0.1');
27
+ });
28
+ }
29
+
30
+ async function run() {
31
+ const defaultPort = parseInt(process.env.PORT || '3001', 10);
32
+ const port = await getFreePort(defaultPort);
23
33
 
24
- // Give the server a moment to spin up, then open the browser
25
- setTimeout(() => {
26
- const url = `http://127.0.0.1:${port}`;
27
- console.log(`Opening browser to ${url}`);
34
+ // Spawn the backend server as a child process of Node.
35
+ // This preserves the ESM package type requirements of the server directory.
36
+ const server = spawn('node', [serverPath], {
37
+ env: {
38
+ ...process.env,
39
+ NODE_ENV: 'production',
40
+ PORT: port.toString()
41
+ },
42
+ stdio: 'inherit'
43
+ });
44
+
45
+ // Give the server a moment to spin up, then open the browser
46
+ setTimeout(() => {
47
+ const url = `http://127.0.0.1:${port}`;
48
+ console.log(`Opening browser to ${url}`);
28
49
 
29
50
  // Use macOS 'open' utility to launch default browser
30
51
  const opener = spawn('open', [url]);
@@ -42,3 +63,6 @@ process.on('SIGTERM', () => {
42
63
  server.kill('SIGTERM');
43
64
  process.exit(0);
44
65
  });
66
+ }
67
+
68
+ run();
package/main.js CHANGED
@@ -1,11 +1,29 @@
1
1
  const { app, BrowserWindow } = require('electron');
2
2
  const path = require('path');
3
3
  const { fork } = require('child_process');
4
+ const net = require('net');
4
5
 
5
6
  let serverProcess = null;
6
7
  let mainWindow = null;
7
8
 
8
- function startBackend() {
9
+ function getFreePort(startPort) {
10
+ return new Promise((resolve) => {
11
+ const server = net.createServer();
12
+ server.once('error', (err) => {
13
+ if (err.code === 'EADDRINUSE') {
14
+ resolve(getFreePort(startPort + 1));
15
+ }
16
+ });
17
+ server.once('listening', () => {
18
+ server.close(() => {
19
+ resolve(startPort);
20
+ });
21
+ });
22
+ server.listen(startPort, '127.0.0.1');
23
+ });
24
+ }
25
+
26
+ function startBackend(port) {
9
27
  const serverPath = path.join(__dirname, 'server/index.js');
10
28
 
11
29
  // Fork the Express backend process
@@ -13,7 +31,7 @@ function startBackend() {
13
31
  env: {
14
32
  ...process.env,
15
33
  NODE_ENV: 'production',
16
- PORT: '3001'
34
+ PORT: port.toString()
17
35
  }
18
36
  });
19
37
 
@@ -26,7 +44,7 @@ function startBackend() {
26
44
  });
27
45
  }
28
46
 
29
- function createWindow() {
47
+ function createWindow(port) {
30
48
  mainWindow = new BrowserWindow({
31
49
  width: 1200,
32
50
  height: 800,
@@ -40,7 +58,7 @@ function createWindow() {
40
58
  const isDev = !app.isPackaged;
41
59
 
42
60
  const loadURL = () => {
43
- const url = isDev ? 'http://127.0.0.1:5173' : 'http://127.0.0.1:3001';
61
+ const url = isDev ? 'http://127.0.0.1:5173' : `http://127.0.0.1:${port}`;
44
62
  mainWindow.loadURL(url).catch((err) => {
45
63
  console.log(`Frontend port not ready yet, retrying in 200ms...`);
46
64
  setTimeout(loadURL, 200);
@@ -54,13 +72,16 @@ function createWindow() {
54
72
  });
55
73
  }
56
74
 
57
- app.whenReady().then(() => {
58
- startBackend();
59
- createWindow();
75
+ app.whenReady().then(async () => {
76
+ const isDev = !app.isPackaged;
77
+ const port = isDev ? 3001 : await getFreePort(3001);
78
+
79
+ startBackend(port);
80
+ createWindow(port);
60
81
 
61
82
  app.on('activate', () => {
62
83
  if (BrowserWindow.getAllWindows().length === 0) {
63
- createWindow();
84
+ createWindow(port);
64
85
  }
65
86
  });
66
87
  });
package/package.json CHANGED
@@ -1,12 +1,18 @@
1
1
  {
2
2
  "name": "@supasayan/ytm",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Root package to run both client and server",
5
5
  "main": "main.js",
6
6
  "productName": "YTM",
7
7
  "bin": {
8
8
  "ytm": "./bin/cli.js"
9
9
  },
10
+ "dependencies": {
11
+ "express": "^4.21.0",
12
+ "cors": "^2.8.5",
13
+ "ytmusic-api": "^5.0.0",
14
+ "ffmpeg-static": "^5.2.0"
15
+ },
10
16
  "scripts": {
11
17
  "start": "npx concurrently \"npm run start --prefix server\" \"npm run dev --prefix client\"",
12
18
  "dev": "npx concurrently \"npm run dev --prefix server\" \"npm run dev --prefix client\"",
@@ -0,0 +1,245 @@
1
+ {
2
+ "downloadsMap": [
3
+ [
4
+ "21212a82-1358-4d4f-8ca8-9e5a780e16fd",
5
+ {
6
+ "downloadId": "21212a82-1358-4d4f-8ca8-9e5a780e16fd",
7
+ "videoId": "PHLWb8RPL54",
8
+ "title": "Butterfly – Jab Harry Met Sejal | Anushka Sharma | Shah Rukh Khan | Pritam | Imtiaz Ali",
9
+ "artist": "Sony Music India",
10
+ "album": null,
11
+ "thumbnail": "https://i.ytimg.com/vi/PHLWb8RPL54/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mQBMb9omx4jxr92T-2jrxp3WT5jA",
12
+ "status": "completed",
13
+ "percent": "100%",
14
+ "speed": "552.00KiB/s",
15
+ "eta": "Unknown",
16
+ "filePath": "/Users/sayan/Desktop/songs/Butterfly – Jab Harry Met Sejal _ Anushka Sharma _ Shah Rukh Khan _ Pritam _ Imtiaz Ali.m4a"
17
+ }
18
+ ],
19
+ [
20
+ "7ee14b67-f496-4945-a8fa-16088880dcbd",
21
+ {
22
+ "downloadId": "7ee14b67-f496-4945-a8fa-16088880dcbd",
23
+ "videoId": "U5Gyw-nGf1I",
24
+ "title": "Radha – Jab Harry Met Sejal | Shah Rukh Khan | Anushka Sharma | Pritam | Imtiaz Ali| Latest Hit 2017",
25
+ "artist": "Sony Music India",
26
+ "album": null,
27
+ "thumbnail": "https://i.ytimg.com/vi/U5Gyw-nGf1I/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3nXOZEBpmGJlP32k0qTqZZ-Nxzkkg",
28
+ "status": "completed",
29
+ "percent": "100%",
30
+ "speed": "13.00MiB/s",
31
+ "eta": "Unknown",
32
+ "filePath": "/Users/sayan/Desktop/songs/Radha – Jab Harry Met Sejal _ Shah Rukh Khan _ Anushka Sharma _ Pritam _ Imtiaz Ali_ Latest Hit 2017.m4a"
33
+ }
34
+ ],
35
+ [
36
+ "3102707a-2578-4fb4-8b7d-c420eac184d8",
37
+ {
38
+ "downloadId": "3102707a-2578-4fb4-8b7d-c420eac184d8",
39
+ "videoId": "xORB1S9YvP8",
40
+ "title": "Safar (From \"Jab Harry Met Sejal\")",
41
+ "artist": "Arijit Singh",
42
+ "album": null,
43
+ "thumbnail": "https://i.ytimg.com/vi/xORB1S9YvP8/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mAutqTgPSFqTs32fwTL7xkz6rq6Q",
44
+ "status": "completed",
45
+ "percent": "100%",
46
+ "speed": "9.97MiB/s",
47
+ "eta": "Unknown",
48
+ "filePath": "/Users/sayan/Desktop/songs/Safar (From _Jab Harry Met Sejal_).m4a"
49
+ }
50
+ ],
51
+ [
52
+ "cf3661ce-aaf8-4630-b247-4be593652bd8",
53
+ {
54
+ "downloadId": "cf3661ce-aaf8-4630-b247-4be593652bd8",
55
+ "videoId": "v3WVAoaA0E0",
56
+ "title": "Beech Beech Mein | Dialogues | Jab Harry Met Sejal | Shah Rukh Khan, Anushka Sharma",
57
+ "artist": "Red Chillies Entertainment",
58
+ "album": null,
59
+ "thumbnail": "https://i.ytimg.com/vi/v3WVAoaA0E0/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3n9Sn8pFUc4YTma20vQHqbKsJtlyg",
60
+ "status": "completed",
61
+ "percent": "100%",
62
+ "speed": "4.08MiB/s",
63
+ "eta": "Unknown",
64
+ "filePath": "/Users/sayan/Desktop/songs/Beech Beech Mein _ Dialogues _ Jab Harry Met Sejal _ Shah Rukh Khan, Anushka Sharma.m4a"
65
+ }
66
+ ],
67
+ [
68
+ "597589bb-e918-469d-bd6c-256dd28f9c15",
69
+ {
70
+ "downloadId": "597589bb-e918-469d-bd6c-256dd28f9c15",
71
+ "videoId": "W5MZevEH5Ns",
72
+ "title": "Jab Harry Met Sejal Trailer | Shah Rukh Khan, Anushka Sharma",
73
+ "artist": "Red Chillies Entertainment",
74
+ "album": null,
75
+ "thumbnail": "https://i.ytimg.com/vi/W5MZevEH5Ns/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3kXsnoUyWXDqSZ98kbVm56wLdnqUw",
76
+ "status": "completed",
77
+ "percent": "100%",
78
+ "speed": "8.40MiB/s",
79
+ "eta": "Unknown",
80
+ "filePath": "/Users/sayan/Desktop/songs/Jab Harry Met Sejal Trailer _ Shah Rukh Khan, Anushka Sharma.m4a"
81
+ }
82
+ ],
83
+ [
84
+ "6cd2e5ed-d91d-46a6-8eb2-1e0488c50aa3",
85
+ {
86
+ "downloadId": "6cd2e5ed-d91d-46a6-8eb2-1e0488c50aa3",
87
+ "videoId": "wp1qNO_mPOg",
88
+ "title": "Beech Beech Mein - Full Video | Jab Harry Met Sejal | Shah Rukh Khan, Anushka| Pritam | Arijit Singh",
89
+ "artist": "Sony Music India",
90
+ "album": null,
91
+ "thumbnail": "https://i.ytimg.com/vi/wp1qNO_mPOg/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3l6qpsaz6OovcKQCdSsPptWew-jdg",
92
+ "status": "completed",
93
+ "percent": "100%",
94
+ "speed": "9.84MiB/s",
95
+ "eta": "Unknown",
96
+ "filePath": "/Users/sayan/Desktop/songs/Beech Beech Mein - Full Video _ Jab Harry Met Sejal _ Shah Rukh Khan, Anushka_ Pritam _ Arijit Singh.m4a"
97
+ }
98
+ ],
99
+ [
100
+ "8f7ce7a5-bbcb-4c01-970f-d301d1c29c87",
101
+ {
102
+ "downloadId": "8f7ce7a5-bbcb-4c01-970f-d301d1c29c87",
103
+ "videoId": "cs1e0fRyI18",
104
+ "title": "Hawayein",
105
+ "artist": "Arijit Singh",
106
+ "album": null,
107
+ "thumbnail": "https://i.ytimg.com/vi/cs1e0fRyI18/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mGSFf2RGl1XQ3ZNxJ7OBCAgr8RGw",
108
+ "status": "completed",
109
+ "percent": "100%",
110
+ "speed": "8.03MiB/s",
111
+ "eta": "Unknown",
112
+ "filePath": "/Users/sayan/Desktop/songs/Hawayein.m4a"
113
+ }
114
+ ],
115
+ [
116
+ "23937d9f-0b64-4bef-bd5d-40f99a0ab7c8",
117
+ {
118
+ "downloadId": "23937d9f-0b64-4bef-bd5d-40f99a0ab7c8",
119
+ "videoId": "Kx7B-XvmFtE",
120
+ "title": "Believer",
121
+ "artist": "Imagine Dragons",
122
+ "album": "Evolve",
123
+ "thumbnail": "https://yt3.googleusercontent.com/weYQWfEwWNPOuAm34geXN1LkSYPlsJay78NnQgHC3PKsyZcdvBHIsMtqoFh3rioA4XgMdHMQd3h6vH6mbA=w120-h120-l90-rj",
124
+ "status": "completed",
125
+ "percent": "100%",
126
+ "speed": "14.49MiB/s",
127
+ "eta": "Unknown",
128
+ "filePath": "/Users/sayan/Desktop/songs/Believer.m4a"
129
+ }
130
+ ],
131
+ [
132
+ "673215d7-046f-4eba-864b-e305158e6fe2",
133
+ {
134
+ "downloadId": "673215d7-046f-4eba-864b-e305158e6fe2",
135
+ "videoId": "PHLWb8RPL54",
136
+ "title": "Butterfly – Jab Harry Met Sejal | Anushka Sharma | Shah Rukh Khan | Pritam | Imtiaz Ali",
137
+ "artist": "Sony Music India",
138
+ "album": null,
139
+ "thumbnail": "https://i.ytimg.com/vi/PHLWb8RPL54/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mQBMb9omx4jxr92T-2jrxp3WT5jA",
140
+ "status": "error",
141
+ "percent": "0%",
142
+ "speed": "",
143
+ "eta": "",
144
+ "error": "unable to download video data: HTTP Error 403: Forbidden"
145
+ }
146
+ ],
147
+ [
148
+ "107467a7-13e4-4b7c-aa67-163a7e70462a",
149
+ {
150
+ "downloadId": "107467a7-13e4-4b7c-aa67-163a7e70462a",
151
+ "videoId": "U5Gyw-nGf1I",
152
+ "title": "Radha – Jab Harry Met Sejal | Shah Rukh Khan | Anushka Sharma | Pritam | Imtiaz Ali| Latest Hit 2017",
153
+ "artist": "Sony Music India",
154
+ "album": null,
155
+ "thumbnail": "https://i.ytimg.com/vi/U5Gyw-nGf1I/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3nXOZEBpmGJlP32k0qTqZZ-Nxzkkg",
156
+ "status": "completed",
157
+ "percent": "100%",
158
+ "speed": "14.50MiB/s",
159
+ "eta": "Unknown",
160
+ "filePath": "/Users/sayan/Desktop/songs/Radha – Jab Harry Met Sejal _ Shah Rukh Khan _ Anushka Sharma _ Pritam _ Imtiaz Ali_ Latest Hit 2017.m4a"
161
+ }
162
+ ],
163
+ [
164
+ "ca30fc86-e82a-429a-9c09-55e6a52ce4cb",
165
+ {
166
+ "downloadId": "ca30fc86-e82a-429a-9c09-55e6a52ce4cb",
167
+ "videoId": "xORB1S9YvP8",
168
+ "title": "Safar (From \"Jab Harry Met Sejal\")",
169
+ "artist": "Arijit Singh",
170
+ "album": null,
171
+ "thumbnail": "https://i.ytimg.com/vi/xORB1S9YvP8/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mAutqTgPSFqTs32fwTL7xkz6rq6Q",
172
+ "status": "completed",
173
+ "percent": "100%",
174
+ "speed": "18.02MiB/s",
175
+ "eta": "Unknown",
176
+ "filePath": "/Users/sayan/Desktop/songs/Safar (From _Jab Harry Met Sejal_).m4a"
177
+ }
178
+ ],
179
+ [
180
+ "26b4940a-833c-441d-8283-bd149ed8d216",
181
+ {
182
+ "downloadId": "26b4940a-833c-441d-8283-bd149ed8d216",
183
+ "videoId": "v3WVAoaA0E0",
184
+ "title": "Beech Beech Mein | Dialogues | Jab Harry Met Sejal | Shah Rukh Khan, Anushka Sharma",
185
+ "artist": "Red Chillies Entertainment",
186
+ "album": null,
187
+ "thumbnail": "https://i.ytimg.com/vi/v3WVAoaA0E0/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3n9Sn8pFUc4YTma20vQHqbKsJtlyg",
188
+ "status": "completed",
189
+ "percent": "100%",
190
+ "speed": "11.69MiB/s",
191
+ "eta": "Unknown",
192
+ "filePath": "/Users/sayan/Desktop/songs/Beech Beech Mein _ Dialogues _ Jab Harry Met Sejal _ Shah Rukh Khan, Anushka Sharma.m4a"
193
+ }
194
+ ],
195
+ [
196
+ "7a6fb894-1ed1-4526-be19-fdfb61a0f90d",
197
+ {
198
+ "downloadId": "7a6fb894-1ed1-4526-be19-fdfb61a0f90d",
199
+ "videoId": "W5MZevEH5Ns",
200
+ "title": "Jab Harry Met Sejal Trailer | Shah Rukh Khan, Anushka Sharma",
201
+ "artist": "Red Chillies Entertainment",
202
+ "album": null,
203
+ "thumbnail": "https://i.ytimg.com/vi/W5MZevEH5Ns/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3kXsnoUyWXDqSZ98kbVm56wLdnqUw",
204
+ "status": "completed",
205
+ "percent": "100%",
206
+ "speed": "14.88MiB/s",
207
+ "eta": "Unknown",
208
+ "filePath": "/Users/sayan/Desktop/songs/Jab Harry Met Sejal Trailer _ Shah Rukh Khan, Anushka Sharma.m4a"
209
+ }
210
+ ],
211
+ [
212
+ "9ee8c69e-31f5-40dd-9a7c-b99261b38707",
213
+ {
214
+ "downloadId": "9ee8c69e-31f5-40dd-9a7c-b99261b38707",
215
+ "videoId": "wp1qNO_mPOg",
216
+ "title": "Beech Beech Mein - Full Video | Jab Harry Met Sejal | Shah Rukh Khan, Anushka| Pritam | Arijit Singh",
217
+ "artist": "Sony Music India",
218
+ "album": null,
219
+ "thumbnail": "https://i.ytimg.com/vi/wp1qNO_mPOg/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3l6qpsaz6OovcKQCdSsPptWew-jdg",
220
+ "status": "completed",
221
+ "percent": "100%",
222
+ "speed": "11.46MiB/s",
223
+ "eta": "Unknown",
224
+ "filePath": "/Users/sayan/Desktop/songs/Beech Beech Mein - Full Video _ Jab Harry Met Sejal _ Shah Rukh Khan, Anushka_ Pritam _ Arijit Singh.m4a"
225
+ }
226
+ ],
227
+ [
228
+ "1b8dee57-f119-43ff-82fc-d2aefc65e96b",
229
+ {
230
+ "downloadId": "1b8dee57-f119-43ff-82fc-d2aefc65e96b",
231
+ "videoId": "cs1e0fRyI18",
232
+ "title": "Hawayein",
233
+ "artist": "Arijit Singh",
234
+ "album": null,
235
+ "thumbnail": "https://i.ytimg.com/vi/cs1e0fRyI18/sddefault.jpg?sqp=-oaymwEWCJADEOEBIAQqCghqEJQEGHgg6AJIWg&rs=AMzJL3mGSFf2RGl1XQ3ZNxJ7OBCAgr8RGw",
236
+ "status": "completed",
237
+ "percent": "100%",
238
+ "speed": "11.66MiB/s",
239
+ "eta": "Unknown",
240
+ "filePath": "/Users/sayan/Desktop/songs/Hawayein.m4a"
241
+ }
242
+ ]
243
+ ],
244
+ "downloadQueue": []
245
+ }