Skip to content

Commit 48a39a7

Browse files
committed
implement cookie check, use browser NPM package for auto install instead of a manual command, fix Docker & add notice about macOS recommendation
1 parent 72bdbe0 commit 48a39a7

8 files changed

+79
-39
lines changed

.env.example

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# For more information, please see the README.md
22
SUNO_COOKIE=
33
TWOCAPTCHA_KEY= # Obtain from 2captcha.com
4-
BROWSER=chromium # chromium or firefox, although chromium is highly recommended
4+
BROWSER=chromium # `chromium` or `firefox`, although `chromium` is highly recommended
55
BROWSER_GHOST_CURSOR=false
66
BROWSER_LOCALE=en
77
BROWSER_HEADLESS=true

Dockerfile

+30-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
1-
# syntax=docker/dockerfile:1
2-
3-
FROM node:lts-alpine AS builder
4-
WORKDIR /src
5-
COPY package*.json ./
6-
RUN npm install
7-
COPY . .
8-
RUN npm run build
9-
10-
FROM node:lts-alpine
11-
WORKDIR /app
12-
COPY package*.json ./
13-
14-
ARG SUNO_COOKIE
15-
ARG BROWSER
16-
RUN if [ -z "$SUNO_COOKIE" ]; then echo "Warning: SUNO_COOKIE is not set"; fi
1+
# syntax=docker/dockerfile:1
2+
3+
FROM node:lts-bookworm AS builder
4+
WORKDIR /src
5+
COPY package*.json ./
6+
RUN npm install
7+
COPY . .
8+
RUN npm run build
9+
10+
FROM node:lts-bookworm
11+
WORKDIR /app
12+
COPY package*.json ./
13+
14+
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y libnss3 \
15+
libdbus-1-3 libatk1.0-0 libatk-bridge2.0-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 \
16+
libgbm1 libxkbcommon0 libasound2 libcups2 xvfb
17+
18+
ARG SUNO_COOKIE
19+
RUN if [ -z "$SUNO_COOKIE" ]; then echo "Warning: SUNO_COOKIE is not set. You will have to set the cookies in the Cookie header of your requests."; fi
1720
ENV SUNO_COOKIE=${SUNO_COOKIE}
18-
RUN if [ -z "$BROWSER" ]; then echo "Warning: BROWSER is not set; will use chromium by default"; fi
19-
ENV BROWSER=${BROWSER:-chromium}
21+
# Disable GPU acceleration, as with it suno-api won't work in a Docker environment
22+
ENV BROWSER_DISABLE_GPU=true
2023

21-
RUN npm install --only=production
22-
RUN npx playwright install $BROWSER
23-
COPY --from=builder /src/.next ./.next
24-
EXPOSE 3000
25-
CMD ["npm", "run", "start"]
24+
RUN npm install --only=production
25+
26+
# Install all supported browsers, else switching browsers requires an image rebuild
27+
RUN npx playwright install chromium
28+
# RUN npx playwright install firefox
29+
30+
COPY --from=builder /src/.next ./.next
31+
EXPOSE 3000
32+
CMD ["npm", "run", "start"]

README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ We have deployed an example bound to a free Suno account, so it has daily usage
6464

