added match files button
This commit is contained in:
parent
2a59ecf7b5
commit
f87ba5688e
@ -9,15 +9,18 @@ function add_file_tree_clickhanlder(side) {
|
||||
|
||||
var type = elem.classList.contains("folder") ? "folder" : "file";
|
||||
if(type=="file") {
|
||||
remove_info(side)
|
||||
let path = cleanup_tree(elem);
|
||||
path.unshift(elem.textContent);
|
||||
let root_dir = document.getElementById(side + "_dir").value;
|
||||
path.push(root_dir);
|
||||
if( elem.textContent.endsWith('.mkv')) {
|
||||
fetchmkvdata(path,side);
|
||||
localStorage.setItem(side, JSON.stringify( [path, "file"]))
|
||||
} else if ( elem.textContent.endsWith('.mp3') || elem.textContent.endsWith('.mp4')) {
|
||||
create_convert_button(path, side);
|
||||
}
|
||||
handle_merge_button_changes()
|
||||
|
||||
}
|
||||
if (type == "folder") {
|
||||
@ -28,12 +31,14 @@ function add_file_tree_clickhanlder(side) {
|
||||
let path = get_path_var(elem);
|
||||
let root_dir = document.getElementById(side + "_dir").value;
|
||||
path.push(root_dir);
|
||||
|
||||
localStorage.setItem(side, JSON.stringify( [path, "folder"]))
|
||||
fetchTable(elem.parentElement,path,side );
|
||||
fetchmkvdata(path.reverse(),side);
|
||||
|
||||
} else {
|
||||
localStorage.setItem(side, null)
|
||||
remove_info(side)
|
||||
cleanup_tree(elem);
|
||||
handle_merge_button_changes()
|
||||
}
|
||||
|
||||
elem.dataset.isexpanded = !isexpanded;
|
||||
|
||||
@ -72,9 +72,12 @@
|
||||
<div id="convert-button-right"></div>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</tr></tr><td>
|
||||
<div id="merge-button-div"></div>
|
||||
</td></tr> </table>
|
||||
<script src="file_structure.js" defer></script>
|
||||
<script src="table_builder.js" defer></script>
|
||||
<script src="merge_button.js" defer></script>
|
||||
<script src="mkvdatefetcher.js"></script>
|
||||
<script src="media_info_presenter.js"></script>
|
||||
<script src="filter.js"></script>
|
||||
|
||||
@ -83,3 +83,10 @@ function create_media_info(data) {
|
||||
info_obj.innerHTML = "";
|
||||
info_obj.appendChild(info_ct);
|
||||
}
|
||||
|
||||
function remove_info(side) {
|
||||
let info_div = document.getElementById("info-" + side);
|
||||
if ( info_div) {
|
||||
info_div.innerHTML = ""
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,2 +1,46 @@
|
||||
function() {
|
||||
function handle_merge_button_changes() {
|
||||
let btn_div = document.getElementById("merge-button-div");
|
||||
btn_div.innerHTML = ""
|
||||
if (localStorage.getItem("left") == "null" || localStorage.getItem("right") == "null") {
|
||||
return;
|
||||
}
|
||||
let left_values = JSON.parse(localStorage.getItem("left"));
|
||||
let right_values = JSON.parse(localStorage.getItem("right"));
|
||||
if (left_values[1] != "folder" || right_values[1] != "folder" ) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
let btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.classList.add("btn", "btn-primary", "merge-btn");
|
||||
btn.textContent = "files matchen";
|
||||
btn.onclick = function () {
|
||||
let endpoint = "dir_matcher.py";
|
||||
|
||||
let url = '/script/' + endpoint+ '?'
|
||||
+ left_values[0]
|
||||
.map((par) => 'param1=' + encodeURIComponent(par))
|
||||
.join('&')+'&' + right_values[0]
|
||||
.map((par) => 'param2=' + encodeURIComponent(par))
|
||||
.join('&');
|
||||
|
||||
let btn_div = document.getElementById("merge-button-div");
|
||||
btn_div.innerHTML ="";
|
||||
localStorage.getItem("left", null)
|
||||
localStorage.getItem("right", null)
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if(Object.keys( data).length === 0) {
|
||||
alert("something went wrong");
|
||||
} else {
|
||||
alert("TODOD");
|
||||
}
|
||||
|
||||
})
|
||||
.catch(error => console.error('Error fetching table data:', error));
|
||||
};
|
||||
btn_div.appendChild(btn);
|
||||
}
|
||||
|
||||
53
script/dir_matcher.py
Normal file → Executable file
53
script/dir_matcher.py
Normal file → Executable file
@ -6,28 +6,30 @@ import cgi
|
||||
import sys
|
||||
import re
|
||||
|
||||
base_dir="/data"
|
||||
form = cgi.FieldStorage()
|
||||
param = form.getvalue('path', [])
|
||||
param1 = form.getvalue('param1', [])
|
||||
param2 = form.getvalue('param2', [])
|
||||
print(param1, file=sys.stderr);
|
||||
print(param2, file=sys.stderr);
|
||||
|
||||
def match_files(dir1, dir2, ep_prefix):
|
||||
filedict={}
|
||||
ep_prefix_no_ep = ep_prefix[:-5] # remove (\d+) at the end
|
||||
ep_prefix_incl_ep_match = get_full_episode_regex(ep_prefix)
|
||||
ep_prefix_no_ep = ep_prefix # remove (\d+) at the end
|
||||
for file1 in os.listdir(dir1):
|
||||
file1_match = re.search(ep_prefix, file1)
|
||||
file1_match = re.search(ep_prefix_incl_ep_match, file1)
|
||||
if not file1.endswith(".mkv"):
|
||||
continue
|
||||
|
||||
# separate ifs - no-mkv files are not surprising, but the episodes should match
|
||||
if not file1_match.search():
|
||||
if not file1_match:
|
||||
print("Error could not match {} - regex did not fit.".format(file1), file=sys.stderr)
|
||||
continue
|
||||
|
||||
for file2 in os.listdir(dir2):
|
||||
if not file2.endswith(".mkv"):
|
||||
continue
|
||||
file2_match = re.search(ep_prefix_no_ep, file1_match.group(1))
|
||||
file2_match = re.search(ep_prefix_no_ep+"E"+ file1_match.group(1), file2)
|
||||
if file2_match:
|
||||
filedict[file1] = file2
|
||||
break
|
||||
@ -36,29 +38,34 @@ def match_files(dir1, dir2, ep_prefix):
|
||||
|
||||
|
||||
def check_result(dir1, dir2, fielddict):
|
||||
unmatched_1 = []
|
||||
unmatched_2 = []
|
||||
matched1= {}
|
||||
matched2={}
|
||||
unmatch1=[]
|
||||
unmatch2=[]
|
||||
for (a,b) in fielddict.items():
|
||||
matched1[a]=1
|
||||
matched2[b]=1
|
||||
|
||||
for file1 in os.listdir(dir1):
|
||||
if not file1.endswith(".mkv"):
|
||||
continue
|
||||
|
||||
if file1 not in fielddict.keys():
|
||||
|
||||
if matched1.get(file1) is None:
|
||||
print("Error: {} from {} wasnt matches.".format(file1, dir1), file=sys.stderr)
|
||||
unmatched_1.push(file1)
|
||||
unmatch1.append(file1)
|
||||
|
||||
for file2 in os.listdir(dir2):
|
||||
if not file2.endswith(".mkv"):
|
||||
continue
|
||||
|
||||
if file2 not in fielddict.keys():
|
||||
if matched2.get(file2) is None:
|
||||
print("Error: {} from {} wasnt matches.".format(file2, dir2), file=sys.stderr)
|
||||
unmatched_2.push(file2)
|
||||
unmatch2.append(file2)
|
||||
|
||||
if len(unmatched_1) > 0:
|
||||
filedict["unmatched1"] =unmatched_1
|
||||
if len(unmatched_2) > 0:
|
||||
filedict["unmatched1"] =unmatched_2
|
||||
if len(unmatch1) > 0:
|
||||
filedict["unmatched1"] =unmatch1
|
||||
if len(unmatch2) > 0:
|
||||
filedict["unmatched2"] =unmatch2
|
||||
|
||||
|
||||
|
||||
@ -71,11 +78,11 @@ def get_path_from_array(path_array):
|
||||
|
||||
if isinstance(path_array, str):
|
||||
path_array = [path_array]
|
||||
|
||||
full_path= base_dir
|
||||
for el in path_array:
|
||||
path = os.path.join(path, el)
|
||||
full_path = os.path.join(full_path, el)
|
||||
|
||||
return path
|
||||
return full_path
|
||||
|
||||
|
||||
def get_season_no(direc1, direc2):
|
||||
@ -110,17 +117,17 @@ def get_season_prefix(season):
|
||||
return "(?i)S" + season
|
||||
|
||||
def get_full_episode_regex(season_prefix):
|
||||
|
||||
return season_prefix + "E(\d+)"
|
||||
|
||||
paths = [ get_path_from_array(param1), get_path_from_array(param2)]
|
||||
|
||||
for p in paths:
|
||||
if !os.path.isdir(p):
|
||||
if not os.path.isdir(p):
|
||||
print("Error, {} is no dir or does not exist. Aborting".format(p), file =sys.stderr)
|
||||
ret([]);
|
||||
|
||||
season = get_season_prefix(get_season_no(param1[-1], param2[-1]))
|
||||
|
||||
if season is None:
|
||||
print("Error couldnt determine Season aborting", file=sys.stderr)
|
||||
ret([])
|
||||
@ -128,6 +135,8 @@ if season is None:
|
||||
|
||||
|
||||
filedict = match_files(paths[0], paths[1], season)
|
||||
|
||||
print(json.dumps(filedict, indent=4), file=sys.stderr)
|
||||
check_result(paths[0], paths[1], filedict)
|
||||
|
||||
ret(filedict)
|
||||
|
||||
@ -15,6 +15,7 @@ function fetchTable(folder_container, path, side) {
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
localStorage.setItem(side,null)
|
||||
data.forEach(el => {
|
||||
if (el.isdir) { let gui_el = create_folder(el["name"]);
|
||||
gui_el.classList.add(side+"-align");
|
||||
@ -23,12 +24,16 @@ function fetchTable(folder_container, path, side) {
|
||||
}
|
||||
folder_container.appendChild(gui_el)
|
||||
} else {
|
||||
if ( el["name"].endsWith(".mkv") ) {
|
||||
localStorage.setItem(side, JSON.stringify( [path, "folder"]))
|
||||
}
|
||||
let gui_el = create_file(el["name"]);
|
||||
gui_el.classList.add(side+"-align");
|
||||
folder_container.appendChild(gui_el)
|
||||
}
|
||||
});
|
||||
|
||||
handle_merge_button_changes()
|
||||
})
|
||||
.catch(error => console.error('Error fetching table data:', error));
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user