├── src ├── musicDownload.py ├── videoDownload.py └── getData.py ├── package.json ├── README.md └── index.js /src/musicDownload.py: -------------------------------------------------------------------------------- 1 | from pytube import YouTube 2 | import sys 3 | link = sys.argv[1] 4 | file = sys.argv[2] 5 | yt = YouTube(link) 6 | stream = yt.streams.get_audio_only() 7 | stream.download(filename=str(file)) -------------------------------------------------------------------------------- /src/videoDownload.py: -------------------------------------------------------------------------------- 1 | from pytube import YouTube 2 | import sys 3 | link = sys.argv[1] 4 | file = sys.argv[2] 5 | yt = YouTube(link) 6 | stream = yt.streams.get_highest_resolution() 7 | stream.download(filename=str(file)) -------------------------------------------------------------------------------- /src/getData.py: -------------------------------------------------------------------------------- 1 | from pytube import YouTube 2 | import json 3 | import sys 4 | link = sys.argv[1] 5 | data = { 6 | "title": YouTube(link).title, 7 | "description": YouTube(link).description, 8 | "author": YouTube(link).author, 9 | "publish_date": str(YouTube(link).publish_date), 10 | "length": str(YouTube(link).length), 11 | "views": str(YouTube(link).views), 12 | "thumbnail": YouTube(link).thumbnail_url 13 | } 14 | print(json.dumps(data)) -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "babytube", 3 | "version": "1.0.0", 4 | "description": "a pytube-based library for getting video data and downloading music or videos from YouTube ", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/Swag666baby/babytube.git" 12 | }, 13 | "author": "Swa666baby", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/Swag666baby/babytube/issues" 17 | }, 18 | "homepage": "https://github.com/Swag666baby/babytube#readme", 19 | "dependencies": { 20 | "child_process": "^1.0.2" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # babytube 2 | [![NPM Version](https://img.shields.io/npm/v/babytube.svg?maxAge=10)](https://www.npmjs.com/package/babytube) 3 | [![Npm package yearly downloads](https://badgen.net/npm/dt/babytube)](https://npmjs.com/package/babytube) 4 | 5 | babytube is a pytube based library to get data from a given youtube video, download it or just the audio. 6 | 7 | # necessary 8 | you need python3 and (obviously) nodejs installed on your machine. 9 | 10 | # installation 11 | ``` 12 | npm install babytube 13 | ``` 14 | 15 | # examples 16 | to get data from a video like description, title, duration, thumbnail and stuff like that use the **getData** method. 17 | 18 | ```javascript 19 | const babytube = require("babytube") 20 | 21 | babytube.getData('https://www.youtube.com/watch?v=VIDEO_ID').then((data) => { 22 | console.log(data); 23 | }) 24 | ``` 25 | # 26 | to download some music use the **musicDownload** method. 27 | ```javascript 28 | const babytube = require("babytube") 29 | 30 | babytube.musicDownload('https://www.youtube.com/watch?v=VIDEO_ID', 'FILENAME.mp3').on('finish', () => { 31 | console.log("completed download.") 32 | }) 33 | ``` 34 | or to download the video 35 | ```javascript 36 | const babytube = require("babytube") 37 | 38 | babytube.videoDownload('https://www.youtube.com/watch?v=VIDEO_ID', 'FILENAME.mp4').on('finish', () => { 39 | console.log("completed download.") 40 | }) 41 | ``` 42 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | function errorMessage(pythonProcess) { 2 | pythonProcess.stderr.on('data', (data) => { 3 | console.error(data); 4 | }); 5 | } 6 | 7 | const { spawn } = require('child_process'); 8 | 9 | function getData(link){ 10 | return new Promise((resolve, reject) => { 11 | const pythonProcess = spawn('python3', ['./node_modules/babytube/src/getData.py', link]); 12 | let jsonData = ''; 13 | pythonProcess.stdout.on('data', (data) => { 14 | jsonData += data.toString(); 15 | }); 16 | pythonProcess.stdout.on('end', () => { 17 | try{ 18 | const parsedData = JSON.parse(jsonData); 19 | resolve(parsedData); 20 | }catch (error){ 21 | reject(error); 22 | } 23 | }); 24 | errorMessage(pythonProcess); 25 | }); 26 | } 27 | 28 | function videoDownload(link, file){ 29 | const pythonProcess = spawn('python3', ['./node_modules/babytube/src/videoDownload.py', link, file]); 30 | 31 | pythonProcess.stdout.on('end', (data) => { 32 | pythonProcess.emit('finish') 33 | }); 34 | errorMessage(pythonProcess); 35 | return pythonProcess; 36 | } 37 | 38 | function musicDownload(link, file) { 39 | const pythonProcess = spawn('python3', ['./node_modules/babytube/src/musicDownload.py', link, file]); 40 | 41 | pythonProcess.stdout.on('end', (data) => { 42 | pythonProcess.emit('finish') 43 | }); 44 | errorMessage(pythonProcess); 45 | return pythonProcess; 46 | } 47 | 48 | module.exports = { musicDownload, videoDownload, getData }; 49 | --------------------------------------------------------------------------------