xat / castnow

commandline chromecast player
MIT License
3.81k stars 243 forks source link

ERROR: unable to write data: [Errno 32] Broken pipe #243

Closed sebma closed 3 years ago

sebma commented 5 years ago

Hi,

I get this error when typing the youtube-dl ... | castnow --quiet - command taken from your ../README.md :

$ youtube-dl -o - https://www.youtube.com/watch?v=t01ATiON3wU | castnow --quiet -
[youtube] t01ATiON3wU: Downloading webpage
[youtube] t01ATiON3wU: Downloading video info webpage
[youtube] t01ATiON3wU: Downloading MPD manifest
[download] Resuming download at byte 145108
[download] Destination: -
Error: Load failed

ERROR: unable to write data: [Errno 32] Broken pipe

But, lucky me, I found a solution that works with Youtube videos (as of May 2019) with the --no-continue option of youtube-dl :

$ youtube-dl --no-continue -o - https://www.youtube.com/watch?v=t01ATiON3wU | castnow --quiet -
[youtube] t01ATiON3wU: Downloading webpage
[youtube] t01ATiON3wU: Downloading video info webpage
[youtube] t01ATiON3wU: Downloading MPD manifest
[download] Destination: -
[download]   2.3% of 416.40MiB at 921.05KiB/s ETA 07:32^C
ERROR: Interrupted by user
gigawatts commented 3 years ago

I'm having this same exact problem, but the proposed fix does not work either

# youtube-dl --no-continue --no-part -o - https://www.youtube.com/watch?v=BaW_jenozKc | castnow --quiet -
[youtube] BaW_jenozKc: Downloading webpage
[download] Destination: -
[download]   3.5% of 1.74MiB at  2.49MiB/s ETA 00:00
Error: Load failed
ERROR: unable to write data: [Errno 32] Broken pipe

that same youtube-dl command sent > to a file runs fine, outputs a MP4 file

sebma commented 3 years ago

@gigawatts I just tried your command and it worked fine :

$ youtube-dl --no-continue --no-part -o - https://www.youtube.com/watch?v=BaW_jenozKc | castnow --quiet -
[youtube] BaW_jenozKc: Downloading webpage
[download] Destination: -
[download] 100% of 354.29KiB in 00:03

Is your upload speed high enough ?

You can check that with the python speedtest-cli package.

gigawatts commented 3 years ago

@sebma I have a 1000/40 Mbps connection, but I'm not sure why you would think internet upload bandwidth would have anything to do with downloading a YouTube video and piping it within the LAN to a Chromecast.

If I cut off the above command at the pipe and redirect the youtube-dl standard out to a file (with -o - > local_file), it downloads the example video in less than a second and produces a proper MP4 file.

For what it's worth, I'm running this within a docker container that contains both programs, and each program works as expected independently, but not when used with a standard out/standard in pipe.

sebma commented 3 years ago

@gigawatts Oops, you're right. I meant the download speed. Anyway, speed does not seem to be the pb.

Can you try on a less secure environment such as a standard linux distribution ?

I'm not a nodejs developer but maybe setting castnow in debug mode can help investigate, I found this.

Your command would become :

$ youtube-dl --no-continue --no-part -o - https://www.youtube.com/watch?v=BaW_jenozKc | NODE_ENV=dev DEBUG=* castnow --quiet -

gigawatts commented 3 years ago

@sebma thank you for the tips! that debug output was what I needed to solve this.

I didn't realize castnow was opening up a port (default 4104/tcp) and informing the chromecast to connect to that port. Once I opened up that port in my docker container, everything worked.

Since I was in a container, I also had to use the --myip x.x.x.x to tell castnow which IP to report itself as using.

sebma commented 3 years ago

@gigawatts I'm glad I could help. I just found this documentation concerning the needed UDP and TCP ports :

https://github.com/xat/castnow/wiki#castnow-keeps-being-stuck-in-the-state-loading-or-scanning

I'm a container newbie, I'd like to know if it's possible to have a container with an IP address in the same LAN just like a bridged VM would in a Linux host environment ?

gigawatts commented 3 years ago

@sebma Here are all the docker networking options https://docs.docker.com/network/

I don't know if there is a way to give it its own IP on your normal LAN subnet, but it's not too difficult to pass specific ports through and make sure your host based firewall allows the traffic as well.

You could always setup a second virtual IP on your docker host and have a specific container bind to that VIP, with castnow that's done with the --myip x.x.x.x flag

sebma commented 3 years ago

@gigawatts Thanks for this doc. I found this.

One last question, one which distribution was your container based on to contain all the requirements for castnow and youtube-dl ?

gigawatts commented 3 years ago

@sebma its still a work in progress, but I wrote this Dockerfile and created my own image from it

$ cat Dockerfile
FROM node:current-buster-slim
RUN npm install castnow -g
RUN apt-get update && \
    apt-get install -y --force-yes ffmpeg curl python3 less && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/bin/python3 /usr/local/bin/python
RUN curl -L https://yt-dl.org/downloads/latest/youtube-dl -o /usr/local/bin/youtube-dl && \
    chmod a+rx /usr/local/bin/youtube-dl
CMD ["/bin/bash"]
$ docker build . -t castnow

For now, I am running it like this while testing:

$ docker run -it --rm --network=host castnow /bin/bash

then running this manually at the container's bash shell

youtube-dl --no-continue -o - https://www.youtube.com/watch?v=BaW_jenozKc | castnow --address x.x.x.x --myip y.y.y.y --quiet -
sebma commented 3 years ago

@gigawatts Thanks a lot for these informations.

Regarding this issue, there seemed to be be 2 possible reasons :

youtube-dl was resuming even when redirecting the stream to a pipe. youtube-dl solved it so the youtube-dl option --no-continue is not needed anymore.

A firewall issue solved by opening the following ports documented here : https://github.com/xat/castnow/wiki#castnow-keeps-being-stuck-in-the-state-loading-or-scanning

Closing this issue.