Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snap package #3010

Closed
1 task done
arashpayan opened this issue Jun 5, 2020 · 17 comments · Fixed by #3611
Closed
1 task done

Snap package #3010

arashpayan opened this issue Jun 5, 2020 · 17 comments · Fixed by #3611

Comments

@arashpayan
Copy link

arashpayan commented Jun 5, 2020

Feature Request

  • This is a feature request and I have read the contribution guidelines.

Description

Hi there. I couldn't an existing feature request for this, so I'd like to suggest a 'Snap' (https://snapcraft.io/) package of streamlink. If a Snap package existed, Linux users could install streamlink on their computer with a simple command:

sudo snap install streamlink

Or through the snap GUI of their distro. Users would get the benefit of an easy installation that always stays up-to-date. The current package maintainers would experience less work, because this single snap package would work across all distributions.

Thanks for your consideration and this excellent app! 😄

Expected / Actual behavior

Linux users would be able to install streamlink from the command line by typing

sudo snap install streamlink

Additional comments, screenshots, etc.

Instructions for creating a snap of a python application:
https://snapcraft.io/#python

@patterns
Copy link

Hello, I'm interested in helping on a snap package. I made a trial run to check and the Snapcraft auto-build pipeline seems to have mature support for Python projects. If I can help, there is one shortcoming in that I don't have a rich test/QA environment. I have one Raspi Ubuntu server for my snaps so I would need others' help to verify the snap output across the different targets (amd64, i386, ppc64, etc).

@back-to
Copy link
Collaborator

back-to commented Jun 21, 2020

snaps are pretty annoying in terms of file permissions,
with your snap example it is the same I can't open my player.

error: Failed to start player: /usr/bin/mpv ([Errno 2] No such file or directory: '/usr/bin/mpv': '/usr/bin/mpv')
error: Failed to start player: mpv ([Errno 2] No such file or directory: 'mpv': 'mpv')

@johnthecracker
Copy link

johnthecracker commented Jun 21, 2020

@back-to,

Tell me how did you install your mpv (with snap or without snap)
I want to give it a shot.

Here is how I installed my mpv on ubuntu 20.04:

sudo add-apt-repository ppa:mc3man/mpv-tests
sudo apt-get update
sudo apt install -y mpv

j@j:~$ mpv
mpv git-2020-04-17-a09c769 Copyright © 2000-2020 mpv/MPlayer/mplayer2 projects
 built on Sun Apr 19 20:30:24 UTC 2020

VLC is default streamlink's player.

This is how it looks like with ubuntu:

https://www.videolan.org/vlc/download-ubuntu.html

sudo snap install vlc

If you wish to install the traditional deb package, it is available as usual via APT, 
with all security and critical bug fixes. However, 
there will be no major VLC version updates until the next Ubuntu release. 

It is version 3.0.9.2 forever with apt, version 3.0.11 today with snap.

j@j:~$ vlc
VLC media player 3.0.11 Vetinari (revision 3.0.11-0-gdc0c5ced72)

@johnthecracker
Copy link

If you install chromium on ubuntu with apt, snap appears to be unavoidable.
Apt installs chromium from snap.
That chromium works flawlessly.

sudo apt autoremove
sudo apt update
sudo apt install chromium-browser
/home/j/snap/chromium/1193/.config/chromium/Default

@back-to
Copy link
Collaborator

back-to commented Jun 22, 2020

@johnthecracker

streamlink with snap https://snapcraft.io/test-streamlink
the command will be test-streamlink

but it can't open mpv from apt installed

@johnthecracker
Copy link

johnthecracker commented Jun 22, 2020

https://snapcraft.io/install/test-streamlink/ubuntu

sudo snap install test-streamlink --edge

There is more than one problem with this test-streamlink.

url=https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
test-streamlink --player=ffplay "$url" 480p
j@j:~/LINUX/news$ ./sky.sh
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
[cli][info] Available streams: 144p (worst), 240p, 360p, 480p, 720p, 1080p (best)
[cli][info] Opening stream: 480p (hls)
[cli][info] Starting player: ffplay
error: Failed to start player: ffplay ([Errno 2] No such file or directory: 'ffplay': 'ffplay')
[cli][info] Closing currently open stream...

ffplay is installed and working, it commes installed by default on ubuntu.

url=https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
test-streamlink "$url" 480p
j@j:~/LINUX/news$ ./sky.sh
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
[cli][info] Available streams: 144p (worst), 240p, 360p, 480p, 720p, 1080p (best)
[cli][info] Opening stream: 480p (hls)
error: The default player (VLC) does not seem to be installed. You must specify the path to a player executable with --player.
[cli][info] Closing currently open stream...

vlc is installed, by "snap".

url=https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
test-streamlink --player=/snap/bin/vlc "$url" 480p
j@j:~/LINUX/news$ ./sky.sh
[cli][info] Found matching plugin youtube for URL https://www.youtube.com/channel/UCoMdktPbSTixAyNGwb-UYkQ
[cli][info] Available streams: 144p (worst), 240p, 360p, 480p, 720p, 1080p (best)
[cli][info] Opening stream: 480p (hls)
[cli][info] Starting player: /snap/bin/vlc
error: Failed to start player: /snap/bin/vlc ([Errno 13] Permission denied: '/snap/bin/vlc')
[cli][info] Closing currently open stream...

They messed up so badly, I can't copy custom plugins to plugins directory as root ???

cp -v *.py /snap/test-streamlink/6/lib/python3.6/site-packages/streamlink/plugins/
root@j:/home/j/LINUX/setup/streamlink# ./plugins.sh
'generic.py' -> '/snap/test-streamlink/6/lib/python3.6/site-packages/streamlink/plugins/generic.py'
cp: cannot create regular file '/snap/test-streamlink/6/lib/python3.6/site-packages/streamlink/plugins/generic.py': Read-only file system

@arashpayan
Copy link
Author

@back-to, thank you for creating that test snap. I just did a couple tests on my system (Ubuntu 20.04, VLC installed via snap) and have the following to report:

Default Install
$ sudo snap install --edge test-streamlink
With this method of installation, streamlink was unable to open vlc on my system, even if I specified the path with --player /snap/bin/vlc

Install with classic confinement
$ sudo snap install --classic --edge test-streamlink
Same outcome as a default install.

Install with 'devmode' confinement
$ sudo snap install --devmode --edge test-streamlink
In this case, streamlink was able to successfully start VLC as long as I included --player /snap/bin/vlc.

Although, I attempted to install with classic confinement in my second test, I think the classic confinement also needs to be specified by the snap itself (I might be totally wrong about that but I can't find external confirmation one way or the other right now), or else the command line switch has no effect. If, after changing the snap confinement to classic, streamlink works with the player path manually being specified, then I think the only change required would be to update the streamlink code to detect if it's running in a snap and have it search /snap/bin/ for VLC or any other players it needs.

Thanks again for creating that snap @back-to. :-)

@back-to
Copy link
Collaborator

back-to commented Jun 23, 2020

@arashpayan

Thanks again for creating that snap

That is not min, it is from @patterns

@arashpayan
Copy link
Author

My mistake. Thank you, @patterns, for the work you put into that snap! 😄

@predr
Copy link

predr commented Jun 30, 2020

Snap in strict confinement does not see other installed binaries and can't start them. This is by design for security reasons. Classic confinement is for build tools and trusted developer teams so I wouldn't bet on being granted that. The only way to use streamlink in strict confinement is to pipe it to a media player.

test-streamlink <URL> best --stdout | <PLAYER> -

This works with vlc and mpv for Youtube but for Twitch I had to pipe it trough ffmpeg to work (no idea why).

test-streamlink <URL> best --stdout | ffmpeg -i pipe:0 -c copy -bsf:a aac_adtstoasc -f mp4 -movflags empty_moov+separate_moof+frag_keyframe pipe:1 | <PLAYER> -

Another way to snap it, is with a simple or stripped down media player and always use this player to play streams. Or even better, to include LiveProxy in snap running as a daemon.

@patterns
Copy link

patterns commented Jul 1, 2020

Thanks @predr I used your snapcraft.yaml to add LiveProxy. I also included the stage-packages list (from the ffmpeg yaml) to cover all the bases. If anyone has the snap and it refreshes, it will be necessary to assign the player:
sudo snap set test-streamlink player=ffplay
If the player setting is left empty, I have it print a explanation which may be annoying. It continues to call plain streamlink. So far, ffplay and vlc+LiveProxy seem to work; I tried the twitch.tv/rifftrax (and /hungry) channel as a quick test.

@predr
Copy link

predr commented Jul 1, 2020

@patterns Nice work! I like the configuration for LiveProxy. Consider restarting server in hook/configure to apply changes immediately so users don't have to do it manually.

snapctl restart test-streamlink.proxy

I also included the stage-packages list (from the ffmpeg yaml) to cover all the bases

In future releases try trimming it down to absolutely necessary stuff.

it will be necessary to assign the player

Never ask users to do something before it works. I tried it without setting player and it worked because hook/install sets it on snap install.

I tried it with player=mpv and it failed to start because -window_title is option for ffplay not mpv.

Error parsing option window_title (option not found)
Setting commandline option --window_title= failed.

But why include mpv and setting for player anyway? Users can pipe if they need another player or use LiveProxy. I would display a message if user tries to use --player argument explaining how to pipe it to another player and how to use LiveProxy. Also it might be confusing for users when they set player=mpv they might think it will use their local mpv installation.

@patterns
Copy link

patterns commented Jul 2, 2020

Great points. Added the proxy restart to the configure hook. Removed mpv. It was to learn about the two (ffplay and mpv) because I didn't know about them until this ticket. Also made it print message when --player is an argument; it is when the snap setting for player is empty.
Trimming down the packages is definitely a task. I just have my Raspi for snaps and I'm not confident what/if dependencies work across platforms.

@predr
Copy link

predr commented Jul 2, 2020

Well I think it's good enough for first stable release under proper name. Search and ask in the snapcraft forum, someone should know what is bare minimum for hardware accelerated video encoding/decoding. Use prime to remove unnecessary files.

prime: # 7,4 MB just in these 2
  - -/usr/share/man
  - -/usr/share/doc

Also you can limit build system architectures in snapcraft.yml and exclude i386 and servers.

architectures: 
  - build-on: amd64
  - build-on: arm64

@arashpayan
Copy link
Author

@predr and @patterns, it seems that if streamlink won't get permission to install in classic confinement, maybe my request for snap packaging of streamlink wasn't a good idea? Might it be worth considering an AppImage package instead? That way no changes need to be made to streamlink and no extra packages (LiveProxy, ffplay, etc.) would need to be added to it. Thoughts?

@predr
Copy link

predr commented Jul 4, 2020

if streamlink won't get permission to install in classic confinement, maybe my request for snap packaging of streamlink wasn't a good idea?

It shouldn't get classic confinement! Classic is for system packages and developer tools, stuff you can trust. Strict is for everything else and especially for apps you don't trust 100% but still want to use. Confinement (isolation from system) is a feature not a bug.

Might it be worth considering an AppImage package

Yes, there should be other packages. Each package has trade-offs and everyone has different values.

changes need to be made to streamlink and no extra packages (LiveProxy, ffplay, etc.)

ffplay is part of ffmpeg which is needed for Twitch to work (I guess streamlink is doing some processing there) so why not use it as default --player when not piping output to player. I suggested including LiveProxy because with playlists it makes streamlink more usable, its not necessary for snap to work. You can make "vanila" snap but it's not going to be very user friendly.

Here is example playlist.m3u to try it. LiveProxy is started automatically.

#EXTM3U

#EXTINF:-1, Level1Tech
http://127.0.0.1:53422/play/?twitch-disable-hosting=true&default-stream=best&url=twitch.tv/teampgp

#EXTINF:-1, Chilled Cow
http://127.0.0.1:53422/play/?default-stream=480p&url=youtube.com/channel/UCSJ4gkVC6NrvII8umztf0Ow

@patterns
Copy link

patterns commented Jul 4, 2020

With some advice on snapcraft forum, the ffplay dependencies list are now down to 13. Also included the filtering of the man pages and docs files. I didn't have much luck with the architectures, yet. A config file, streamlinkrc, is editable so that the user has more control because $SNAP_DATA (/var/snap/test-streamlink/current) can be accessed by root. I think it can choose the location of plugins (commented example in file).

AppImage sounds interesting, but I haven't built one before. The confinement feels like a hurdle at times, but that trade-off is to add protection. Like in a landscape where user does not know the app, the trust just needs to be in Snapcraft store and the Snap virtualization/container.

@back-to back-to linked a pull request Mar 13, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants