mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
up2k-hook-ytid: upload into subdirs by id
This commit is contained in:
parent
7000123a8b
commit
50a477ee47
|
@ -51,6 +51,8 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
cname = name, // will clobber
|
cname = name, // will clobber
|
||||||
sz = fobj.size,
|
sz = fobj.size,
|
||||||
ids = [],
|
ids = [],
|
||||||
|
fn_ids = [],
|
||||||
|
md_ids = [],
|
||||||
id_ok = false,
|
id_ok = false,
|
||||||
m;
|
m;
|
||||||
|
|
||||||
|
@ -71,7 +73,7 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
|
|
||||||
cname = cname.replace(m[1], '');
|
cname = cname.replace(m[1], '');
|
||||||
yt_ids.add(m[1]);
|
yt_ids.add(m[1]);
|
||||||
ids.push(m[1]);
|
fn_ids.unshift(m[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// look for IDs in video metadata,
|
// look for IDs in video metadata,
|
||||||
|
@ -110,10 +112,13 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
|
|
||||||
console.log(`found ${m} @${bofs}, ${name} `);
|
console.log(`found ${m} @${bofs}, ${name} `);
|
||||||
yt_ids.add(m);
|
yt_ids.add(m);
|
||||||
if (!has(ids, m)) {
|
if (!has(fn_ids, m) && !has(md_ids, m)) {
|
||||||
ids.push(m);
|
md_ids.push(m);
|
||||||
md_only.push(`${m} ${name}`);
|
md_only.push(`${m} ${name}`);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
// id appears several times; make it preferred
|
||||||
|
md_ids.unshift(m);
|
||||||
|
|
||||||
// bail after next iteration
|
// bail after next iteration
|
||||||
chunk = nchunks - 1;
|
chunk = nchunks - 1;
|
||||||
|
@ -130,6 +135,13 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (var yi of md_ids)
|
||||||
|
ids.push(yi);
|
||||||
|
|
||||||
|
for (var yi of fn_ids)
|
||||||
|
if (!has(ids, yi))
|
||||||
|
ids.push(yi);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (md_only.length)
|
if (md_only.length)
|
||||||
|
@ -164,6 +176,7 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
|
|
||||||
function process_id_list(txt) {
|
function process_id_list(txt) {
|
||||||
var wanted_ids = new Set(txt.trim().split('\n')),
|
var wanted_ids = new Set(txt.trim().split('\n')),
|
||||||
|
name_id = {},
|
||||||
wanted_names = new Set(), // basenames with a wanted ID
|
wanted_names = new Set(), // basenames with a wanted ID
|
||||||
wanted_files = new Set(); // filedrops
|
wanted_files = new Set(); // filedrops
|
||||||
|
|
||||||
|
@ -174,8 +187,11 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
wanted_files.add(good_files[a]);
|
wanted_files.add(good_files[a]);
|
||||||
|
|
||||||
var m = /(.*)\.(mp4|webm|mkv|flv|opus|ogg|mp3|m4a|aac)$/i.exec(name);
|
var m = /(.*)\.(mp4|webm|mkv|flv|opus|ogg|mp3|m4a|aac)$/i.exec(name);
|
||||||
if (m)
|
if (!m)
|
||||||
wanted_names.add(m[1]);
|
continue;
|
||||||
|
|
||||||
|
wanted_names.add(m[1]);
|
||||||
|
name_id[m[1]] = file_ids[a][b];
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -189,6 +205,9 @@ async function a_up2k_namefilter(good_files, nil_files, bad_files, hooks) {
|
||||||
name = name.replace(/\.[^\.]+$/, '');
|
name = name.replace(/\.[^\.]+$/, '');
|
||||||
if (wanted_names.has(name)) {
|
if (wanted_names.has(name)) {
|
||||||
wanted_files.add(good_files[a]);
|
wanted_files.add(good_files[a]);
|
||||||
|
|
||||||
|
var subdir = `${name_id[name]}-${Date.now()}-${a}`;
|
||||||
|
good_files[a][1] = subdir + '/' + good_files[a][1].split(/\//g).pop();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue