-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
23 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[MESSAGES CONTROL] | ||
disable = bad-continuation, import-error, invalid-name, missing-docstring, multiple-imports, too-few-public-methods, ungrouped-imports, wrong-import-order | ||
disable = bad-continuation, fixme, import-error, invalid-name, missing-docstring, multiple-imports, too-few-public-methods, ungrouped-imports, wrong-import-order | ||
|
||
[FORMAT] | ||
max-line-length = 200 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Does not work because this endpoint also requires an OAuth2 access token | ||
# INSTALL: pip install google-api-python-client google-auth-oauthlib | ||
# USAGE: ./playlistItems_delete.py $id1 [$id2 ...] | ||
|
||
# USAGE: YOUTUBE_API_KEY=... ./playlistItems_delete.py $id1 [$id2 ...] | ||
import os, sys | ||
|
||
import os, requests, sys | ||
import google_auth_oauthlib.flow | ||
import googleapiclient.discovery | ||
import googleapiclient.errors | ||
|
||
|
||
def playlistItems_delete(youtube_api_key, items_ids): | ||
YOUR_CLIENT_SECRET_FILE = "client_secret_CLIENTID.json" | ||
|
||
|
||
def playlistItems_delete(items_ids): | ||
# Disable OAuthlib's HTTPS verification when running locally. | ||
# os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1" | ||
|
||
# Get credentials and create an API client | ||
flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file( | ||
YOUR_CLIENT_SECRET_FILE, scopes=["https://www.googleapis.com/auth/youtube.force-ssl"]) | ||
credentials = flow.run_console() | ||
youtube = googleapiclient.discovery.build("youtube", "v3", credentials=credentials) | ||
|
||
for item_id in items_ids: | ||
resp = requests.delete('https://www.googleapis.com/youtube/v3/playlistItems', params={ | ||
'key': youtube_api_key, | ||
'id': item_id, | ||
}) | ||
if resp != 200: | ||
print(resp.text, file=sys.stderr) | ||
resp.raise_for_status() | ||
youtube.playlistItems().delete(id=item_id).execute() | ||
|
||
|
||
if __name__ == '__main__': | ||
playlistItems_delete(os.environ['YOUTUBE_API_KEY'], sys.argv[1:]) | ||
playlistItems_delete(sys.argv[1:]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters