yt_dl.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import time
  2. import random
  3. import string
  4. import os
  5. import sys
  6. import traceback
  7. import rpyc
  8. import datetime
  9. from selenium.webdriver.common.keys import Keys
  10. from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
  11. import codecs
  12. from selenium import webdriver
  13. from selenium.webdriver.chrome.options import *
  14. from selenium.webdriver.common.keys import Keys
  15. from jinja2 import Template
  16. import datetime
  17. import pafy
  18. #import download_youtube_subtitle.common as common
  19. #import download_youtube_subtitle.main as download_youtube_subtitle
  20. import json
  21. import codecs
  22. import time
  23. import dataset
  24. db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
  25. cursor=db.query('select video from yt_list')
  26. lst=[]
  27. table=db['yt_done_job']
  28. for c in cursor:
  29. lst.append(c['video'])
  30. for vid in lst:
  31. url='https://www.youtube.com/watch?v='+vid
  32. video = pafy.new(url)
  33. print(video.title)
  34. print(video)
  35. streams = video.streams
  36. best = video.getbest(preftype='mp4')
  37. filepath = "c:/tmp/video/"+vid+".mp4"
  38. best.download(filepath=filepath, quiet=False)
  39. table.insert({'vid':vid,'dt':datetime.datetime.now()})