youtube_info_fetch.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import os
  2. import json
  3. import db_model
  4. import youtube_model
  5. import model
  6. AUTH_CHANNEL_ID = None
  7. """
  8. Set to None to use app level access.
  9. Data fetched without credentials can be more liberally cached and shared among accounts.
  10. See session_sample.json for the format.
  11. """
  12. def main ():
  13. if not os.path.exists('.data'):
  14. os.mkdir('.data')
  15. if not os.path.exists('.data/yt-client-secret.json'):
  16. print('.data/yt-client-secret does not exist. load it up with your youtube client config')
  17. exit(-1)
  18. db_path = db_model.DB_PATH
  19. db_model.init_db( db_path )
  20. if not AUTH_CHANNEL_ID:
  21. print('using app level access')
  22. youtube_user = youtube_model.get_youtube_user(AUTH_CHANNEL_ID)
  23. if AUTH_CHANNEL_ID and not youtube_user:
  24. print('could not load auth for configured channel. exiting.')
  25. exit(-1)
  26. video_ids = [
  27. 'Z6ih1aKeETk',
  28. 'vE-ViyPXj4Q',
  29. 'jfKfPfyJRdk',
  30. '5d7e9lj8BQw',
  31. '_sSBKm-CDNU'
  32. ]
  33. vid_infos = model.get_video_infos(video_ids, youtube_user=youtube_user, db_path=db_path)
  34. print(f'got videos, count={len(vid_infos)}')
  35. #print(json.dumps(vid_infos, indent=2))
  36. if __name__ == '__main__':
  37. main()