Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Unlike all your YouTube videos via YouTube Data API v3
import os
import time
import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors
scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]
def main():
# Disable OAuthlib's HTTPS verification when running locally.
# *DO NOT* leave this option enabled in production.
os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
api_service_name = "youtube"
api_version = "v3"
client_secrets_file = "client_secret.com.json" # get this file from your google console
# Get credentials and create an API client
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
client_secrets_file, scopes)
credentials = flow.run_console()
youtube = googleapiclient.discovery.build(
api_service_name, api_version, credentials=credentials)
totalResult = 10 # any integer than 1, needed only for first run
nextPageToken = ''
while totalResult > 0:
likedVideoList = youtube.videos().list(
part="id",
myRating="like",
maxResults=50,
pageToken=nextPageToken
)
likedResponse = likedVideoList.execute()
print('list of next batch response')
print('Looping items begins')
for item in likedResponse['items']:
request = youtube.videos().rate(
id=item['id'],
rating='none'
)
try:
request.execute()
print('Video unliked', item['id'])
except:
print('For whatever reason,', item['id'], 'unliking did not happen')
print('Going to next')
time.sleep(0.2)
totalResult = likedResponse['pageInfo']['totalResults']
nextPageToken = likedResponse['nextPageToken']
print('Videos left', totalResult)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment