ming 3 years ago
parent
commit
632e547898
3 changed files with 177 additions and 9 deletions
  1. 40 8
      hhh/yt/upload_test.py
  2. 2 1
      hhh/yt/upload_video.py
  3. 135 0
      hhh/yt/yt_looping.py

+ 40 - 8
hhh/yt/upload_test.py

@@ -1,23 +1,55 @@
 # youtube upload api
 from youtube_upload.client import YoutubeUploader
+import dataset
+import sys
+import codecs
+
+fr=codecs.open('c:/tmp/ytfiles.csv','r','utf-8')
+lines=fr.readlines()
+fr.close()
+fnamedict={}
+for l in lines:
+    elmts=l.split(',')
+    if len(elmts[2])>10:
+        fnamedict[elmts[0].lower().replace('\r','').replace('\n','')]=elmts[2].replace('\r','').replace('\n','').replace("http://youtu.be/",'').replace("https://youtu.be/",'')
+
+prefix='P:\\【完整版】幸福空間節目\\#31'
+fname='31video_1304.mp4'
+yt=fnamedict[fname.lower()]
+print(yt)
+
+#db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
+db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@127.0.0.1:13317/xoops?charset=utf8mb4')
+
+cursor=db.query('select * from youtube_list where youtube_video_id="'+yt+'"')
+title=None
+desc=None
+for c in cursor:
+    print(c)
+    title=c['title']
+    desc=c['description']
+    break
+
+
 #uploader = YoutubeUploader()
-uploader = YoutubeUploader(secrets_file_path='c:\\keys\\client_secret_244642730545-m6s4um0g6p3289ig7k92oseusisibnfp.apps.googleusercontent.com.json')
+uploader = YoutubeUploader(secrets_file_path='c:\\keys\\.client_secrets.json')
 
-uploader.authenticate(access_token='ya29.A0ARrdaM9829B5NAtYwMqfUBXxuYfD6ldW4ANvPuhB00LoMQlWT9v-kU4V0HXugiLLGKw413iM5gRpU1bwRP0iksATPfJyC9bnjOnnOVKGveRZNcl-y_YSqoOpwcMUYem0DlUiXMX-t6DPmt1WiTO-bZwTh-cb',refresh_token='1//0eDV6kUVBHW_VCgYIARAAGA4SNwF-L9IrFgT567AW0kbn36quvdu5NfQrcY-vYAT2xl1dpwP1KOayUQOcgTQCoYG1X7dYh1ye4Gc')
+uploader.authenticate(access_token='ya29.A0ARrdaM-8J7urxGZFJBi4jt4ORkrCofDLMI3SN_jNfFjt5HlRZnlQ_FCRqQNZupdR0HWhAgzOE92p-AjAaBpKwklGQGxM5m3byAjQsr8qHr237p1lsdWif0kffHt2wpNxowuy5UyrzxbrSsj0zmuzZ5JgthRd',refresh_token='1//0e3GKAc0Xl1V1CgYIARAAGA4SNwF-L9IrMmaPcxVGEA6J-yYeVzx8l9C3op0oiga7Ouw-_b7hv3enOhPwEixoH7pY3efL_aY6cSw')
 #uploader.authenticate(oauth_path='c:\\keys\\storage.json')
 
 # Video options
 options = {
-    "title" : "Example title", # The video title
-    "description" : "Example description", # The video description
-    "tags" : ["tag1", "tag2", "tag3"],
-    "categoryId" : "22",
+    "title" : title, # The video title
+    "description" : desc, # The video description
+    "tags" : [],
     "publishAt":"2015-01-21T11:20:27.751+00:00",
     "privacyStatus" : "public", # Video privacy. Can either be "public", "private", or "unlisted"
     "kids" : False # Specifies if the Video if for kids or not. Defaults to False.
 #    "thumbnailLink" : "https://hhh.com.tw/event170427/images/designer/37.png" # Optional. Specifies video thumbnail.
 }
+#    "categoryId" : "22",
+
+uploader.upload(prefix+"\\"+fname, options)
+sys.exit()
 
-# upload video
-uploader.upload('C:\\data\\demo\\test.mp4', options)
 uploader.close()

+ 2 - 1
hhh/yt/upload_video.py

@@ -20,7 +20,8 @@ def get_credentials(secrets):
     'c:\\keys\\.client_secrets.json',
     scopes= ['https://www.googleapis.com/auth/youtube.upload'],
 #    redirect_uri='urn:ietf:wg:oauth:2.0:oob')
