mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
feat: centralize isPlaylistUrl function as a helper that could be upgraded in the future
This commit is contained in:
@@ -2,6 +2,7 @@ const { fetchInfo } = require("../services/info.services");
|
|||||||
const { parseVideo, parsePlaylist } = require("../helpers/parseInfo.helpers");
|
const { parseVideo, parsePlaylist } = require("../helpers/parseInfo.helpers");
|
||||||
const { logger } = require("../logger");
|
const { logger } = require("../logger");
|
||||||
const { isValidUrl } = require("../helpers/validation.helpers");
|
const { isValidUrl } = require("../helpers/validation.helpers");
|
||||||
|
const {isUrlPlaylist} = require("../helpers/playlist.helpers");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles metadata retrieval for a video or playlist.
|
* Handles metadata retrieval for a video or playlist.
|
||||||
@@ -36,7 +37,7 @@ async function infoController(req, res) {
|
|||||||
logger.info(`Info request received. ENCODED: ${encodedUrl}`);
|
logger.info(`Info request received. ENCODED: ${encodedUrl}`);
|
||||||
|
|
||||||
// Lightweight heuristic to detect playlist URLs. It works for Youtube.
|
// Lightweight heuristic to detect playlist URLs. It works for Youtube.
|
||||||
const isPlaylistUrl = url.includes("&list") || url.includes("?list");
|
const isPlaylistUrl = isUrlPlaylist(url);
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
isPlaylistUrl
|
isPlaylistUrl
|
||||||
|
|||||||
12
server/helpers/playlist.helpers.js
Normal file
12
server/helpers/playlist.helpers.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* Determines whether a URL targets a playlist.
|
||||||
|
*
|
||||||
|
* The detection is based on the presence of the YouTube
|
||||||
|
* playlist query parameter (`list`).
|
||||||
|
*
|
||||||
|
* @param {string} url - URL to inspect.
|
||||||
|
* @returns {boolean} True if the URL appears to be a playlist.
|
||||||
|
*/
|
||||||
|
export function isUrlPlaylist(url) {
|
||||||
|
return url.includes("?list=") || url.includes("&list=") || url.includes("@");
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ const notify = require("../helpers/notify.helpers");
|
|||||||
const path = require("path");
|
const path = require("path");
|
||||||
const { isSafePath } = require("../helpers/validation.helpers");
|
const { isSafePath } = require("../helpers/validation.helpers");
|
||||||
const {reloadFeatures} = require("../../config");
|
const {reloadFeatures} = require("../../config");
|
||||||
|
const {isUrlPlaylist} = require("../helpers/playlist.helpers");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference to the currently running yt-dlp process.
|
* Reference to the currently running yt-dlp process.
|
||||||
@@ -18,19 +19,6 @@ const {reloadFeatures} = require("../../config");
|
|||||||
*/
|
*/
|
||||||
let currentDownloadProcess = null;
|
let currentDownloadProcess = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether a URL targets a playlist.
|
|
||||||
*
|
|
||||||
* The detection is based on the presence of the YouTube
|
|
||||||
* playlist query parameter (`list`).
|
|
||||||
*
|
|
||||||
* @param {string} url - URL to inspect.
|
|
||||||
* @returns {boolean} True if the URL appears to be a playlist.
|
|
||||||
*/
|
|
||||||
function isPlaylistUrl(url) {
|
|
||||||
return url.includes("?list=") || url.includes("&list=");
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a dedicated download folder for a playlist.
|
* Creates a dedicated download folder for a playlist.
|
||||||
*
|
*
|
||||||
@@ -160,7 +148,7 @@ function fetchDownload(options, progressListeners, speedListeners, stageListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Détecte si c'est une playlist et crée un dossier approprié
|
// Détecte si c'est une playlist et crée un dossier approprié
|
||||||
const isPlaylist = options.playlistTitle || isPlaylistUrl(options.url);
|
const isPlaylist = options.playlistTitle || isUrlPlaylist(options.url);
|
||||||
|
|
||||||
if (isPlaylist && userConfig.createPlaylistFolders) {
|
if (isPlaylist && userConfig.createPlaylistFolders) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user