Skip to content

Commit

Permalink
fix: unable to play music (#168)
Browse files Browse the repository at this point in the history
* feat(poToken_generator.py): Added a script to generate poToken and updated requirements.txt.

* fix(application.yml): Added poToken configuration option.

* docs(README.md): Added poToken generation tutorial and Pterodactyl egg setup instructions.

* refactor(poToken_generator.py): resolve check

* docs(Readme.md): A more detailed description of the tutorial on generating poToken and added Support group invite link.

* Update(player.png, player-en.png): new UI
  • Loading branch information
Mantouisyummy authored Aug 25, 2024
1 parent 6e46dfa commit 2107681
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 73 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
<br />
<a href="https://discord.gg/acgmcity">試用</a>
·
<a href="https://discord.com/invite/3y7mN82NQa">支援群組</a>
·
<a href="https://github.com/Nat1anWasTaken/Lava/issues">回報問題</a>
·
<a href="https://github.com/Nat1anWasTaken/Lava/issues">請求功能</a>
Expand Down Expand Up @@ -78,6 +80,11 @@

你可以透過 [LavaLauncher][LavaLauncher] 這個一鍵式腳本,你可以在裡面按照教學一步一步創建 Lavalink 節點 和 Discord 機器人

### Pterodactyl (翼手龍)
為了方便使用,我們提供 Pterodactyl Egg 並整合了 Lavalink 來方便架設 Lava 機器人

你可以透過 [這裡](https://github.com/Mantouisyummy/Lava-egg/blob/main/egg-lava.json) 來下載Lava的Egg檔案並匯入.

### Docker

<details>
Expand Down Expand Up @@ -160,6 +167,31 @@ docker run -it \

<!-- CONFIGURATION -->

## Lavalink 配置
> [!WARNING]
> 由於 YouTube 的種種限制,必須填入一些驗證資訊才能使音樂服務正常工作,具體方式請詳閱下方教學。
首先,請先使用 `pip install -r requirements.txt` 安裝所有必要的套件
安裝完後進入到Lava的資料夾運行 `python poToken_generator.py`
運行後你會看到終端輸出以下內容:

```
visitor_data: your visitor_data
po_token: your po_token
```

打開 `configs/application.yml` 後找到以下配置資訊
```yml
plugins:
youtube:
pot:
token: "paste your po_token here"
visitorData: "paste your visitor_data here"
```
隨後將你獲得的 `po_token` 和 `visitor_data` 分別填入 `token` 和 `visitorData` 中即可完成配置

<p align="right">(<a href="#readme-top">回到頂部</a>)</p>

## 設定
Lava 提供了一些簡單的設定讓你能夠輕鬆地自定義你的音樂機器人,像是:

Expand Down
135 changes: 63 additions & 72 deletions configs/application.yml
Original file line number Diff line number Diff line change
@@ -1,74 +1,65 @@
server: # REST and WS server
port: 2333
address: 0.0.0.0
lavalink:
server:
password: "youshallnotpass"
sources:
youtube: false
bandcamp: true
soundcloud: true
twitch: true
vimeo: true
http: true
local: false
filters:
volume: true
equalizer: true
karaoke: true
timescale: true
tremolo: true
vibrato: true
distortion: true
rotation: true
channelMix: true
lowPass: true
bufferDurationMs: 400
frameBufferDurationMs: 5000
opusEncodingQuality: 10
resamplingQuality: HIGH
trackStuckThresholdMs: 10000
useSeekGhosting: true
youtubePlaylistLoadLimit: 6
playerUpdateInterval: 5
youtubeSearchEnabled: true
soundcloudSearchEnabled: true
gc-warnings: true
plugins:
- dependency: "dev.lavalink.youtube:youtube-plugin:1.5.2"
snapshot: false

plugins:
youtube:
enabled: true
allowSearch: true
allowDirectVideoIds: true
allowDirectPlaylistIds: true
clients: [ "MUSIC", "ANDROID", "WEB" ]

metrics:
prometheus:
enabled: false
endpoint: /metrics

plugins:
- dependency: dev.lavalink.youtube:youtube-plugin:1.7.2
snapshot: false
server:
bufferDurationMs: 400
filters:
channelMix: true
distortion: true
equalizer: true
karaoke: true
lowPass: true
rotation: true
timescale: true
tremolo: true
vibrato: true
volume: true
frameBufferDurationMs: 5000
gc-warnings: true
opusEncodingQuality: 10
password: youshallnotpass
playerUpdateInterval: 5
resamplingQuality: HIGH
soundcloudSearchEnabled: true
sources:
bandcamp: true
http: true
local: false
soundcloud: true
twitch: true
vimeo: true
youtube: false
trackStuckThresholdMs: 10000
useSeekGhosting: true
youtubePlaylistLoadLimit: 6
youtubeSearchEnabled: true
logging:
file:
path: ./logs/

level:
root: INFO
lavalink: INFO

request:
enabled: true
includeClientInfo: true
includeHeaders: false
includeQueryString: true
includePayload: true
maxPayloadLength: 10000


logback:
rollingpolicy:
max-file-size: 1GB
max-history: 30
file:
path: ./logs/
level:
lavalink: INFO
root: INFO
logback:
rollingpolicy:
max-file-size: 1GB
max-history: 30
request:
enabled: true
includeClientInfo: true
includeHeaders: false
includePayload: true
includeQueryString: true
maxPayloadLength: 10000
metrics:
prometheus:
enabled: false
endpoint: /metrics
plugins:
youtube:
pot:
token: "Paste your po_token here"
visitorData: "paste your visitor_data here"
server:
address: 0.0.0.0
port: 2333
Binary file modified img/player-en.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified img/player.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions poToken_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from nodriver import start, cdp, loop
import json
import sys


async def main(): # pylint: disable=W0613
browser = await start(headless=False)
print("[INFO] launching browser.")
tab = browser.main_tab
tab.add_handler(cdp.network.RequestWillBeSent, send_handler)
await browser.get('https://www.youtube.com/embed/jNQXAC9IVRw')
await tab.wait(cdp.network.RequestWillBeSent)
button_play = await tab.select("#movie_player")
await button_play.click()
await tab.wait(cdp.network.RequestWillBeSent)
print("[INFO] waiting additional 30 seconds for slower connections.")
await tab.sleep(30)


async def send_handler(event: cdp.network.RequestWillBeSent): # pylint: disable=W0613
if "/youtubei/v1/player" in event.request.url:
post_data = event.request.post_data
post_data_json = json.loads(post_data)
print("visitor_data: " + post_data_json["context"]["client"]["visitorData"])
print("po_token: " + post_data_json["serviceIntegrityDimensions"]["poToken"])
sys.exit(0)
return


if __name__ == '__main__':
loop().run_until_complete(main())
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ python-dotenv==1.0.1
yt-dlp==2024.7.9
aiohttp==3.9.5
imageio==2.35.0
syncedlyrics==1.0.0
pylrc==0.1.2
syncedlyrics==1.0.0
nodriver==0.32
undetected-chromedriver==3.5.5
colorlog
git+https://github.com/Nat1anWasTaken/Lavalink.py.git
git+https://github.com/Snipy7374/disnake-ext-paginator.git

0 comments on commit 2107681

Please sign in to comment.