Kashire's Youtube Query
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
807B

  1. import urllib.request
  2. from bs4 import BeautifulSoup
  3. import sys
  4. ## Requirements
  5. # pip3 install bs4 --user
  6. ## NOTE: This is a tempory solution for now.
  7. ## I really need this to work via bash
  8. ## or through the youtube API.
  9. user_query = ""
  10. for x in range(1, len(sys.argv)):
  11. user_query += sys.argv[x]
  12. user_query += " "
  13. query = urllib.parse.quote(user_query)
  14. url = "https://www.youtube.com/results?search_query=" + query
  15. response = urllib.request.urlopen(url)
  16. html = response.read()
  17. soup = BeautifulSoup(html, 'html.parser')
  18. for vid in soup.findAll(attrs={'class':'yt-uix-tile-link'}):
  19. if ("/user/" not in vid['href']) and ("&list" not in vid['href']):
  20. vals = 30 - len(vid['href'])
  21. spaces = vals * ' '
  22. print(' https://www.youtube.com' + vid['href'] + spaces + vid['title'])