6565
[Create](https://2captcha.com/auth/register?userType=customer) a new 2Captcha account, [top up](https://2captcha.com/pay) your balance and [get your API key](https://2captcha.com/enterpage#recognition).
6666

67-
If you are located in Russia or Belarus, use the [ruCaptcha](https://rucaptcha.com) interface instead of 2Captcha. It's the same service, but it supports payments from those countries.
67+
> [!NOTE]
68+
> If you are located in Russia or Belarus, use the [ruCaptcha](https://rucaptcha.com) interface instead of 2Captcha. It's the same service, but it supports payments from those countries.
69+
70+
> [!TIP]
71+
> If you want as few CAPTCHAs as possible, it is recommended to use a macOS system. macOS systems usually get fewer CAPTCHAs than Linux and Windows—this is due to its unpopularity in the web scraping industry. Running suno-api on Windows and Linux will work, but in some cases, you could get a pretty large number of CAPTCHAs.
6872
6973
### 3. Clone and deploy this project
7074

@@ -80,9 +84,11 @@ You can choose your preferred deployment method:
8084
git clone https://github.com/gcui-art/suno-api.git
8185
cd suno-api
8286
npm install
83-
npx playwright install chromium
8487
```
8588
#### Docker
89+
>[!IMPORTANT]
90+
> GPU acceleration will be disabled in Docker. If you have a slow CPU, it is recommended to [deploy locally](#run-locally).
91+
8692
Alternatively, you can use [Docker Compose](https://docs.docker.com/compose/). However, follow the step below before running.
8793

8894
```bash

README_RU.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ Suno — потрясающий сервис для ИИ-музыки. Несм
6464

6565
[Создайте](https://2captcha.com/ru/auth/register?userType=customer) новый аккаунт, [пополните](https://2captcha.com/ru/pay) баланс и [получите свой API-ключ](https://2captcha.com/ru/enterpage#recognition).
6666

67-
ℹ Если вы находитесь в России или Беларуси, используйте интерфейс [ruCaptcha](https://rucaptcha.com) вместо 2Captcha. Это абсолютно тот же сервис, но данный интерфейс поддерживает платежи из этих стран.
67+
> [!NOTE]
68+
> Если вы находитесь в России или Беларуси, используйте интерфейс [ruCaptcha](https://rucaptcha.com) вместо 2Captcha. Это абсолютно тот же сервис, но данный интерфейс поддерживает платежи из этих стран.
69+
70+
> [!TIP]
71+
> Если вы хотите получать как можно меньше капч, рекомендуется использовать macOS. Системы на macOS обычно получают меньше капч, чем Linux и Windows — это связано с их непопулярностью в сфере веб-скрейпинга. Запуск suno-api на Windows и Linux будет работать, но в некоторых случаях вы можете получить довольно большое количество капч.
6872
6973
### 3. Скачайте и запустите проект
7074

@@ -80,9 +84,10 @@ Suno — потрясающий сервис для ИИ-музыки. Несм
8084
git clone https://github.com/gcui-art/suno-api.git
8185
cd suno-api
8286
npm install
83-
npx playwright install chromium
8487
```
8588
#### Docker
89+
>[!IMPORTANT]
90+
> Аппаратное видеоускорение браузера будет отключено в Docker. Если у вас медленный процессор, рекомендуется [развернуть локально](#локально).
8691
Также можно использовать [Docker Compose](https://docs.docker.com/compose/), однако перед запуском выполните шаг ниже.
8792

8893
```bash

docker-compose.yml

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ services:
1010
- ./public:/app/public
1111
ports:
1212
- "3000:3000"
13+
env_file: ".env"

package-lock.json

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"dependencies": {
1818
"@2captcha/captcha-solver": "^1.3.0",
19+
"@playwright/browser-chromium": "^1.49.1",
1920
"@vercel/analytics": "^1.2.2",
2021
"axios": "^1.7.8",
2122
"bufferutil": "^4.0.8",

src/lib/SunoApi.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -230,17 +230,23 @@ class SunoApi {
230230
* @returns {BrowserContext}
231231
*/
232232
private async launchBrowser(): Promise<BrowserContext> {
233+
const args = [
234+
'--disable-blink-features=AutomationControlled',
235+
'--disable-web-security',
236+
'--no-sandbox',
237+
'--disable-dev-shm-usage',
238+
'--disable-features=site-per-process',
239+
'--disable-features=IsolateOrigins',
240+
'--disable-extensions',
241+
'--disable-infobars'
242+
];
243+
// Check for GPU acceleration, as it is recommended to turn it off for Docker
244+
if (yn(process.env.BROWSER_DISABLE_GPU, { default: false }))
245+
args.push('--enable-unsafe-swiftshader',
246+
'--disable-gpu',
247+
'--disable-setuid-sandbox');
233248
const browser = await this.getBrowserType().launch({
234-
args: [
235-
'--disable-blink-features=AutomationControlled',
236-
'--disable-web-security',
237-
'--no-sandbox',
238-
'--disable-dev-shm-usage',
239-
'--disable-features=site-per-process',
240-
'--disable-features=IsolateOrigins',
241-
'--disable-extensions',
242-
'--disable-infobars'
243-
],
249+
args,
244250
headless: yn(process.env.BROWSER_HEADLESS, { default: true })
245251
});
246252
const context = await browser.newContext({ userAgent: this.userAgent, locale: process.env.BROWSER_LOCALE, viewport: null });
@@ -798,7 +804,7 @@ class SunoApi {
798804
}
799805

800806
export const sunoApi = async (cookie?: string) => {
801-
const resolvedCookie = cookie || process.env.SUNO_COOKIE;
807+
const resolvedCookie = cookie && cookie.includes('__client') ? cookie : process.env.SUNO_COOKIE; // Check for bad `Cookie` header (It's too expensive to actually parse the cookies *here*)
802808
if (!resolvedCookie) {
803809
logger.info('No cookie provided! Aborting...\nPlease provide a cookie either in the .env file or in the Cookie header of your request.')
804810
throw new Error('Please provide a cookie either in the .env file or in the Cookie header of your request.');

0 commit comments

Comments
 (0)