npm init -y
npm i express
index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
const express = require('express') const bodyparser = require('body-parser') const {exec} = require('child_process') const app = express() app.use(bodyparser.urlencoded({extended:false})) app.use(bodyparser.json()) app.get('/',(req,res) => { res.sendFile(__dirname + "/index.html") }) app.post('/getinfo',(req,res) => { exec(`python app.py ${req.body.url} ${req.body.limit} ${req.body.sort}`,(err,stdout,stderr) => { if(err){ console.log(err) } else{ console.log(stdout) res.download("videoinfo.csv",(err) => { }) } }) }) app.listen(5000) |
index.html
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
<!DOCTYPE html> <html> <head> <title>Youtube Channel Info App</title> </head> <!-- Latest compiled and minified CSS --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"> <!-- jQuery library --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <body> <div class="container"> <h1 class="text-center"> Youtube Channel Info App </h1> <form action="/getinfo" method="post"> <div class="form-group"> <label for="url">Enter Channel URL</label> <input class="form-control" required type="text" name="url" placeholder="Enter Youtube Channel URL" id=""> </div> <div class="form-group"> <label for="limit">Enter Number of Videos to Get:</label> <input type="number" name="limit" value="5" required class="form-control" id=""> </div> <div class="form-group"> <select name="sort" class="form-control" required id=""> <option value="popular" selected>Popular Videos</option> <option value="newest">Newest Videos</option> <option value="oldest">Oldest Videos</option> </select> </div> <div class="form-group"> <button class="btn btn-danger btn-block"> Get Info </button> </div> </form> </div> </body> </html> |
Now make a app.py
script and copy paste the below code
app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import scrapetube import csv import sys videos = scrapetube.get_channel(channel_url=sys.argv[1], limit=int(sys.argv[2]),sort_by=sys.argv[3]) x=-1 print(videos) f = open('videoinfo.csv', 'w') writer = csv.writer(f) header = ['title','views','publishedTime'] writer.writerow(header) for video in videos: print(video['title']['runs'][x+1]['text']) print(video['viewCountText']['simpleText']) print(video['publishedTimeText']['simpleText']) writer.writerow(['runs'][x+1]['text'],video['viewCountText']['simpleText'],video['publishedTimeText']['simpleText']]) |