Based on JMusicBot by jagrosh (https://github.com/jagrosh/MusicBot), via the maintained fork by arif-banai (https://github.com/arif-banai/MusicBot). See NOTICE for attribution. Licensed under Apache 2.0. YouTube-side changes had broken playback entirely. Fixes: - Apply the remote signature cipher independently of OAuth. Deciphering and authentication are unrelated, but the cipher was only configured when OAuth was enabled, so the default install fell back to the bundled extractor and failed with "Must find sig function from script: /s/player/<id>/...". Now always applied, and configurable via playback.youtube.remoteCipher.url. - Add the ANDROID client and order the client list by reliability. ANDROID is currently the only client YouTube reliably streams to anonymously. WEB moves last, as YouTube answers it with SABR-only responses carrying no playable format ("No supported audio streams available, available types:"). - Detect sign-in failures across the whole exception graph. The existing hint could never fire: it matched the aggregate AllClientsFailedException message rather than the per-client reasons, and compared against an ASCII apostrophe while YouTube sends U+2019. - Track youtube-source past 1.18.2, which predates the TV client User-Agent fix and the contentLength recovery fix. Measured on previously failing tracks: 5/5 playing, stable across repeat runs (was 1/5). No OAuth required. Adds 17 tests; 676 unit + 48 integration pass.
64 lines
2.3 KiB
Java
64 lines
2.3 KiB
Java
/*
|
|
* Copyright 2018 John Grosh <[email protected]>.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
package com.jagrosh.jmusicbot.commands.v1;
|
|
|
|
import com.jagrosh.jdautilities.command.CommandEvent;
|
|
import com.jagrosh.jmusicbot.Bot;
|
|
import com.jagrosh.jmusicbot.settings.Settings;
|
|
import net.dv8tion.jda.api.Permission;
|
|
import net.dv8tion.jda.api.entities.Guild;
|
|
import net.dv8tion.jda.api.entities.Member;
|
|
import net.dv8tion.jda.api.entities.Role;
|
|
|
|
/**
|
|
*
|
|
* @author John Grosh ([email protected])
|
|
*/
|
|
public abstract class DJCommand extends MusicCommand
|
|
{
|
|
public DJCommand(Bot bot)
|
|
{
|
|
super(bot);
|
|
this.category = new Category("DJ", event -> checkDJPermission(event));
|
|
}
|
|
|
|
public static boolean checkDJPermission(CommandEvent event)
|
|
{
|
|
if(event.getAuthor().getId().equals(event.getClient().getOwnerId()))
|
|
return true;
|
|
if(event.getGuild()==null)
|
|
return true;
|
|
if(event.getMember().hasPermission(Permission.MANAGE_SERVER))
|
|
return true;
|
|
Settings settings = event.getClient().getSettingsFor(event.getGuild());
|
|
Role dj = settings.getRole(event.getGuild());
|
|
return dj!=null && (event.getMember().getRoles().contains(dj) || dj.getIdLong()==event.getGuild().getIdLong());
|
|
}
|
|
|
|
public static boolean checkDJPermission(Bot bot, Guild guild, Member member)
|
|
{
|
|
if(String.valueOf(bot.getConfig().getOwnerId()).equals(member.getUser().getId()))
|
|
return true;
|
|
if(guild==null)
|
|
return true;
|
|
if(member.hasPermission(Permission.MANAGE_SERVER))
|
|
return true;
|
|
Settings settings = bot.getSettingsManager().getSettings(guild);
|
|
Role dj = settings.getRole(guild);
|
|
return dj!=null && (member.getRoles().contains(dj) || dj.getIdLong()==guild.getIdLong());
|
|
}
|
|
}
|