Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

I/O Error during YouTube playback #10

Closed
Its-treason opened this issue Jun 25, 2023 · 4 comments
Closed

I/O Error during YouTube playback #10

Its-treason opened this issue Jun 25, 2023 · 4 comments

Comments

@Its-treason
Copy link

Since some days, an IO Error occurs while playing songs from YouTube.

/app # node test.js 
[Error: I/O error]

Test script:

const { Client, GatewayIntentBits } = require('discord.js');
const { TrackPlayer, VoiceConnection, Source } = require('yasha');

(async () => {
  const client = new Client({
      intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildVoiceStates,
        GatewayIntentBits.GuildModeration,
        GatewayIntentBits.GuildMembers,
      ],
  });
  await client.login('DISCORD_BOT_TOKEN');

  const channel = await client.channels.fetch('VOICE_CHANNEL_ID');

  var player = new TrackPlayer();
  player.on("error", console.error);
  var track = await Source.resolve('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  var connection = await VoiceConnection.connect(channel);

  var subscription = connection.subscribe(player);

  player.play(track);
  player.start();
})()

I'm testing this on WSL2 with Debian unstable inside a Docker container, this worked fine for several months. This is my Dockerfile:

FROM alpine:3.18 AS protoc-js

WORKDIR /tmp

RUN echo "@edge-testing https://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
 && apk add --no-cache \
    bazel5@edge-testing \
    build-base \
    git \
 && git clone --branch v3.21.2 https://github.com/protocolbuffers/protobuf-javascript \
 && cd protobuf-javascript \
 && bazel build plugin_files \
 && install -o root -g root -m 0755 bazel-bin/generator/protoc-gen-js -t /tmp


FROM node:20.3-alpine AS base

RUN mkdir /app
WORKDIR /app

################################################################################
FROM base AS development

COPY --from=protoc-js /tmp/protoc-gen-js /usr/local/bin

ENV PYTHONUNBUFFERED=1
RUN apk add --no-cache --virtual .build-deps pango-dev jpeg-dev build-base cairo-dev giflib-dev python3 libsodium-dev libtool cmake g++ gcc ffmpeg-dev make git autoconf automake opus-dev libuv-dev protoc msttcorefonts-installer \
 && ln -sf python3 /usr/bin/python \
 && python3 -m ensurepip \
 && pip3 install --no-cache --upgrade pip setuptools

USER node

Log with strace: https://pastebin.com/szVcRfaF

@davidzeng0
Copy link
Owner

davidzeng0 commented Jun 25, 2023

YouTube revokes streaming urls on ANDROID clients if they detect significant backpressure. You can alleviate this pressure by using a different client, e.g. WEB (but you will have to decode signatures), or IOS (but you lose webm+opus). If that doesn't work, you can proxy https://*.googlevideo.com/* requests through your own proxy that breaks up the file into 160kB segments to prevent backpressure.

I'm not sure what changes happened in FFmpeg but rather than reporting 403 Forbidden as an error, they now return I/O error (maybe try downgrading to FFmpeg 4.x?). The behavior upon 403 is to re-fetch another set of streaming urls and re-start playback but that doesn't happen with I/O error. Even if that were fixed, you'd notice 2-3 interruptions on average for a 3 minute track.

@davidzeng0
Copy link
Owner

If your bot does not serve a large number of users, my best solution for you is to simply change
"ANDROID" to "IOS" @ https://github.com/davidzeng0/yasha/blob/master/src/api/Youtube.js#L285

@Its-treason
Copy link
Author

Changing ANDROID to IOS solved my issue, thank you!

@davidzeng0
Copy link
Owner

Fixed by #12

@davidzeng0 davidzeng0 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 4, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants