0

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))
Luciebix
  • 3
  • 2

1 Answers1

0

Consider that some videos may be marked as private, then, if you're not the owner of the video(s), you wont be able to get the details of such video(s).

In your comment, you added these video_ids examples:

zzr8YwY0y2U, zypHHsc3Q_Y, zyXCdTAdL2s, zvgtoZvL-Gs

Here are the results of each one:

  • zzr8YwY0y2U = Catch the Crooks - LEGO City - mini movie: Ep. 13
  • zypHHsc3Q_Y = LEGO Marvel: Spider-Man 'Vexed By Venom' Episode 4: Paging Ghost-Spider
  • zyXCdTAdL2s = PUBLIC INFO NOT AVAILABLE - this video is private.
  • zvgtoZvL-Gs = ~どんなどうぶつが暮らすサファリをつくる?篇~「みやぞんとあらぽんがつくる!つながる、ひろがる、 レゴ シティ!」

See the answers here and modify your code in order to handle such unavailable video(s) you might get with your current code - or just accept that you cannot get data if those video(s) are not publicly available.