Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add torrent functionality to automate book downloads #111

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions about.html
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ <h1 class="display-5 fw-semibold">
chapters. You can also adjust playback speed and volume to suit your
listening preferences.
</p>
<button id="downloadBtn" class="btn btn-primary mt-4">Download Torrent</button>
<div class="progress mt-3">
<div id="torrent-progress-bar" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div id="error-message" class="alert alert-danger mt-3" style="display: none;"></div>
</div>
<div class="col-12 col-lg-6 pe-5 ps-lg-5">
<img
Expand Down
5 changes: 5 additions & 0 deletions adventures.html
Original file line number Diff line number Diff line change
Expand Up @@ -569,5 +569,10 @@ <h2 class="display-5 page-title fw-semibold mb-6">
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz"
crossorigin="anonymous"
></script>
<button id="downloadBtn" class="btn btn-primary mt-4">Download Torrent</button>
<div class="progress mt-3">
<div id="torrent-progress-bar" class="progress-bar" role="progressbar" style="width: 0%;" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
</div>
<div id="error-message" class="alert alert-danger mt-3" style="display: none;"></div>
</body>
</html>
25 changes: 25 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { downloadTorrent, handleError, displayProgress, manageStorage } from './torrent.js';

document.addEventListener("DOMContentLoaded", function () {
const audioPlayer = document.getElementById("audio-player");
const playlistItems = document.querySelectorAll("#playlist li");
Expand Down Expand Up @@ -77,4 +79,27 @@ document.addEventListener("DOMContentLoaded", function () {

// Event listener for "Previous" button
if (prevBtn) prevBtn.addEventListener("click", prevPage);

// Torrent download button functionality
const downloadBtn = document.getElementById("downloadBtn");
if (downloadBtn) {
downloadBtn.addEventListener("click", () => {
const torrentId = "magnet:?xt=urn:btih:...";
const downloadPath = "downloads/";
downloadTorrent(torrentId, downloadPath);
});
}

// Display torrent download progress
const progressBar = document.getElementById("torrent-progress-bar");
if (progressBar) {
displayProgress(progressBar);
}

// Handle torrent download errors
client.on('error', handleError);

// Manage torrent download storage
const storagePath = "downloads/";
manageStorage(storagePath);
});
Loading