I use youtube reporting API to get VideoIDs and some metrics. Then I also use Youtube Data API to get list of ALL VideoNames. But when I combine these two groups (to get names to these IDs), I found out that a lot of names are missing.
HTTP request: GET https://www.googleapis.com/youtube/v3/playlistItems
What is the best HTTP request to get ALL existing VideoNames historically? Why playlistItems doesn't work properly and not showing all VideoNames? Thank you
def get_videos():
for f in glob.glob(f'YoutubeAnalytics/videos/*.json'):
os.unlink(f)
for ch_name, token_file, ch_id in channels:
print(ch_name)
print(ch_id, 'UU' + ch_id[2:])
jsn = json.load(open(TOKEN_PATH + token_file))
svc = get_youtube_data(jsn)
name = token_file.replace('.json', '')
rsp = svc.playlistItems().list(part='snippet', playlistId= 'UU' + ch_id[2:], maxResults=50).execute()
# rsp = svc.channels().list(part='id,snippet', mine=True).execute()
i = 0
while 1:
# tak se to stahne to originalniho folderu Python
with open(f'YoutubeAnalytics/videos/{name}_{i:04d}.json', 'w') as w:
json.dump(rsp, w)
if 'nextPageToken' in rsp:
i += 1
if i % 10 == 0:
print(i)
rsp = svc.playlistItems().list(part='snippet', playlistId= 'UU' + ch_id[2:], maxResults=50, pageToken=rsp['nextPageToken']).execute()
else:
break
def make_videos_csv():
htag = re.compile(r"\s#\S+")
with open(f'YoutubeAnalytics/videos/videos.csv', 'w', encoding='utf-8', newline='') as csvf:
wrt = csv.writer(csvf)
for f in glob.glob(f'YoutubeAnalytics/videos/*.json'):
jsn = json.load(open(f))
for i in jsn['items']:
snip = i['snippet']
descr = snip['description']
tags = ','.join([ t[1:] for t in htag.findall(descr) ])
wrt.writerow((snip['resourceId']['videoId'], i['id'], i['etag'], snip['channelId'], snip['publishedAt'][:-1], snip['title'], snip['description'], tags))