Advertisement
Guest User

Untitled

a guest
Mar 16th, 2021
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.83 KB | None | 0 0
  1. import requests
  2. import time
  3. your_api_key = 'AI###########################BA'
  4. #https://console.cloud.google.com/
  5. Archive_Filename = "F:\\ProperBackup\\Video\\Youtube2\\youtube-dl-archive_backup.txt" # File filed with 'youtube XXXXXXXX'
  6. Results_Filename = "F:\\ProperBackup\\Video\\Youtube2\\youtube-dl-archive-verify.txt" # File to dump results to
  7.  
  8. num_lines = sum(1 for line in open(Archive_Filename))
  9. print(f"{num_lines} Videos detected")
  10. total_videos = 0
  11. removed_videos = 0
  12. unlisted_videos = 0
  13. public_videos = 0
  14. if num_lines < 9000: #Not a joke, the API limits you to 10,000 requests per day
  15.     rate_limit = 1
  16. else:
  17.     rate_limit = 9 #Seriously, this script fails if it gets rate limit enforced, so don't tinker.
  18.  
  19. for i in range (0,num_lines):
  20.     line = open(Archive_Filename, "r").readlines()[i]
  21.     y, z = line.split()
  22.     url = f'https://www.googleapis.com/youtube/v3/videos?id={z}&key={your_api_key}&part=status'
  23.     url_get = requests.get(url)
  24.     data = url_get.json()
  25.     time.sleep(rate_limit)
  26.     total_videos +=1
  27.     try:
  28.         returned = data['items'][0]['status']['privacyStatus']
  29.         if returned == 'public':
  30.             print(z+" Public")
  31.             public_videos += 1
  32.         elif returned == 'unlisted':
  33.             unlisted_videos += 1
  34.             print(z+" Unlisted")
  35.             f = open(Results_Filename,'a+')
  36.             f.write('\n' + z + ", Unlisted")
  37.             f.close()
  38.         else:
  39.             print(z+" Other," + returned + "###########################")
  40.     except(IndexError, ValueError):
  41.         removed_videos += 1
  42.         gotdata = 'null'
  43.         print(z + " Private or nuked")
  44.         f = open(Results_Filename,'a+')
  45.         f.write('\n' + z + ", Removed")
  46.         f.close()
  47.     pr = round(100*removed_videos/total_videos,2)
  48.     pu = round(100*unlisted_videos/total_videos,2)
  49.     pp = round(100*public_videos/total_videos,2)
  50.     print(f"%P={pp},%U={pu},%R={pr}")
  51.     print(f"P={public_videos},U={unlisted_videos},R={removed_videos}")
  52.  
  53.  
  54. print("Pause")
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement