upload_test.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # youtube upload api
  2. from youtube_upload.client import YoutubeUploader
  3. import dataset
  4. import sys
  5. import codecs
  6. fr=codecs.open('c:/tmp/ytfiles.csv','r','utf-8')
  7. lines=fr.readlines()
  8. fr.close()
  9. fnamedict={}
  10. for l in lines:
  11. elmts=l.split(',')
  12. if len(elmts[2])>10:
  13. fnamedict[elmts[0].lower().replace('\r','').replace('\n','')]=elmts[2].replace('\r','').replace('\n','').replace("http://youtu.be/",'').replace("https://youtu.be/",'')
  14. prefix='P:\\【完整版】幸福空間節目\\#31'
  15. fname='31video_1304.mp4'
  16. yt=fnamedict[fname.lower()]
  17. print(yt)
  18. #db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@hhh-v57.cmab1ctkglka.ap-northeast-2.rds.amazonaws.com:3306/xoops?charset=utf8mb4')
  19. db = dataset.connect('mysql://hhh7796hhh:lYmWsu^ujcA1@127.0.0.1:13317/xoops?charset=utf8mb4')
  20. cursor=db.query('select * from youtube_list where youtube_video_id="'+yt+'"')
  21. title=None
  22. desc=None
  23. for c in cursor:
  24. print(c)
  25. title=c['title']
  26. desc=c['description']
  27. break
  28. #uploader = YoutubeUploader()
  29. uploader = YoutubeUploader(secrets_file_path='c:\\keys\\.client_secrets.json')
  30. uploader.authenticate(access_token='ya29.A0ARrdaM-8J7urxGZFJBi4jt4ORkrCofDLMI3SN_jNfFjt5HlRZnlQ_FCRqQNZupdR0HWhAgzOE92p-AjAaBpKwklGQGxM5m3byAjQsr8qHr237p1lsdWif0kffHt2wpNxowuy5UyrzxbrSsj0zmuzZ5JgthRd',refresh_token='1//0e3GKAc0Xl1V1CgYIARAAGA4SNwF-L9IrMmaPcxVGEA6J-yYeVzx8l9C3op0oiga7Ouw-_b7hv3enOhPwEixoH7pY3efL_aY6cSw')
  31. #uploader.authenticate(oauth_path='c:\\keys\\storage.json')
  32. # Video options
  33. options = {
  34. "title" : title, # The video title
  35. "description" : desc, # The video description
  36. "tags" : [],
  37. "publishAt":"2015-01-21T11:20:27.751+00:00",
  38. "privacyStatus" : "public", # Video privacy. Can either be "public", "private", or "unlisted"
  39. "kids" : False # Specifies if the Video if for kids or not. Defaults to False.
  40. # "thumbnailLink" : "https://hhh.com.tw/event170427/images/designer/37.png" # Optional. Specifies video thumbnail.
  41. }
  42. # "categoryId" : "22",
  43. uploader.upload(prefix+"\\"+fname, options)
  44. sys.exit()
  45. uploader.close()