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

downlib

v1.2.7

Published

A powerful library for downloading videos and files from various platforms.

Downloads

88

Readme

Downlib

Downlib is a Node.js class for downloading content from various popular websites such as YouTube, Instagram, and TikTok. It uses tools like yt-dlp for YouTube downloads and handles downloading media from Instagram and TikTok.

License npm version VIEWS

Installation

To use Downlib, first install it via npm:

npm install downlib

Usage

Example Usage

import Downlib from 'downlib';

// Initialize Downlib with optional configurations
const downlib = new Downlib({
    ytDlpPath: '', // Optional: Specify the path for yt-dlp if needed
    deleteAfterDownload: true,
});

// Example: Download a video from YouTube
const youtubeUrl = 'https://www.youtube.com/watch?v=yourvideoid';
const saveDir = './downloads';
downlib.downloadFromYouTube(youtubeUrl, saveDir, { audioOnly: false })
  .then((result) => {
    console.log('Downloaded video information:', result);
  })
  .catch((error) => {
    console.error('Error downloading video:', error);
  });

// Example: Download media from Instagram
const instagramUrl = 'https://www.instagram.com/p/yourpostid/';
downlib.downloadFromInstagram(instagramUrl, saveDir)
  .then((result) => {
    console.log('Downloaded Instagram media:', result);
  })
  .catch((error) => {
    console.error('Error downloading Instagram media:', error);
  });

// Example: Download video from TikTok
const tiktokUrl = 'https://www.tiktok.com/@username/video/123456789';
downlib.downloadFromTikTok(tiktokUrl, saveDir)
  .then((result) => {
    console.log('Downloaded TikTok video:', result);
  })
  .catch((error) => {
    console.error('Error downloading TikTok video:', error);
  });

// Example: Determine the type of a URL
const urlToCheck = 'https://www.reddit.com/r/javascript/';
const urlType = downlib.checkUrlType(urlToCheck);
console.log(`URL '${urlToCheck}' is of type '${urlType}'.`);
// Output: URL 'https://www.reddit.com/r/javascript/' is of type 'Reddit'.

// You can also explore more methods provided by Downlib for other functionalities.

class Downlib

Constructor
/**
 * Initialize Downlib with optional configurations.
 * @param {object} options - Optional configurations.
 */
const downlib = new Downlib(options);
Methods
  • ensureDirectoryExists(dirPath): Ensures that a directory exists at the specified path. Creates the directory if it doesn't already exist.
  • deleteFile(filepath): Deletes a file from the filesystem.
  • downloadFromInstagram(url, saveDir): Downloads media (photos or videos) from Instagram using instagramGetUrl and Axios. It handles multiple media files if available.
  • downloadFromYouTube(url, saveDir, options): Downloads videos or playlists from YouTube using yt-dlp. Supports options like audioOnly to download only audio.
  • downloadFromTikTok(url, saveDir): Downloads videos from TikTok using a custom function (tiktokdl).
  • downloadFromTwitter(url, saveDir): Downloads videos from Twitter using yt-dlp.
  • downloadFromFacebook(url, saveDir, options): Downloads videos from Facebook using yt-dlp.
  • downloadFromTwitch(url, saveDir, options): Downloads videos from Twitch using yt-dlp.
  • downloadFromDailymotion(url, saveDir, options): Downloads videos from Dailymotion using yt-dlp.
  • downloadFromSoundCloud(url, saveDir): Downloads audio tracks from SoundCloud using yt-dlp.
  • downloadFromReddit(url, saveDir, options): Downloads videos from Reddit using yt-dlp.
  • checkUrlType(url): Checks the type of a URL and returns the corresponding social media platform or streaming service (YouTube, Instagram, TikTok, Pinterest, Facebook, Twitter, Reddit, SoundCloud, Dailymotion, Twitch). If the URL doesn't match any recognized patterns, it returns 'Unknown'.

Example Code

See examples above for usage of each method.

Configuration Options

You can pass optional configurations when initializing Downlib. These options include:

  • options.ytDlpPath: Path to yt-dlp executable.
  • options.deleteAfterDownload: Whether to delete the downloaded files after completion.

Issues

If you encounter any issues or have suggestions, please open an issue here.

License

This project is licensed under the MIT License - see the LICENSE file for details.