time.sleep(1) videos.extend(get_all_video_ids(nextPageToken)) return videos def get_video_summary(id): result = youtube.videos().list( part='id,snippet,contentDetails,liveStreamingDetails', id=id, ).execute() return result output_dir = './work' # 出力先ディレクトリがなければ作る if not os.path.isdir(output_dir): os.makedirs(output_dir) local_dict = {x['id']: x for x in get_local_video_info()} ids = get_all_video_ids() for id in ids: if id in local_dict: # print('{} skipped.'.format(id)) continue time.sleep(1) summary = get_video_summary(id) s = json.dumps(summary, ensure_ascii=False) with codecs.open('{}/{}.json'.format(output_dir, id), 'w', 'utf-8') as f: f.write(s) print('{} done.'.format(id))
from get_local_video_info import get_local_video_info for info in get_local_video_info(): print('{id}:{title}:{date}:{isLive}:{existsChatData}'.format(**info))