Merge pull request #1 from Sartharon/fixYoutube

fix youtube
This commit was merged in pull request #1.
This commit is contained in:
SugoiDogo
2024-08-10 14:34:46 -07:00
committed by GitHub
5 changed files with 49 additions and 5 deletions
+6
View File
@@ -33,6 +33,12 @@ Run the bot with `docker run --rm jmusicbot`. To run it in the background, use `
A cross-platform Discord music bot with a clean interface, and that is easy to set up and run yourself!
# Fork additions/fixes
* Fix 403 error during loading of YouTube songs/videos
* ~~Add PAPISID and PSID token support allowing playback of age restricted videos (Consult the [documentation](https://github.com/Sartharon/MusicBot/blob/gh-pages/docs/youtube-age-restrictions.md) on how to get these tokens)~~
* Use Google account to play age restricted songs/videos (Consult [example config](https://github.com/Sartharon/MusicBot/blob/fixYoutube/src/main/resources/reference.conf) - Variables: YoutubeEmail/YoutubePassword)
* Update LavaPlayer to an actively maintained [fork](https://github.com/Walkyst/lavaplayer-fork)
[![Setup](http://i.imgur.com/VvXYp5j.png)](https://jmusicbot.com/setup)
## Features
+3 -3
View File
@@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<version>Snapshot</version>
<version>0.4.3</version>
<packaging>jar</packaging>
<repositories>
@@ -82,7 +82,7 @@
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.2</version>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
@@ -94,7 +94,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
@@ -41,7 +41,7 @@ public class BotConfig
private Path path = null;
private String token, prefix, altprefix, helpWord, playlistsFolder, logLevel,
successEmoji, warningEmoji, errorEmoji, loadingEmoji, searchingEmoji,
evalEngine;
evalEngine, YoutubeEmail, YoutubePwd;
private boolean stayInChannel, songInGame, npImages, updatealerts, useEval, dbots;
private long owner, maxSeconds, aloneTimeUntilStop;
private int maxYTPlaylistPages;
@@ -98,6 +98,8 @@ public class BotConfig
aliases = config.getConfig("aliases");
transforms = config.getConfig("transforms");
skipratio = config.getDouble("skipratio");
YoutubeEmail = config.getString("YoutubeEmail");
YoutubePwd = config.getString("YoutubePassword");
dbots = owner == 113156185389092864L;
// we may need to write a new config file
@@ -381,4 +383,14 @@ public class BotConfig
{
return transforms;
}
public String getYoutubeEmail()
{
return YoutubeEmail;
}
public String getYoutubePwd()
{
return YoutubePwd;
}
}
@@ -21,6 +21,7 @@ import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry;
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManagers;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeHttpContextFilter;
import com.sedmelluq.discord.lavaplayer.source.bandcamp.BandcampAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.beam.BeamAudioSourceManager;
import com.sedmelluq.discord.lavaplayer.source.getyarn.GetyarnAudioSourceManager;
@@ -31,6 +32,8 @@ import com.sedmelluq.discord.lavaplayer.source.twitch.TwitchStreamAudioSourceMan
import com.sedmelluq.discord.lavaplayer.source.vimeo.VimeoAudioSourceManager;
import dev.lavalink.youtube.YoutubeAudioSourceManager;
import net.dv8tion.jda.api.entities.Guild;
import com.sedmelluq.discord.lavaplayer.tools.io.HttpInterfaceManager;
import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAccessTokenTracker;
/**
*
@@ -51,6 +54,23 @@ public class PlayerManager extends DefaultAudioPlayerManager
YoutubeAudioSourceManager yt = new YoutubeAudioSourceManager(true);
yt.setPlaylistPageCount(bot.getConfig().getMaxYTPlaylistPages());
if (bot.getConfig().getYoutubeEmail() != null && bot.getConfig().getYoutubePwd() != null)
{
YoutubeHttpContextFilter youtubeHttpContextFilter = new YoutubeHttpContextFilter();
HttpInterfaceManager httpInterfaceManager = yt.getHttpInterfaceManager();
YoutubeAccessTokenTracker accessTokenTracker = new YoutubeAccessTokenTracker(httpInterfaceManager, bot.getConfig().getYoutubeEmail(), bot.getConfig().getYoutubePwd());
while (accessTokenTracker.getMasterToken() == null) {
//Busy waiting for the master token
}
while (accessTokenTracker.getAccessToken() == null) {
//Busy waiting for the access token
}
while (accessTokenTracker.getVisitorId() == null) {
//Busy waiting for the visitor token
}
youtubeHttpContextFilter.setTokenTracker(accessTokenTracker);
httpInterfaceManager.setHttpContextFilter(youtubeHttpContextFilter);
}
registerSourceManager(yt);
registerSourceManager(SoundCloudAudioSourceManager.createDefault());
@@ -92,4 +112,4 @@ public class PlayerManager extends DefaultAudioPlayerManager
handler = (AudioHandler) guild.getAudioManager().getSendingHandler();
return handler;
}
}
}
+6
View File
@@ -23,6 +23,12 @@ token = BOT_TOKEN_HERE
owner = 0 // OWNER ID
// A Youtube/Google account is required in order to play age restricted videos.
// Make sure to use app passwords if you are using multifactor authentication (MFA) for your google account
// You can create app passwords on https://myaccount.google.com/ under "Security" - "Signing in to Google" - "App passwords"
YoutubeEmail = "" // Google account email
YoutubePassword = "" // Google account password or app password (if MFA is activated)
// This sets the prefix for the bot
// The prefix is used to control the commands