mirror of
https://github.com/Tzahi12345/YoutubeDL-Material.git
synced 2026-04-08 12:11:28 +03:00
Fixed bug where audio files that had a stale webm extension in the metadata file path would fail to register
This commit is contained in:
@@ -1188,7 +1188,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// get filepath with no extension
|
// get filepath with no extension
|
||||||
const filepath_no_extension = removeFileExtension(output_json['_filename']);
|
const filepath_no_extension = utils.removeFileExtension(output_json['_filename']);
|
||||||
|
|
||||||
var full_file_path = filepath_no_extension + ext;
|
var full_file_path = filepath_no_extension + ext;
|
||||||
var file_name = filepath_no_extension.substring(fileFolderPath.length, filepath_no_extension.length);
|
var file_name = filepath_no_extension.substring(fileFolderPath.length, filepath_no_extension.length);
|
||||||
@@ -1310,7 +1310,7 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
|||||||
video.on('info', function(info) {
|
video.on('info', function(info) {
|
||||||
video_info = info;
|
video_info = info;
|
||||||
file_size = video_info.size;
|
file_size = video_info.size;
|
||||||
const json_path = removeFileExtension(video_info._filename) + '.info.json';
|
const json_path = utils.removeFileExtension(video_info._filename) + '.info.json';
|
||||||
fs.ensureFileSync(json_path);
|
fs.ensureFileSync(json_path);
|
||||||
fs.writeJSONSync(json_path, video_info);
|
fs.writeJSONSync(json_path, video_info);
|
||||||
video.pipe(fs.createWriteStream(video_info._filename, { flags: 'w' }))
|
video.pipe(fs.createWriteStream(video_info._filename, { flags: 'w' }))
|
||||||
@@ -1336,14 +1336,14 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
|||||||
let difference = (new_date - date)/1000;
|
let difference = (new_date - date)/1000;
|
||||||
logger.debug(`Video download delay: ${difference} seconds.`);
|
logger.debug(`Video download delay: ${difference} seconds.`);
|
||||||
download['timestamp_end'] = Date.now();
|
download['timestamp_end'] = Date.now();
|
||||||
download['fileNames'] = [removeFileExtension(video_info._filename) + ext];
|
download['fileNames'] = [utils.removeFileExtension(video_info._filename) + ext];
|
||||||
download['complete'] = true;
|
download['complete'] = true;
|
||||||
updateDownloads();
|
updateDownloads();
|
||||||
|
|
||||||
// audio-only cleanup
|
// audio-only cleanup
|
||||||
if (is_audio) {
|
if (is_audio) {
|
||||||
// filename fix
|
// filename fix
|
||||||
video_info['_filename'] = removeFileExtension(video_info['_filename']) + '.mp3';
|
video_info['_filename'] = utils.removeFileExtension(video_info['_filename']) + '.mp3';
|
||||||
|
|
||||||
// ID3 tagging
|
// ID3 tagging
|
||||||
let tags = {
|
let tags = {
|
||||||
@@ -1353,8 +1353,8 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
|||||||
let success = NodeID3.write(tags, video_info._filename);
|
let success = NodeID3.write(tags, video_info._filename);
|
||||||
if (!success) logger.error('Failed to apply ID3 tag to audio file ' + video_info._filename);
|
if (!success) logger.error('Failed to apply ID3 tag to audio file ' + video_info._filename);
|
||||||
|
|
||||||
const possible_webm_path = removeFileExtension(video_info['_filename']) + '.webm';
|
const possible_webm_path = utils.removeFileExtension(video_info['_filename']) + '.webm';
|
||||||
const possible_mp4_path = removeFileExtension(video_info['_filename']) + '.mp4';
|
const possible_mp4_path = utils.removeFileExtension(video_info['_filename']) + '.mp4';
|
||||||
// check if audio file is webm
|
// check if audio file is webm
|
||||||
if (fs.existsSync(possible_webm_path)) await convertFileToMp3(possible_webm_path, video_info['_filename']);
|
if (fs.existsSync(possible_webm_path)) await convertFileToMp3(possible_webm_path, video_info['_filename']);
|
||||||
else if (fs.existsSync(possible_mp4_path)) await convertFileToMp3(possible_mp4_path, video_info['_filename']);
|
else if (fs.existsSync(possible_mp4_path)) await convertFileToMp3(possible_mp4_path, video_info['_filename']);
|
||||||
@@ -1371,7 +1371,7 @@ async function downloadFileByURL_normal(url, type, options, sessionID = null) {
|
|||||||
fs.appendFileSync(archive_path, diff);
|
fs.appendFileSync(archive_path, diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
videopathEncoded = encodeURIComponent(removeFileExtension(base_file_name));
|
videopathEncoded = encodeURIComponent(utils.removeFileExtension(base_file_name));
|
||||||
|
|
||||||
resolve({
|
resolve({
|
||||||
[is_audio ? 'audiopathEncoded' : 'videopathEncoded']: videopathEncoded,
|
[is_audio ? 'audiopathEncoded' : 'videopathEncoded']: videopathEncoded,
|
||||||
@@ -1778,12 +1778,6 @@ async function checkExistsWithTimeout(filePath, timeout) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function removeFileExtension(filename) {
|
|
||||||
const filename_parts = filename.split('.');
|
|
||||||
filename_parts.splice(filename_parts.length - 1)
|
|
||||||
return filename_parts.join('.');
|
|
||||||
}
|
|
||||||
|
|
||||||
app.use(function(req, res, next) {
|
app.use(function(req, res, next) {
|
||||||
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
|
||||||
res.header("Access-Control-Allow-Origin", getOrigin());
|
res.header("Access-Control-Allow-Origin", getOrigin());
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ function initialize(input_db, input_users_db, input_logger) {
|
|||||||
|
|
||||||
function registerFileDB(file_path, type, multiUserMode = null, sub = null, customPath = null, category = null) {
|
function registerFileDB(file_path, type, multiUserMode = null, sub = null, customPath = null, category = null) {
|
||||||
let db_path = null;
|
let db_path = null;
|
||||||
const file_id = file_path.substring(0, file_path.length-4);
|
const file_id = utils.removeFileExtension(file_path);
|
||||||
const file_object = generateFileObject(file_id, type, customPath || multiUserMode && multiUserMode.file_path, sub);
|
const file_object = generateFileObject(file_id, type, customPath || multiUserMode && multiUserMode.file_path, sub);
|
||||||
if (!file_object) {
|
if (!file_object) {
|
||||||
logger.error(`Could not find associated JSON file for ${type} file ${file_id}`);
|
logger.error(`Could not find associated JSON file for ${type} file ${file_id}`);
|
||||||
|
|||||||
@@ -181,6 +181,12 @@ async function recFindByExt(base,ext,files,result)
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeFileExtension(filename) {
|
||||||
|
const filename_parts = filename.split('.');
|
||||||
|
filename_parts.splice(filename_parts.length - 1);
|
||||||
|
return filename_parts.join('.');
|
||||||
|
}
|
||||||
|
|
||||||
// objects
|
// objects
|
||||||
|
|
||||||
function File(id, title, thumbnailURL, isAudio, duration, url, uploader, size, path, upload_date, description, view_count, height, abr) {
|
function File(id, title, thumbnailURL, isAudio, duration, url, uploader, size, path, upload_date, description, view_count, height, abr) {
|
||||||
@@ -210,5 +216,6 @@ module.exports = {
|
|||||||
deleteJSONFile: deleteJSONFile,
|
deleteJSONFile: deleteJSONFile,
|
||||||
getDownloadedFilesByType: getDownloadedFilesByType,
|
getDownloadedFilesByType: getDownloadedFilesByType,
|
||||||
recFindByExt: recFindByExt,
|
recFindByExt: recFindByExt,
|
||||||
|
removeFileExtension: removeFileExtension,
|
||||||
File: File
|
File: File
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user