Guest User

bot dis.

a guest
Apr 18th, 2023
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. import discord
  2. import os
  3. import requests
  4. import shutil
  5. import moviepy.editor as mp
  6. from google.oauth2.credentials import Credentials
  7. from googleapiclient.errors import HttpError
  8. from googleapiclient.discovery import build
  9.  
  10. # Define the intents for the Discord bot
  11. intents = discord.Intents.default()
  12. intents.members = True
  13.  
  14. # Discord bot setup
  15. client = discord.Client(intents=intents)
  16.  
  17. @client.event
  18. async def on_ready():
  19. print('Logged in as {0.user}'.format(client))
  20.  
  21. @client.event
  22. async def on_message(message):
  23. if message.author == client.user:
  24. return
  25.  
  26. if message.content.startswith('!tiktok'):
  27. # Get the TikTok video URL from the user's message
  28. url = message.content.split(' ')[1]
  29.  
  30. # Download the TikTok video
  31. response = requests.get(url, stream=True)
  32. with open('video.mp4', 'wb') as file:
  33. shutil.copyfileobj(response.raw, file)
  34. del response
  35.  
  36. # Apply a green filter to the video using MoviePy
  37. clip = mp.VideoFileClip('video.mp4')
  38. green_screen = mp.ColorClip(clip.size, (0, 255, 0))
  39. filtered_clip = mp.CompositeVideoClip([clip, green_screen.set_opacity(0.5)])
  40. filtered_clip.write_videofile('filtered_video.mp4', fps=clip.fps)
  41.  
  42. # Remove the metadata from the video
  43. os.system('ffmpeg -i filtered_video.mp4 -map_metadata -1 -c:v copy -c:a copy no_metadata_video.mp4')
  44.  
  45. # Upload the video to Google Drive
  46. try:
  47. # Set up the Google Drive API
  48. creds = Credentials.from_authorized_user_file('credentials.json', ['https://www.googleapis.com/auth/drive'])
  49. service = build('drive', 'v3', credentials=creds)
  50.  
  51. # Create a file on Google Drive and upload the video to it
  52. file_metadata = {'name': 'no_metadata_video.mp4'}
  53. media = MediaFileUpload('no_metadata_video.mp4', resumable=True)
  54. file = service.files().create(body=file_metadata, media_body=media, fields='id').execute()
  55.  
  56. # Send a message to the Discord channel with the link to the uploaded video
  57. 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")}')
  58. except HttpError as error:
  59. print(f'An error occurred: {error}')
  60. await message.channel.send('There was an error uploading the video to Google Drive.')
  61.  
  62. # Run the Discord bot
  63. client.run('mytoken')
Advertisement
Add Comment
Please, Sign In to add comment