Skip to content

Commit

Permalink
Added filter help and improved the gif command
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrasn committed Mar 17, 2021
1 parent eb1be99 commit ba55a83
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
16 changes: 8 additions & 8 deletions COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,17 @@ You can bookmark videos and load them in any server with g_man. Bookmark labels
<br>

# Utility
| Command | Format | Description | Examples |
| --- | --- | --- | --- |
| gif | `!gif` | Convert the video to a gif. | `!gif`|
| mp3 | `!mp3` | Convert the video to an mp3. | `!mp3`|
| swap | `!swap` | Swap the last two videos sent, simply by reposting the second to last video. | `!swap` |
| time<br>timestamp | `!time` | Draws a timestamp, useful for figuring out when to !extract. | `!time` |
| undo | `!undo` | Delete the last video sent. | `!undo` |
| Command | Format | Min/Max Values | Description | Examples |
| --- | --- | --- | --- | --- |
| gif | `!gif <fps>` | `1 to 24` | Convert the video to a gif. Default `<fps>` is 24, consider lowering this number or scaling the video down if the GIF gets cut off. | `!gif`<br><br>`!gif 12`|
| mp3 | `!mp3` | | Convert the video to an mp3. | `!mp3`|
| swap | `!swap` | | Swap the last two videos sent, simply by reposting the second to last video. | `!swap` |
| time<br>timestamp | `!time` | | Draws a timestamp, useful for figuring out when to !extract. | `!time` |
| undo | `!undo` | | Delete the last video sent. | `!undo` |

# Advanced
## !filter command
You can apply almost any filter from FFMPEG using the !filter command.<br>
EXPERIMENTAL: You can apply almost any filter from FFMPEG using the !filter command. At the moment, filters requiring two or more videos will not work.<br> You can get a link to all the filters in FFMPEG by typing `!filter help`.
* Format: `!filter <filter_name> <filter_args>`
* \<filter_args\> are formatted in this way: `arg1_name=arg1_value arg2_name=arg2_value ...`
* Examples:
Expand Down
5 changes: 5 additions & 0 deletions cogs/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,11 @@ async def filter(self, ctx, *, commands : str = ''):
for k,v in enumerate(commands):
commands[k] = shlex.split(v)

# Help command
if(commands[0][0] == 'help'):
await ctx.send("Filters: https://ffmpeg.org/ffmpeg-filters.html\nUtilities: https://ffmpeg.org/ffmpeg-utils.html")
return

# Remove invalid commands
commands_copy = commands
commands = []
Expand Down
11 changes: 8 additions & 3 deletions cogs/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
from discord.ext import commands
import video_creator
import database as db
import ffmpeg

class Utility(commands.Cog):
def __init__(self, bot):
self.bot = bot


async def _gif(self, ctx, vstream, astream, kwargs):
return (vstream, astream, {})
vstream = vstream.filter('fps', fps=fps).split()
palette = vstream[1].filter('palettegen')
vstream = ffmpeg.filter([vstream[0], palette], 'paletteuse')
return vstream, astream, {}
@commands.command()
async def gif(self, ctx):
await video_creator.apply_filters_and_send(ctx, self._gif, {'is_gif':True})
async def gif(self, ctx, fps : int = 24):
fps = max(1, min(gif, 24))
await video_creator.apply_filters_and_send(ctx, self._gif, {'is_gif':True, 'fps':fps})


async def _mp3(self, ctx, vstream, astream, kwargs):
Expand Down
2 changes: 1 addition & 1 deletion media_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import database as db

MAX_MEM_PER_CHANNEL = 8
yt_regex = (r'(https?://)?(www\.)?(youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?([^&=%\?]{11})')
yt_regex = (r'(https?://)?(www\.)?(m\.youtube|youtube|youtu|youtube-nocookie)\.(com|be)/(watch\?v=|embed/|v/|.+\?v=)?([^&=%\?]{11})')
discord_cdn_regex = (r'https://(cdn|media)\.discordapp\.(com|net)/attachments/.+\.(mp4|MP4|webm|WEBM|mov|MOV|mkv|MKV)')
twitter_regex = (r'(https?://)?(www\.)?(mobile\.)?twitter\.com/.+/status/[0-9]+(\?.+)?')

Expand Down

0 comments on commit ba55a83

Please sign in to comment.