Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord
- import os
- import requests
- import shutil
- import moviepy.editor as mp
- from google.oauth2.credentials import Credentials
- from googleapiclient.errors import HttpError
- from googleapiclient.discovery import build
- # Define the intents for the Discord bot
- intents = discord.Intents.default()
- intents.members = True
- # Discord bot setup
- client = discord.Client(intents=intents)
- @client.event
- async def on_ready():
- print('Logged in as {0.user}'.format(client))
- @client.event
- async def on_message(message):
- if message.author == client.user:
- return
- if message.content.startswith('!tiktok'):
- # Get the TikTok video URL from the user's message
- url = message.content.split(' ')[1]
- # Download the TikTok video
- response = requests.get(url, stream=True)
- with open('video.mp4', 'wb') as file:
- shutil.copyfileobj(response.raw, file)
- del response
- # Apply a green filter to the video using MoviePy
- clip = mp.VideoFileClip('video.mp4')
- green_screen = mp.ColorClip(clip.size, (0, 255, 0))
- filtered_clip = mp.CompositeVideoClip([clip, green_screen.set_opacity(0.5)])
- filtered_clip.write_videofile('filtered_video.mp4', fps=clip.fps)
- # Remove the metadata from the video
- os.system('ffmpeg -i filtered_video.mp4 -map_metadata -1 -c:v copy -c:a copy no_metadata_video.mp4')
- # Upload the video to Google Drive
- try:
- # Set up the Google Drive API
- creds = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/drive'])
- service = build('drive', 'v3', credentials=creds)
- # Create a file on Google Drive and upload the video to it
- file_metadata = {'name': 'no_metadata_video.mp4'}
- media = MediaFileUpload('no_metadata_video.mp4', resumable=True)
- file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
- # Send a message to the Discord channel with the link to the uploaded video
- await message.channel.send(f'The filtered and processed video has been uploaded to Google Drive: https://drive.google.com/file/d/{file.get("id")}')
- except HttpError as error:
- print(f'An error occurred: {error}')
- await message.channel.send('There was an error uploading the video to Google Drive.')
- # Run the Discord bot
- client.run('mytoken')
Advertisement
Add Comment
Please, Sign In to add comment