import time import random import string import os import sys import traceback import rpyc import datetime from selenium.webdriver.common.keys import Keys from selenium.webdriver.firefox.firefox_binary import FirefoxBinary import codecs from selenium import webdriver from selenium.webdriver.chrome.options import * from selenium.webdriver.common.keys import Keys from jinja2 import Template import datetime import pafy #import download_youtube_subtitle.common as common #import download_youtube_subtitle.main as download_youtube_subtitle import json import codecs import time import dataset db = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4') cursor=db.query('select video from yt_list') lst=[] table=db['yt_done_job'] for c in cursor: lst.append(c['video']) for vid in lst: url='https://www.youtube.com/watch?v='+vid video = pafy.new(url) print(video.title) print(video) streams = video.streams best = video.getbest(preftype='mp4') filepath = "c:/tmp/video/"+vid+".mp4" best.download(filepath=filepath, quiet=False) table.insert({'vid':vid,'dt':datetime.datetime.now()})