diff --git a/General.py b/General.py index db5f48e..ff571da 100644 --- a/General.py +++ b/General.py @@ -6,6 +6,8 @@ import random import re from discord.ext import commands from sympy import latex, symbols, preview, Symbol #for LaTeX images +import youtube_dl +import ffmpeg class General(object): """Overal toegestaan.""" @@ -74,6 +76,41 @@ class General(object): except: print("No permission to delete message") yield from ctx.channel.send(ctx.author.mention + ' ' + post.url) + + @commands.command(pass_context=True) + @asyncio.coroutine + def gif(self, ctx, yt: str, start: str, duration: str, res: str, fps: int): + """ Giffify. + Syntax: !gif [YT] [START] [DUUR] [RESOLUTIE] [FPS] + Bv: !gif RPxvTd_jCPQ 00:02:39 13 320 10 + """ + if (duration > 20) + yield from ctx.channel.send(ctx.author.mention + ' Au, stop. Dat is te lang.') + try: + yield from ctx.message.delete() + except: + print("No permission to delete message") + ydl_opts = { + 'outtmpl': 'temp', + 'format': 'bestvideo[ext=mp4]/mp4' + } + with youtube_dl.YoutubeDL(ydl_opts) as ydl: + ydl.download([yt]) + split = ffmpeg.input('temp').trim(start=start, duration=duration).filter_('fps',fps=fps).filter_('scale', w=res, h=-1).filter_multi_output('split') + pal = split.stream(0).filter_('palettegen') + inputs = { + 'v1':split.stream(1), + 'v2':pal + } + gif = ( + ffmpeg + .filter(stream_spec=[split.stream(1), pal], filter_name='paletteuse') + .output('out.gif') + .overwrite_output() + .run() + ) + os.remove('temp') + yield from ctx.channel.send(ctx.author.mention + ' hoi ', file=discord.File('out.gif')) @commands.command(pass_context=True, hidden=True) @asyncio.coroutine diff --git a/README.md b/README.md index 9a28dc2..1391686 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,6 @@ Verder zoek je het maar lekker zelf uit. Of installeer deze requirements: * `oauth2` * `sympy` * `asyncio` -* `numpy` \ No newline at end of file +* `numpy` +* `youtube_dl` +* `ffmpeg-python` \ No newline at end of file