Get keywords from YouTube video meta tag.
My wife was wanting to see meta tags embedded in YouTube videos so I whipped up this quick Python script.
Install Python 3
Install Beautiful Soup
Ubuntu:
sudo apt-get install python3-bs4
sudo apt-get install python-lxml
PIP:
python3 -m pip install BeautifulSoup4
python3 -m pip install lxml
import urllib.request from bs4 import BeautifulSoup url = 'https://www.youtube.com/watch?v=BWYiMcH0cRc' print('URL: %s' % url) print('*' * 60) request = urllib.request.Request(url) response = urllib.request.urlopen(request) soup = BeautifulSoup(response,"lxml") keywords = soup.find("meta", {"name":"keywords"})['content'] for keyword in keywords.split(','): print(keyword.strip())
Result:
URL: https://www.youtube.com/watch?v=BWYiMcH0cRc
****************************************
indoor plants
indoor plant guide
house plants
Make it a simple Tk application:
import urllib.request from bs4 import BeautifulSoup from tkinter import * def get_keywords(): url = entry.get() if not url: return listbox.delete(0, END) request = urllib.request.Request(url) response = urllib.request.urlopen(request) soup = BeautifulSoup(response,"lxml") keywords = soup.find("meta", {"name":"keywords"})['content'] for id,keyword in enumerate(keywords.split(',')): #print(keyword.strip()) listbox.insert(id, keyword.strip()) entry.delete(0, END) entry.focus() def close_window (): root.destroy() root = Tk() root.title('Keywords') root.geometry("640x480") root.resizable(0, 0) topframe = Frame(root) topframe.pack(side = TOP, fill = X) label = Label(topframe, text = "URL") label.pack(side = LEFT) entry = Entry(topframe, bd = 1) entry.pack(fill = X) entry.focus() buttonframe = Frame(root) buttonframe.pack(side = BOTTOM, fill = X) button_run = Button(buttonframe, text="Run", command=get_keywords) button_run.pack(side = RIGHT) button_close = Button(buttonframe, text="Close", command=close_window) button_close.pack(side = LEFT) bottomframe = Frame(root) bottomframe.pack(side = BOTTOM, fill = BOTH, expand = 1) listbox = Listbox(bottomframe) listbox.pack(side = LEFT, fill = BOTH, expand = 1) root.mainloop()