mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[Audio] Support for YouTube URLs with timestamp (#919)
This commit is contained in:
parent
78173bd68c
commit
fc32524d16
@ -18,6 +18,7 @@ import math
|
||||
import time
|
||||
import inspect
|
||||
import subprocess
|
||||
import urllib.parse
|
||||
from enum import Enum
|
||||
|
||||
__author__ = "tekulvw"
|
||||
@ -145,6 +146,8 @@ class Song:
|
||||
self.url = kwargs.pop('url', None)
|
||||
self.webpage_url = kwargs.pop('webpage_url', "")
|
||||
self.duration = kwargs.pop('duration', 60)
|
||||
self.start_time = kwargs.pop('start_time', None)
|
||||
self.end_time = kwargs.pop('end_time', None)
|
||||
|
||||
class QueuedSong:
|
||||
def __init__(self, url, channel):
|
||||
@ -396,7 +399,7 @@ class Audio:
|
||||
self.queue[server.id][QueueKey.QUEUE] = deque()
|
||||
self.queue[server.id][QueueKey.TEMP_QUEUE] = deque()
|
||||
|
||||
async def _create_ffmpeg_player(self, server, filename, local=False):
|
||||
async def _create_ffmpeg_player(self, server, filename, local=False, start_time=None, end_time=None):
|
||||
"""This function will guarantee we have a valid voice client,
|
||||
even if one doesn't exist previously."""
|
||||
voice_channel_id = self.queue[server.id][QueueKey.VOICE_CHANNEL_ID]
|
||||
@ -429,6 +432,12 @@ class Audio:
|
||||
|
||||
use_avconv = self.settings["AVCONV"]
|
||||
options = '-b:a 64k -bufsize 64k'
|
||||
before_options = ''
|
||||
|
||||
if start_time:
|
||||
before_options += '-ss {}'.format(start_time)
|
||||
if end_time:
|
||||
options += ' -to {} -copyts'.format(end_time)
|
||||
|
||||
try:
|
||||
voice_client.audio_player.process.kill()
|
||||
@ -441,7 +450,7 @@ class Audio:
|
||||
log.debug("making player on sid {}".format(server.id))
|
||||
|
||||
voice_client.audio_player = voice_client.create_ffmpeg_player(
|
||||
song_filename, use_avconv=use_avconv, options=options)
|
||||
song_filename, use_avconv=use_avconv, options=options, before_options=before_options)
|
||||
|
||||
# Set initial volume
|
||||
vol = self.get_server_settings(server)['VOLUME'] / 100
|
||||
@ -884,7 +893,9 @@ class Audio:
|
||||
raise
|
||||
|
||||
voice_client = await self._create_ffmpeg_player(server, song.id,
|
||||
local=local)
|
||||
local=local,
|
||||
start_time=song.start_time,
|
||||
end_time=song.end_time)
|
||||
# That ^ creates the audio_player property
|
||||
|
||||
voice_client.audio_player.start()
|
||||
@ -1466,7 +1477,11 @@ class Audio:
|
||||
url = "[SEARCH:]" + url
|
||||
|
||||
if "[SEARCH:]" not in url and "youtube" in url:
|
||||
url = url.split("&")[0] # Temp fix for the &list issue
|
||||
parsed_url = urllib.parse.urlparse(url)
|
||||
query = urllib.parse.parse_qs(parsed_url.query)
|
||||
query.pop("list", None)
|
||||
parsed_url = parsed_url._replace(query=urllib.parse.urlencode(query, True))
|
||||
url = urllib.parse.urlunparse(parsed_url)
|
||||
|
||||
self._stop_player(server)
|
||||
self._clear_queue(server)
|
||||
@ -1741,7 +1756,11 @@ class Audio:
|
||||
url = "[SEARCH:]" + url
|
||||
|
||||
if "[SEARCH:]" not in url and "youtube" in url:
|
||||
url = url.split("&")[0] # Temp fix for the &list issue
|
||||
parsed_url = urllib.parse.urlparse(url)
|
||||
query = urllib.parse.parse_qs(parsed_url.query)
|
||||
query.pop("list", None)
|
||||
parsed_url = parsed_url._replace(query=urllib.parse.urlencode(query, True))
|
||||
url = urllib.parse.urlunparse(parsed_url)
|
||||
|
||||
# We have a queue to modify
|
||||
if self.queue[server.id][QueueKey.PLAYLIST]:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user