Skip to content

Commit

Permalink
Merge branch 'main' of github.com:bulgariamitko/flutterflowtutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
bulgariamitko committed Jan 24, 2024
2 parents 0050d2c + 943c633 commit 9fe44dd
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ ff-tutorials.sublime-project
ff-tutorials.sublime-workspace
/Paid Members/*.csv
flutterflowtutorials.code-workspace
YT/token.json
YT/credentials.json
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Links

[![Support my work](https://img.shields.io/badge/-Support%20my%20work-purple?style=for-the-badge&logo=github-sponsors&logoColor=white)](https://github.com/sponsors/bulgariamitko) [![Use this code](https://img.shields.io/badge/-Use%20this%20code-blue?style=for-the-badge&logo=Github)](https://bulgariamitko.github.io/flutterflowtutorials/) [![My YouTube channel](https://img.shields.io/badge/-YouTube-red?style=for-the-badge&logo=youtube&logoColor=white)](https://youtube.com/@flutterflowexpert) [![Book me](https://img.shields.io/badge/-Book%20me-green?style=for-the-badge&logo=googlecalendar&logoColor=white)](https://calendly.com/bulgaria_mitko) [![Join my Discord](https://img.shields.io/badge/-Join%20my%20Discord-orange?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/ERDVFBkJmY)
[![Support my work](https://img.shields.io/badge/-Support%20my%20work-purple?style=for-the-badge&logo=github-sponsors&logoColor=white)](https://github.com/sponsors/bulgariamitko) [![Use this code](https://img.shields.io/badge/-Use%20this%20code-blue?style=for-the-badge&logo=Github)](https://bulgariamitko.github.io/flutterflowtutorials/) [![My YouTube channel](https://img.shields.io/badge/-YouTube-red?style=for-the-badge&logo=youtube&logoColor=white)](https://youtube.com/@flutterflowexpert) [![Book me](https://img.shields.io/badge/-Book%20me-green?style=for-the-badge&logo=googlecalendar&logoColor=white)](https://calendly.com/bulgaria_mitko) [![Join my Discord](https://img.shields.io/badge/-Join%20my%20Discord-orange?style=for-the-badge&logo=discord&logoColor=white)](https://discord.gg/G69hSUqEeU)


# FlutterFlow Tutorials
Expand Down
115 changes: 115 additions & 0 deletions YT/replace-desc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import os
import re
import json
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from google.auth.transport.requests import Request

# Define the scopes
SCOPES = ['https://www.googleapis.com/auth/youtube']

def replace_discord_link(description):
old_link = 'https://discord.gg/ERDVFBkJmY'
new_link = 'https://discord.gg/G69hSUqEeU'
return description.replace(old_link, new_link)

def update_video_description(youtube, video_id, new_title, new_description, category_id):
youtube.videos().update(
part='snippet',
body={
'id': video_id,
'snippet': {
'title': new_title,
'description': new_description,
'categoryId': category_id
}
}
).execute()

def get_all_videos(youtube):
request = youtube.channels().list(
part="contentDetails",
mine=True
)
response = request.execute()

playlist_id = response['items'][0]['contentDetails']['relatedPlaylists']['uploads']
videos = []

next_page_token = None
while True:
playlist_request = youtube.playlistItems().list(
part="snippet,contentDetails",
playlistId=playlist_id,
maxResults=50,
pageToken=next_page_token
)
playlist_response = playlist_request.execute()

videos += playlist_response['items']
next_page_token = playlist_response.get('nextPageToken')

if not next_page_token:
break

return videos

def get_video_details(youtube, video_id):
response = youtube.videos().list(
part="snippet",
id=video_id
).execute()

if response['items']:
return response['items'][0]['snippet']
else:
return None

def main():
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
os.path.expanduser('credentials.json'), SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())

youtube = build('youtube', 'v3', credentials=creds)

videos = get_all_videos(youtube)

print(f"Found {len(videos)} videos.")

for video in videos:
video_id = video['snippet']['resourceId']['videoId']
video_details = get_video_details(youtube, video_id)

if video_details:
original_title = video_details['title']
original_description = video_details['description']
category_id = video_details.get('categoryId')

if category_id:
new_description = replace_discord_link(original_description)

if original_description != new_description:
update_video_description(youtube, video_id, original_title, new_description, category_id)
else:
print(f"No change for video: {video_id}")
else:
print(f"Category ID not found for video: {video_id}")
else:
print(f"Details not found for video: {video_id}")

if __name__ == '__main__':
main()

0 comments on commit 9fe44dd

Please sign in to comment.