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

A way to limit video length/A way to edit start and end times for the video (i.g. 01:22-12:30) #57

Open
MESAresearch opened this issue Aug 14, 2020 · 12 comments

Comments

@MESAresearch
Copy link

I'm trying to prevent users from being able to upload videos that have like a 10 hour long length so as to not bog up my servers. I can't seem to find anything about this on the docs or when searching online. Is this not a feature yet?

Also being able to edit start and end times to clip the video would be nice. I of course know that's possible with ffmpeg but if it could be done more efficiently at the beginning so that actually only the clipped portion of the video is captured/downloaded by the YouTube-mp3-downloader package. Thanks

@fdciabdul
Copy link

you can read the documentary from ytdl

@kevin4dhd
Copy link

any solution?

@ytb2mp3
Copy link
Owner

ytb2mp3 commented Aug 28, 2020

I'm open to contributions / PRs, feel free to add this functionality

@fdciabdul
Copy link

fdciabdul commented Aug 28, 2020

i thought u need this one , but u need to install ytdl globally with npm i -g ytdl

ytdl.getInfo("ID").then(info => {
if (info.length_seconds > 3000){
console.log("file is too big");
}else{
///

}

any solution?

@kevin4dhd
Copy link

My code for 10 minutes

var YoutubeMp3Downloader = require("youtube-mp3-downloader");
var ffmpeg = require('@ffmpeg-installer/ffmpeg');
var ytdl = require('ytdl-core');

//Configure YoutubeMp3Downloader with your settings
var YD = new YoutubeMp3Downloader({
    "ffmpegPath": ffmpeg.path, // FFmpeg binary location
    "outputPath": "./youtube_mp3/mp3", // Output file location (default: the home directory)
    "youtubeVideoQuality": "highestaudio", // Desired video quality (default: highestaudio)
    "queueParallelism": 2, // Download parallelism (default: 1)
    "progressTimeout": 2000, // Interval in ms for the progress reports (default: 1000)
    "allowWebm": false // Enable download from WebM sources (default: false)
});

let url = "https://www.youtube.com/watch?v=RwJbRV_SSAk&t=35s";
url = url.replace('https://www.youtube.com/watch?v=', '');
url = url.replace('https://youtu.be/', '');
url = url.substring(0, url.lastIndexOf('&'));

try {
    ytdl.getInfo(url).then(info => {
        console.log(info);
        if (info.lengthSeconds > 600) {
            console.log("file is too big");
        } else {
            console.log("e.e");
        }
    });
} catch (e) {
    console.log("La URL no existe");
}

@kevin4dhd
Copy link

thanks @fdciabdul

@fdciabdul
Copy link

My code for 10 minutes

var YoutubeMp3Downloader = require("youtube-mp3-downloader");
var ffmpeg = require('@ffmpeg-installer/ffmpeg');
var ytdl = require('ytdl-core');

//Configure YoutubeMp3Downloader with your settings
var YD = new YoutubeMp3Downloader({
    "ffmpegPath": ffmpeg.path, // FFmpeg binary location
    "outputPath": "./youtube_mp3/mp3", // Output file location (default: the home directory)
    "youtubeVideoQuality": "highestaudio", // Desired video quality (default: highestaudio)
    "queueParallelism": 2, // Download parallelism (default: 1)
    "progressTimeout": 2000, // Interval in ms for the progress reports (default: 1000)
    "allowWebm": false // Enable download from WebM sources (default: false)
});

let url = "https://www.youtube.com/watch?v=RwJbRV_SSAk&t=35s";
url = url.replace('https://www.youtube.com/watch?v=', '');
url = url.replace('https://youtu.be/', '');
url = url.substring(0, url.lastIndexOf('&'));

try {
    ytdl.getInfo(url).then(info => {
        console.log(info);
        if (info.lengthSeconds > 600) {
            console.log("file is too big");
        } else {
            console.log("e.e");
        }
    });
} catch (e) {
    console.log("La URL no existe");
}

for getting video id , you just set the regex like this

var videoid = url.match(/(?:https?:\/{2})?(?:w{3}\.)?youtu(?:be)?\.(?:com|be)(?:\/watch\?v=|\/)([^\s&]+)/);

console.log(videoid[1]);

@MESAresearch
Copy link
Author

Idk what happened but for some reason now it only converts the first 10 seconds of videos into audio?? Is anyone else getting this problem

@fdciabdul
Copy link

fdciabdul commented Aug 29, 2020

Idk what happened but for some reason now it only converts the first 10 seconds of videos into audio?? Is anyone else getting this problem

nope , send your coding on here

@MESAresearch
Copy link
Author

Idk what happened but for some reason now it only converts the first 10 seconds of videos into audio?? Is anyone else getting this problem

nope , send your coding on here

Oh wait nvm. Think it was just a problem with my server I guess because it works now

@MESAresearch
Copy link
Author

Yeah wait actually. I still am getting the 10 second problem. But for me it only occurs for certain videos. Is this happening to anyone else? https://www.youtube.com/watch?v=wuO4_P_8p-Q

@MESAresearch
Copy link
Author

Yeah wait actually. I still am getting the 10 second problem. But for me it only occurs for certain videos. Is this happening to anyone else? https://www.youtube.com/watch?v=wuO4_P_8p-Q

function youtube_parser(url){
var regExp = /^.((youtu.be/)|(v/)|(/u/\w/)|(embed/)|(watch?))??v?=?([^#&?]).*/;
var match = url.match(regExp);
return (match&&match[7].length==11)? match[7] : false;
}

        var isTooLong;

        ytdl.getInfo(youtube_parser(ytAudioURL)).then(info => { //checking yt video length 
          if (info.videoDetails.lengthSeconds > 600){
            console.log('cannot convert videos longer than 10min to audio');
            isTooLong = true;
          }



          if(!isTooLong){
            var YD = new YoutubeMp3Downloader({
              "ffmpegPath": "../../../usr/bin/ffmpeg",        // FFmpeg binary location
              "outputPath": `./public/uploads/${folder}`,    
              "youtubeVideoQuality": "highestaudio",  
              "queueParallelism": 2,                  
              "progressTimeout": 2000,                
              "allowWebm": false                      
            });
            //Download video and save as MP3 file
            YD.download(youtube_parser(ytAudioURL));
            
            YD.on("finished", function(err, data) {
                var ytAudFileName = data.videoTitle + '.mp3';
                postModel.findOneAndUpdate({postNumber:counted},{mp3File:ytAudFileName},function(err,doc){
                  if (err) {
                    throw err;
                  }
                  console.log('youtube mp3 file '+ytAudFileName+' has been saved to folder: '+folder);
                  console.log(doc);
                });
        
            });
          } //YT download is in callback so as to wait for the verdict on if isTooLong is true or not


        });



        here's my code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants