Code Monkey home page Code Monkey logo

yt2mp3's Introduction

Yt2Mp3:

MIT License

Minimalistic Mp3 downloader for YouTube videos, available for the windows platform.
(Downloaded files are stored in the homedirectory under downloads)

Setup:

Install JavaScript dependencies with npm:

npm i

Run with hot-reload and browser dev tools.

npm run dev

Build:

npm run build

yt2mp3's People

Contributors

janml avatar

Watchers

 avatar

Forkers

cakfer scara78

yt2mp3's Issues

Add form validation

Make sure only YouTube videos can be entered in the video url form.
Everything else should give an error (Or change the color of the form to red ?).

Implement actual downloading and converting

The following source code can be used to download and convert a video to mp3 by using ffmpegs pipe:

import ytdl from "ytdl-core";
import {spawn} from "child_process";
import ffmpeg from "ffmpeg-static"


function getFFmpegConvertingConsumer(outputFile, outputFormat) {
    return spawn(
        ffmpeg, 
        [
            // Remove ffmpeg's console spamming
            '-loglevel', '8', '-hide_banner',
            // Redirect/Enable progress messages
            '-progress', 'pipe:3',
            // Set inputs
            '-i', 'pipe:4',
            // Map audio & video from streams
            '-map', '0:a',
            // Define output file
            `${outputFile}.${outputFormat}`,
        ], 
        {
            windowsHide: true,
            stdio: [
                /* Standard: stdin, stdout, stderr */
                'inherit', 'inherit', 'inherit',
                // Custom: pipe:3, pipe:4
                'pipe', 'pipe',
            ],
        }
    )
}


function downloadYoutubeVideoAsMp3(videoUrl, filename, onProgress) {
    let progress = {
        processed: 0, 
        total: Infinity
    }

    let onProgressCaller = null

    const download = ytdl(videoUrl, {quality: 'highestaudio'})
    const ffmpegConvertingConsumer = getFFmpegConvertingConsumer(filename, "mp3")

    download.on('progress', (_, processed, total) => {
        progress = {processed: processed, total: total}
    })

    ffmpegConvertingConsumer.on('close', () => {
        clearInterval(onProgressCaller)
    })
      
    ffmpegConvertingConsumer.stdio[3].on('data', chunk => {
        if (!onProgressCaller) {
            onProgressCaller = setInterval(() => {onProgress(progress)}, 10)
        }
    })

    download.pipe(ffmpegConvertingConsumer.stdio[4])
}


downloadYoutubeVideoAsMp3(
    "https://www.youtube.com/watch?v=EbHGS_bVkXY",
    "123",
    (progress) => {console.log(`Processed: ${progress.processed} of: ${progress.total}`)}
)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.