Node.js Express Python Script to Extract Youtube Video Tags Using BeautifulSoup4 Library Full Project 2020

Node.js Express Python Script to Extract Youtube Video Tags Using BeautifulSoup4 Library Full Project 2020

 

 

Live Demo

 

Youtube Video Tag Finder Tool Live Demo Here

 

 

Screenshot

 

 

 

 

 

 

Dependencies

 

 

In order to get started you need to create the python script you need to install these dependencies

 

pip install bs4

 

pip install requests

 

Now you need to create the node.js project by invoking the command

 

npm init -y

 

npm i express ejs

 

Now you need to create the index.js file and copy paste the following code

 

 

const express = require('express')

const {spawn} = require('child_process')

const app = express()

app.set('view engine','ejs')

const bodyParser = require('body-parser')

app.use(bodyParser.json())

app.use(bodyParser.urlencoded({extended:false}))

app.get('/',(req,res) => {

res.render('index',{title:'Youtube Video Url Tag Finder'})

})

app.post('/',(req,res) => {

var url = req.body.url

 console.log(url)
 
 var dataToSend;
 // spawn new child process to call the python script
 const python = spawn('python3', ['script.py',url]);
 // collect data from script
 python.stdout.on('data', function (data) {
  console.log('Pipe data from python script ...');
  dataToSend = data.toString();
 });
 // in close event we are sure that stream from child process is closed
 python.on('close', (code) => {
 console.log(`child process close all stdio with code ${code}`);
 // send data to browser
 res.render('youtubetagfinder',{title:'FREE Youtube Video Tag Finder Extractor and Generator Online Tool - Extract Youtube Video Tags From Video URL Online - FreeMediaTools.com',tags:dataToSend})
 });

})

app.listen(5000)

 

See also  How to Modify PDF File and Add Watermark Text in Deno Using PDF-LIB Library Full Tutorial With Example

 

#  HTML Template File

 

 

Now create a directory called as views inside the root directory and inside this you need to create the file called as index.ejs and copy paste the following code

 

 

index.ejs

 

 

<div class="container">
          <br>
      <h1 class="text-center">Youtube Video Tag Finder Or Extractor Online</h1>
      <form action="/youtubetagfinder" method="post">
      <div class="form-group">
        <label for="youtubeurl">Youtube Video URL:</label>
        <input
          type="text"
          name="url"
          placeholder="https://www.youtube.com/watch?v=4hFFY5Uzazs"
          required
          class="form-control"
        >
      </div>

      <div class="form-group">
        <button id="button" class="btn btn-danger btn-block">
          Get Youtube Video Tags
        </button>
      </div>

      </form>

      <br><br>

      <div class="form-group">
<label for="youtubetags">Youtube Tags:</label>
<textarea id="code" cols="10" rows="10" class="form-control" placeholder="Youtube Tags"><%=tags%></textarea>
</div>
      <br><br>

      
      <div class="form-group">
        <button id="copy" onclick="copytoclipboard()" class="btn btn-primary btn-block">
          Copy to Clipboard
        </button>
      </div>
        <br><br>
      </div>
</body>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
<script>

function copytoclipboard(){
  var textToCopy = $("#code").text();

var myTemporaryInputElement = document.createElement("input");
myTemporaryInputElement.type = "text";
myTemporaryInputElement.value = textToCopy;

document.body.appendChild(myTemporaryInputElement);

myTemporaryInputElement.select();
document.execCommand("Copy");

document.body.removeChild(myTemporaryInputElement);

Swal.fire(
  'Good job!',
  'Youtube Video Tags Successfully Copied',
  'success'
)
}

</script>
</html>

 

 

 

 

 

script.py

 

 

from bs4 import BeautifulSoup
import requests
import sys

def youtubeTags():
    request = requests.get(sys.argv[1])
    
    html = BeautifulSoup(request.content,"html.parser")
    
    tags = html.find_all("meta",property="og:video:tag")
    
    for tag in tags:
        print(tag['content'] + "," )
        
        
youtubeTags()

 

 

See also  Generate Custom Social Share Buttons With jQuery C Share Plugin

 

Execution

 

 

Now you can run your node.js app by running the command

 

node index.js

 

 

Leave a Reply