mirror of
https://github.com/musix-org/musix-oss
synced 2025-07-07 01:20:48 +00:00
fix
This commit is contained in:
23
node_modules/simple-youtube-api/src/util/Constants.js
generated
vendored
Normal file
23
node_modules/simple-youtube-api/src/util/Constants.js
generated
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
exports.PARTS = {
|
||||
Search: 'snippet',
|
||||
Videos: 'snippet,contentDetails',
|
||||
Playlists: 'snippet',
|
||||
PlaylistItems: 'snippet,status',
|
||||
Channels: 'snippet'
|
||||
};
|
||||
|
||||
exports.KINDS = {
|
||||
Video: 'youtube#video',
|
||||
PlaylistItem: 'youtube#playlistItem',
|
||||
Playlist: 'youtube#playlist',
|
||||
SearchResult: 'youtube#searchResult',
|
||||
Channel: 'youtube#channel'
|
||||
};
|
||||
|
||||
exports.ENDPOINTS = {
|
||||
PlaylistItems: 'playlistItems',
|
||||
Channels: 'channels',
|
||||
Videos: 'videos',
|
||||
Playlists: 'playlists',
|
||||
Search: 'search'
|
||||
};
|
36
node_modules/simple-youtube-api/src/util/index.js
generated
vendored
Normal file
36
node_modules/simple-youtube-api/src/util/index.js
generated
vendored
Normal file
@ -0,0 +1,36 @@
|
||||
const { parse } = require('url');
|
||||
|
||||
/**
|
||||
* Parse a string as a potential YouTube resource URL.
|
||||
* @param {string} url
|
||||
* @returns {{video: ?string, channel: ?string, playlist: ?string}}
|
||||
*/
|
||||
exports.parseURL = (url) => {
|
||||
const parsed = parse(url, true);
|
||||
switch (parsed.hostname) {
|
||||
case 'www.youtube.com':
|
||||
case 'youtube.com':
|
||||
case 'm.youtube.com': {
|
||||
const idRegex = /^[a-zA-Z0-9-_]+$/;
|
||||
if (parsed.pathname === '/watch') {
|
||||
if (!idRegex.test(parsed.query.v)) return {};
|
||||
const response = { video: parsed.query.v };
|
||||
if (parsed.query.list) response.playlist = parsed.query.list;
|
||||
return response;
|
||||
} else if (parsed.pathname === '/playlist') {
|
||||
if(!idRegex.test(parsed.query.list)) return {};
|
||||
return { playlist: parsed.query.list };
|
||||
} else if (parsed.pathname.startsWith('/channel/')) {
|
||||
const id = parsed.pathname.replace('/channel/', '');
|
||||
if (!idRegex.test(id)) return {};
|
||||
return { channel: id };
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
case 'youtu.be':
|
||||
return { video: /^\/[a-zA-Z0-9-_]+$/.test(parsed.pathname) ? parsed.pathname.slice(1) : null };
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user