Added modifications

This commit is contained in:
2025-12-06 20:47:35 -05:00
parent a577551c05
commit 4f4e5276a6
7 changed files with 272 additions and 137 deletions
+72
View File
@@ -728,6 +728,7 @@ def qb_torrents():
"dlspeed": torrent.dlspeed, "dlspeed": torrent.dlspeed,
"upspeed": torrent.upspeed, "upspeed": torrent.upspeed,
"eta": torrent.eta, "eta": torrent.eta,
"save_path": torrent.save_path
}) })
return jsonify(torrents) return jsonify(torrents)
except Exception as e: except Exception as e:
@@ -753,6 +754,10 @@ def qb_action():
client.torrents_resume(torrent_hashes=hashes) client.torrents_resume(torrent_hashes=hashes)
elif action == 'delete': elif action == 'delete':
client.torrents_delete(delete_files=True, torrent_hashes=hashes) client.torrents_delete(delete_files=True, torrent_hashes=hashes)
elif action == 'force_resume':
client.torrents_force_resume(torrent_hashes=hashes)
elif action == 'recheck':
client.torrents_recheck(torrent_hashes=hashes)
else: else:
return jsonify({"error": "Invalid action."}), 400 return jsonify({"error": "Invalid action."}), 400
@@ -760,5 +765,72 @@ def qb_action():
except Exception as e: except Exception as e:
return jsonify({"error": str(e)}), 500 return jsonify({"error": str(e)}), 500
@app.route('/api/create_folder', methods=['POST'])
def create_folder():
data = request.get_json()
path = data.get('path')
folder_name = data.get('folder_name')
if not path or not folder_name:
return jsonify({"error": "Path and folder name are required"}), 400
try:
creds = get_smb_credentials(path)
# Security check: Ensure destination is within the main VIDEO_PATH
common_path = os.path.commonpath([os.path.normpath(VIDEO_PATH), os.path.normpath(path)])
if common_path != os.path.normpath(VIDEO_PATH):
raise ValueError("Creation path is outside the allowed base directory.")
new_folder_path = os.path.join(path, folder_name)
smbclient.makedirs(new_folder_path, exist_ok=False, **creds)
return jsonify({"success": True})
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/api/move_file', methods=['POST'])
def move_file():
data = request.get_json()
source_path = data.get('source_path')
dest_path = data.get('dest_path')
if not source_path or not dest_path:
return jsonify({"error": "Source and destination paths are required"}), 400
try:
creds = get_smb_credentials(source_path)
# Ensure the destination directory exists
if not smbclient.exists(dest_path, **creds):
smbclient.makedirs(dest_path, exist_ok=True, **creds)
# Construct the full destination path including the filename
filename = os.path.basename(source_path)
full_dest_path = os.path.join(dest_path, filename)
smbclient.rename(source_path, full_dest_path, **creds)
return jsonify({"success": True})
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/api/qb_set_location', methods=['POST'])
def qb_set_location():
try:
client = get_qb_client()
if not client:
return jsonify({"error": "qBittorrent not configured."}), 400
data = request.get_json()
hashes = data.get('hashes')
location = data.get('location')
if not hashes or not location:
return jsonify({"error": "Missing hashes or location."}), 400
client.torrents_set_location(torrent_hashes=hashes, location=location)
return jsonify({"success": True})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__': if __name__ == '__main__':
app.run(debug=True, port=5000, host='0.0.0.0') app.run(debug=True, port=5000, host='0.0.0.0')
+1
View File
@@ -0,0 +1 @@
scene_id,path,basename,path_id
1 scene_id path basename path_id
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
id,path
1 id path
+2 -1
View File
@@ -2,4 +2,5 @@ flask[async]
smbprotocol smbprotocol
qbittorrent-api qbittorrent-api
requests requests
beautifulsoup4 beautifulsoup4
pandas
+1
View File
@@ -0,0 +1 @@
id,oshash
1 id oshash
+195 -136
View File
@@ -134,8 +134,6 @@
<p class="lead text-white-50">Your friendly neighborhood media manager</p> <p class="lead text-white-50">Your friendly neighborhood media manager</p>
</header> </header>
<div id="messages" class="mb-4"></div>
<div class="accordion" id="mainAccordion"> <div class="accordion" id="mainAccordion">
<div class="accordion-item"> <div class="accordion-item">
@@ -348,31 +346,31 @@
<div class="accordion-item"> <div class="accordion-item">
<h2 class="accordion-header" id="headingQBittorrent"> <h2 class="accordion-header" id="headingQBittorrent">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseQBittorrent" aria-expanded="false" aria-controls="collapseQBittorrent"> <button class="accordion-button collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapseQBittorrent" aria-expanded="false" aria-controls="collapseQBittorrent">
qBittorrent qBittorrent
</button> </button>
</h2> </h2>
<div id="collapseQBittorrent" class="accordion-collapse collapse" aria-labelledby="headingQBittorrent" data-bs-parent="#mainAccordion"> <div id="collapseQBittorrent" class="accordion-collapse collapse" aria-labelledby="headingQBittorrent" data-bs-parent="#mainAccordion">
<div class="accordion-body"> <div class="accordion-body">
<div class="card p-4"> <div class="card p-4">
<h2 class="card-title h4 mb-4"></h2> <h2 class="card-title h4 mb-4"></h2>
<div id="qb-torrents" class="mt-4 table-responsive"></div> <div id="qb-torrents" class="mt-2 table-responsive"></div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
@@ -448,7 +446,7 @@
<label for="coomer-url" class="form-label">Artist URL</label> <label for="coomer-url" class="form-label">Artist URL</label>
<input type="url" class="form-control" id="coomer-url" placeholder="https://coomer.su/onlyfans/user/artistname"> <input type="url" class="form-control" id="coomer-url" placeholder="https://coomer.st/onlyfans/user/artistname">
</div> </div>
@@ -594,25 +592,29 @@
<div class="card p-4"> <div class="card p-4">
<h2 class="card-title h4 mb-4"></h2> <div class="d-flex justify-content-between align-items-center mb-2">
<nav aria-label="breadcrumb"> <nav aria-label="breadcrumb">
<ol class="breadcrumb" id="breadcrumb-container"> <ol class="breadcrumb" id="breadcrumb-container">
</ol> </ol>
</nav> </nav>
<div id="file-explorer-list" class="list-group"></div> <button id="new-folder-btn" class="btn btn-sm btn-primary">New Folder</button>
</div> </div>
</div> <div id="file-explorer-list" class="list-group"></div>
</div> </div>
</div> </div>
</div>
</div>
</div> </div>
</div> </div>
@@ -656,6 +658,10 @@
</div> </div>
</div> </div>
<!-- Toast container -->
<div class="toast-container position-fixed bottom-0 end-0 p-3">
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script> <script>
document.addEventListener('DOMContentLoaded', async () => { document.addEventListener('DOMContentLoaded', async () => {
@@ -826,11 +832,28 @@
function showMessage(message, type = 'info') { function showMessage(message, type = 'info') {
const alert = `<div class="alert alert-${type} alert-dismissible fade show" role="alert"> const toastContainer = document.querySelector('.toast-container');
${message} const toastId = 'toast-' + Date.now();
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> const toastHTML = `
</div>`; <div id="${toastId}" class="toast align-items-center text-bg-${type} border-0" role="alert" aria-live="assertive" aria-atomic="true">
messages.innerHTML += alert; <div class="d-flex">
<div class="toast-body">
${message}
</div>
<button type="button" class="btn-close btn-close-white me-2 m-auto" data-bs-dismiss="toast" aria-label="Close"></button>
</div>
</div>
`;
toastContainer.innerHTML += toastHTML;
const toastEl = document.getElementById(toastId);
const toast = new bootstrap.Toast(toastEl, {
delay: 5000 // Auto-hide after 5 seconds
});
toast.show();
toastEl.addEventListener('hidden.bs.toast', () => {
toastEl.remove();
});
} }
function poll_logs(scan_id, terminal_el) { function poll_logs(scan_id, terminal_el) {
@@ -1185,65 +1208,65 @@
return; return;
} }
const table = document.createElement('table'); const listGroup = document.createElement('div');
table.className = 'table table-striped table-hover'; listGroup.className = 'list-group';
table.innerHTML = `
<thead>
<tr>
<th>Name</th>
<th>Size</th>
<th>Progress</th>
<th>Status</th>
<th>Down Speed</th>
<th>Up Speed</th>
<th>ETA</th>
<th>Actions</th>
</tr>
</thead>
`;
const tbody = document.createElement('tbody');
torrents.forEach(torrent => { torrents.forEach(torrent => {
const row = document.createElement('tr'); const listItem = document.createElement('div');
const progress = (torrent.progress * 100).toFixed(2); listItem.className = 'list-group-item';
row.innerHTML = `
<td>${torrent.name}</td> const titleEl = document.createElement('h6');
<td>${(torrent.size / 1024 / 1024 / 1024).toFixed(2)} GB</td> titleEl.className = 'mb-1 text-break'; // text-break for wrapping
<td> titleEl.textContent = torrent.name;
<div class="progress" style="height: 20px;"> listItem.appendChild(titleEl);
<div class="progress-bar" role="progressbar" style="width: ${progress}%" aria-valuenow="${progress}" aria-valuemin="0" aria-valuemax="100">${progress}%</div>
</div> const savePathEl = document.createElement('small');
</td> savePathEl.className = 'text-muted d-block text-break';
<td>${torrent.status}</td> savePathEl.innerHTML = `&#128193; <strong>Path:</strong> ${torrent.save_path}`;
<td>${(torrent.dlspeed / 1024 / 1024).toFixed(2)} MB/s</td> listItem.appendChild(savePathEl);
<td>${(torrent.upspeed / 1024 / 1024).toFixed(2)} MB/s</td>
<td>${new Date(torrent.eta * 1000).toISOString().substr(11, 8)}</td> const statusLine = document.createElement('small');
<td> statusLine.className = 'text-muted';
<button class="btn btn-sm btn-success qb-action-btn" data-action="resume" data-hash="${torrent.hash}">▶</button> statusLine.innerHTML = `
<button class="btn btn-sm btn-warning qb-action-btn" data-action="pause" data-hash="${torrent.hash}">❚❚</button> Status: <strong>${torrent.status}</strong> | Progress: <strong>${(torrent.progress * 100).toFixed(2)}%</strong><br>
<button class="btn btn-sm btn-danger qb-action-btn" data-action="delete" data-hash="${torrent.hash}">✖</button> Size: ${(torrent.size / 1024 / 1024 / 1024).toFixed(2)} GB | DL: ${(torrent.dlspeed / 1024 / 1024).toFixed(2)} MB/s | UP: ${(torrent.upspeed / 1024 / 1024).toFixed(2)} MB/s | ETA: ${new Date(torrent.eta * 1000).toISOString().substr(11, 8)}
</td>
`; `;
tbody.appendChild(row); listItem.appendChild(statusLine);
const actionsEl = document.createElement('div');
actionsEl.className = 'mt-2 d-flex justify-content-start flex-wrap'; // Use flexbox for buttons
const resumeBtn = createButton('▶ Resume', 'btn-sm btn-success me-1 mb-1', () => qbAction('resume', torrent.hash));
const pauseBtn = createButton('❚❚ Pause', 'btn-sm btn-warning me-1 mb-1', () => qbAction('pause', torrent.hash));
const forceResumeBtn = createButton('⟳ Force Resume', 'btn-sm btn-info me-1 mb-1', () => qbAction('force_resume', torrent.hash));
const recheckBtn = createButton('? Recheck', 'btn-sm btn-secondary me-1 mb-1', () => qbAction('recheck', torrent.hash));
const setLocationBtn = createButton('Set Location', 'btn-sm btn-primary me-1 mb-1', () => openQbMoveModal(torrent.hash));
const deleteBtn = createButton('✖ Delete', 'btn-sm btn-danger me-1 mb-1', () => qbAction('delete', torrent.hash, true));
actionsEl.appendChild(resumeBtn);
actionsEl.appendChild(pauseBtn);
actionsEl.appendChild(forceResumeBtn);
actionsEl.appendChild(recheckBtn);
actionsEl.appendChild(setLocationBtn);
actionsEl.appendChild(deleteBtn);
listItem.appendChild(actionsEl);
listGroup.appendChild(listItem);
}); });
table.appendChild(tbody); qbTorrentsDiv.appendChild(listGroup);
qbTorrentsDiv.appendChild(table); }
document.querySelectorAll('.qb-action-btn').forEach(button => { async function qbAction(action, hash, confirmDelete = false) {
button.addEventListener('click', async (e) => { if (action === 'delete' && confirmDelete && !confirm('Are you sure you want to delete this torrent and its files?')) {
const action = e.target.dataset.action; return;
const hash = e.target.dataset.hash; }
if (action === 'delete' && !confirm('Are you sure you want to delete this torrent and its files?')) { await fetch('/api/qb_action', {
return; method: 'POST',
} headers: { 'Content-Type': 'application/json' },
await fetch('/api/qb_action', { body: JSON.stringify({ action, hashes: [hash] })
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action, hashes: [hash] })
});
fetchAndRenderTorrents();
});
}); });
fetchAndRenderTorrents();
} }
setInterval(fetchAndRenderTorrents, 5000); // Refresh every 5 seconds setInterval(fetchAndRenderTorrents, 5000); // Refresh every 5 seconds
@@ -1268,53 +1291,52 @@
renderBreadcrumbs(path); renderBreadcrumbs(path);
} }
function renderFileExplorer(items) { function renderFileExplorer(items) {
fileExplorerList.innerHTML = ''; fileExplorerList.innerHTML = '';
if (items.error) { if (items.error) {
fileExplorerList.innerHTML = `<div class="alert alert-danger">${items.error}</div>`; fileExplorerList.innerHTML = `<div class="alert alert-danger">${items.error}</div>`;
return; return;
}
items.sort((a, b) => {
if (a.is_dir !== b.is_dir) {
return a.is_dir ? -1 : 1;
}
return a.name.localeCompare(b.name);
});
items.forEach(item => {
const isDir = item.is_dir;
const icon = isDir ? '&#128193;' : '&#128196;';
const listItem = document.createElement('div');
listItem.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center file-explorer-item';
const nameEl = document.createElement('a');
nameEl.href = '#';
nameEl.innerHTML = `${icon} ${item.name}`;
nameEl.addEventListener('click', (e) => {
e.preventDefault();
if (isDir) {
browse(item.path);
} else {
previewFile(item.path, item.name);
} }
}); items.sort((a, b) => {
if (a.is_dir !== b.is_dir) {
const actionsEl = document.createElement('div'); return a.is_dir ? -1 : 1;
actionsEl.className = 'actions'; }
const renameBtn = createButton('Rename', 'btn-sm btn-outline-primary me-2', () => renameFile(item.path, item.name)); return a.name.localeCompare(b.name);
const moveBtn = createButton('Move', 'btn-sm btn-outline-secondary me-2', () => moveFile(item.path)); });
const deleteBtn = createButton('Delete', 'btn-sm btn-outline-danger', () => deleteFile(item.path)); items.forEach(item => {
const isDir = item.is_dir;
actionsEl.appendChild(renameBtn); const icon = isDir ? '&#128193;' : '&#128196;';
actionsEl.appendChild(moveBtn); const listItem = document.createElement('div');
actionsEl.appendChild(deleteBtn); listItem.className = 'list-group-item list-group-item-action d-flex justify-content-between align-items-center file-explorer-item';
listItem.appendChild(nameEl);
listItem.appendChild(actionsEl);
fileExplorerList.appendChild(listItem);
});
}
const nameEl = document.createElement('a');
nameEl.href = '#';
nameEl.innerHTML = `${icon} ${item.name}`;
nameEl.addEventListener('click', (e) => {
e.preventDefault();
if (isDir) {
browse(item.path);
} else {
previewFile(item.path, item.name);
}
});
const actionsEl = document.createElement('div');
actionsEl.className = 'actions';
const renameBtn = createButton('Rename', 'btn-sm btn-outline-primary me-2', () => renameFile(item.path, item.name));
const moveBtn = createButton('Move', 'btn-sm btn-outline-secondary me-2', () => moveFile(item.path));
const deleteBtn = createButton('Delete', 'btn-sm btn-outline-danger', () => deleteFile(item.path));
actionsEl.appendChild(renameBtn);
actionsEl.appendChild(moveBtn);
actionsEl.appendChild(deleteBtn);
listItem.appendChild(nameEl);
listItem.appendChild(actionsEl);
fileExplorerList.appendChild(listItem);
});
}
function createButton(text, classes, onClick) { function createButton(text, classes, onClick) {
const button = document.createElement('button'); const button = document.createElement('button');
button.textContent = text; button.textContent = text;
@@ -1346,14 +1368,28 @@
const moveBreadcrumbContainer = document.getElementById('move-breadcrumb-container'); const moveBreadcrumbContainer = document.getElementById('move-breadcrumb-container');
let moveSourcePath = ''; let moveSourcePath = '';
let moveCurrentPath = ''; let moveCurrentPath = '';
let modalContext = 'move'; // 'move' or 'qb_torrent_location'
let moveTorrentHash = '';
async function moveFile(path) { async function moveFile(path) {
console.log('moveFile called with path:', path);
modalContext = 'move';
moveSourcePath = path; moveSourcePath = path;
document.querySelector('#move-modal .modal-title').textContent = 'Move File';
await browseMoveModal('');
moveModal.show();
}
async function openQbMoveModal(hash) {
modalContext = 'qb_torrent_location';
moveTorrentHash = hash;
document.querySelector('#move-modal .modal-title').textContent = 'Set Torrent Location';
await browseMoveModal(''); await browseMoveModal('');
moveModal.show(); moveModal.show();
} }
async function browseMoveModal(path) { async function browseMoveModal(path) {
console.log('browseMoveModal called with path:', path);
moveCurrentPath = path; moveCurrentPath = path;
moveExplorerList.innerHTML = '<div class="text-center"><div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div></div>'; moveExplorerList.innerHTML = '<div class="text-center"><div class="spinner-border" role="status"><span class="visually-hidden">Loading...</span></div></div>';
@@ -1367,7 +1403,7 @@
renderMoveExplorer(items.filter(item => item.is_dir)); renderMoveExplorer(items.filter(item => item.is_dir));
renderMoveBreadcrumbs(path); renderMoveBreadcrumbs(path);
} }
function renderMoveExplorer(items) { function renderMoveExplorer(items) {
moveExplorerList.innerHTML = ''; moveExplorerList.innerHTML = '';
if (items.error) { if (items.error) {
@@ -1426,29 +1462,52 @@
}); });
breadcrumbItem.appendChild(link); breadcrumbItem.appendChild(link);
} }
breadcrumbContainer.appendChild(breadcrumbItem); moveBreadcrumbContainer.appendChild(breadcrumbItem);
} }
}); });
} }
moveConfirmBtn.addEventListener('click', async () => { moveConfirmBtn.addEventListener('click', async () => {
const destPath = moveCurrentPath; const destPath = moveCurrentPath;
if (moveSourcePath && destPath) { console.log('Move Confirm button clicked. Context:', modalContext);
const response = await fetch('/api/move_file', { console.log('Source:', moveSourcePath);
console.log('Destination:', destPath);
if (modalContext === 'move') {
if (moveSourcePath && destPath) {
const response = await fetch('/api/move_file', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({source_path: moveSourcePath, dest_path: destPath})
});
const result = await response.json();
if(result.success) {
moveModal.hide();
showMessage('File moved successfully!', 'success');
browse(currentPath);
} else {
showMessage(`Error moving file: ${result.error}`, 'danger');
}
}
} else if (modalContext === 'qb_torrent_location') {
console.log('Setting qb torrent location for hash:', moveTorrentHash);
const response = await fetch('/api/qb_set_location', {
method: 'POST', method: 'POST',
headers: {'Content-Type': 'application/json'}, headers: {'Content-Type': 'application/json'},
body: JSON.stringify({source_path: moveSourcePath, dest_path: destPath}) body: JSON.stringify({hashes: [moveTorrentHash], location: destPath})
}); });
const result = await response.json(); const result = await response.json();
if(result.success) { if(result.success) {
moveModal.hide(); moveModal.hide();
browse(currentPath); showMessage('Torrent location set successfully!', 'success');
fetchAndRenderTorrents();
} else { } else {
alert(`Error: ${result.error}`); showMessage(`Error setting torrent location: ${result.error}`, 'danger');
} }
} }
}); });
async function deleteFile(path) { async function deleteFile(path) {
if(confirm(`Are you sure you want to delete ${path}?`)) { if(confirm(`Are you sure you want to delete ${path}?`)) {
const response = await fetch('/api/delete_files', { const response = await fetch('/api/delete_files', {