npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

utorrent-web-api

v0.3.2

Published

A complete uTorrent Web API for TypeScript/JavaScript

Downloads

21

Readme

utorrent-web-api

A powerful and complete implementation of the uTorrent Web API. It is compatible with both Javascript and TypeScript!

Note: This library is a work in progress, so not all features may be available.

Installation

npm i utorrent-web-api

Examples

Some neat examples to show the simplicity and power of the API.

Create a Client

Creating a new uTorrent client instance is easy!

import { uTorrent } from "utorrent-web-api";

// Create an instance of the client
let utorrent = new uTorrent(host, port, username, password);

Add Torrents

Torrents can be added by .torrent URL, magnet link, or file upload.

// Add a torrent via .torrent URL or magnet link
utorrent.addUrl(url).then((infoHash) => {
    console.log("Success! Info hash:", infoHash);
}).catch((err) => {
    console.error("Failed to add the torrent:", err);
});

// Add a torrent via .torrent file upload
[WORK IN PROGRESS]

List Torrents

It's easy to get the list of torrents currently in uTorrent!

let myAddedTorrent;

utorrent.list().then((result) => {
    // Find the added torrent and save it
    myAddedTorrent = result.torrents[infoHash];

    // Iterate over all torrents
    for (let hash in result.torrents) {
        // Do something with the torrent
    }
}).catch((err) => {
    console.error("Failed to list torrents", err);
});

Working with Torrents

Once you have a torrent object, you can use that object to work with the torrent directly. Each time an action is performed, it will update all of its attributes with the latest information from the server. View the full Torrent documentation here: Torrent Docs

// Check if the torrent status indicates it's paused
if (myAddedTorrent.status & TorrentStatus.Paused) {
    console.log("It is paused!");
}

// Refresh the torrent
myAddedTorrent.refresh().then(() => {
    console.log("Torrent refreshed successfully");
});

// Pause the torrent
myAddedTorrent.pause().then(() => {
    console.log("Paused successfully");
});

// Start the torrent
myAddedTorrent.start().then(() => {
    console.log("Started successfully");
});

// Delete the torrent with its data
myAddedTorrent.remove(RemoveFlag.WithTorrent | RemoveFlag.WithData).then(() => {
    console.log("Removed successfully");
});

Downloaded Files

It's a peace of cake to manage downloading or downloaded files with the API! You can check on their progress and manage their priority.

// Fetch the files
myTorrent.files().then((fileArray) => {
    for (let file of fileArray) {
        console.log("Name:", file.name, "; Progress:", file.progress * 100);
    }
});

// Set a file's download priority
file.setPriority(Priority.Skip).then(() => {
    console.log("This file will not be downloaded...");
});

// Set the priority of multiple files at once
myTorrent.setFilePriority(myTorrentFiles, Priority.High).then(() => {
    console.log("The files specified have been set");
});

Documentation

Full Documention can be found here