-    redirect_uri='http://api.ptt.cx')
+#    redirect_uri='http://api.ptt.cx')
+    redirect_uri='https://m.hhh.com.tw/hhh-home-mb/index.html')
 
 
     # Tell the user to go to the authorization URL.

+ 135 - 0
hhh/yt/yt_looping.py

@@ -0,0 +1,135 @@
+import traceback
+from selenium import webdriver
+from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
+import time
+import os
+import datetime
+import urllib.parse
+from selenium.webdriver.support.ui import WebDriverWait
+from selenium.webdriver.common.by import By
+from selenium.webdriver.support import expected_conditions as EC
+from selenium.webdriver.common.keys import Keys
+import codecs
+import random
+import requests
+import time
+import rpyc
+import sys
+import codecs
+import sys
+import time
+import dataset
+import os
+
+def scrolling(driver,pgnum):
+    ub = driver.find_element_by_css_selector('body')
+    for i in range(pgnum):
+        ub.send_keys(Keys.PAGE_DOWN)
+        if pgnum>1:
+            time.sleep(0.3)
+
+
+def restart_browser():
+#    os.system('docker container restart p4444')
+#    time.sleep(10)
+
+    options = webdriver.ChromeOptions()
+#    options.add_argument("--proxy-server=socks5://130.61.93.198:1080")
+    options.add_argument("start-maximized")
+    options.add_argument('user-data-dir=C:\\Users\\user\\AppData\\Local\\Google\\Chrome\\User Data')
+    options.add_argument('--profile-directory=Profile 7')
+
+    driver=webdriver.Chrome(desired_capabilities=options.to_capabilities())
+    driver.set_window_size(1400,1000)
+    return driver
+
+db2 = dataset.connect('mysql://choozmo:pAssw0rd@db.ptt.cx:3306/hhh?charset=utf8mb4')
+#cursor=db2.query('select * from yt_tasks where yid not in (SELECT yid FROM hhh.yt_hhh_progress)')
+cursor=db2.query('select * from yt_tasks2 where yid not in (SELECT yid FROM hhh.yt_hhh_progress)')
+
+table=db2['yt_hhh_progress']
+yid=spath=title=desc=None
+for c in cursor:
+    print(c)
+    yid=c['yid']
+    spath=c['path']
+    print(spath)
+
+    title=c['title']
+    desc=c['desc']
+    break
+
+driver=restart_browser()
+url='https://www.youtube.com/upload'
+
+driver.get(url)
+print(spath)
+
+time.sleep(5)
+elmt=driver.find_element_by_xpath("//input[@type='file']")
+elmt.send_keys(spath)
+time.sleep(6)
+
+elmts=driver.find_elements_by_xpath("//div[@id='textbox']")
+elmt=elmts[0]
+elmt.click()
+for i in range(20):
+    elmt.send_keys(Keys.BACKSPACE)
+    time.sleep(0.1)
+elmt.send_keys(title)
+time.sleep(1)
+
+elmt=elmts[1]
+elmt.click()
+for i in range(15):
+    elmt.send_keys(Keys.ARROW_UP)
+    time.sleep(0.1)
+elmt.send_keys(Keys.RETURN)
+elmt.send_keys(Keys.ARROW_UP)
+
+elmt.send_keys(desc)
+elmt.send_keys(Keys.RETURN)
+
+time.sleep(1)
+
+elmt=driver.find_element_by_xpath("//*[@id='next-button']")
+elmt.click()
+time.sleep(3)
+
+elmt=driver.find_element_by_xpath("//*[@id='next-button']")
+elmt.click()
+time.sleep(3)
+
+elmt=driver.find_element_by_xpath("//*[@id='next-button']")
+elmt.click()
+
+elmt=driver.find_element_by_xpath("//div[@class='value style-scope ytcp-video-info']")
+new_yid=elmt.text
+table.insert({'yid':yid,'new_yid':new_yid,'dt':datetime.datetime.now()})
+
+#time.sleep(9999)
+
+time.sleep(3)
+elmt=driver.find_element_by_xpath("//*[@id='done-button']")
+elmt.click()
+time.sleep(3)
+
+cnt=0
+while True:
+    try:
+        cnt+=1
+#        elmt=driver.find_element_by_xpath("//span[contains(text(),'檢查完畢,未發現任何問題')]")
+
+#        if cnt >=20:
+#            break
+        elmt=driver.find_element_by_xpath("//span[contains(text(),'檢查完畢,未發現任何問題')]")
+        break
+    except:
+        print('not yet')
+        time.sleep(5)
+
+driver.quit()
+#檢查完畢,未發現任何問題。
+sys.exit()
+#time.sleep(9999)
+