mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.
GNU General Public License v3.0
8.09k stars 644 forks source link

Http client (web interface) #646

Open rocketinventor opened 7 years ago

rocketinventor commented 7 years ago

Hi, I am thinking about creating a HTTP (web) interface for MPSYT.

To do this, I plan on using Flask to create a web server (using python) and reimplenting the UI with Javascript/HTML/CSS. The client would then communicate with MPSYT via Ajax or web sockets.

As planned, the flow would look like this:

  1. Start server (I.e. mpsyt server)
  2. Web interface opens and checks for current state of player (current tracks, queue, etc.)
  3. User opens web interface and browses for videos and playlists
  4. Web client pushes new queue back to the server

The main benefits of this approach is that full functionality is maintained while playing tracks and that anyone on the network can control the player (at the same time).

Any thoughts on this? Any preference on which port number to use? Is there anyone that can assist me with the development of this (I am unfamiliar with the MPSYT code base).

Thanks!

tommysolsen commented 7 years ago

I'm pretty new to the code myself, but I got some grasp over it right now. While I've never touched Flask before, I'dd be willing to help out where I can.

itsikol commented 7 years ago

@rocketinventor Sounds great, should we do it using django? as i am good at django, i have no prior exposure to flask.

rocketinventor commented 7 years ago

I think Django has a little bit more overhead than we need (unless you think that we need user authentication, etc). Flask is simple and easy to learn.

Most of the work here will be in controlling mpsyt from another program. The main i/o code would be the same no matter which framework we use. I can write up some boiler plate code for Flask if that helps.

As far as the http server goes, all it needs to do is serve up the html and respond to a few API endpoints, right?

rocketinventor commented 7 years ago

@lokendras395 How familiar are you with the mpsyt base code?

itsikol commented 7 years ago

@rocketinventor i am very little familiar with mpsyt bascode, but i am familiar with python and django, and previously i have worked on django to create webview for controlling os functionality in storage machines, like mounting unmounting disks, creating zfs snaps, transfering snaps.

rocketinventor commented 7 years ago

@lokendras395 does Django have special functionality for that, or did you just use os.system / subsystem as normal?

The python bits should be the same no matter which framework is used. I can take care of the parts that are unique to Flask. As I said before, Django has a lot of boat that is good for some projects but not others. If you have something fancy on mind (Ie any type of login), we'll stick with Django - let me know

rocketinventor commented 7 years ago

Is there anyone who is familiar with the base code who can assist in modifying the code to support non-interactive commandline usage?

tommysolsen commented 7 years ago

It does already support a form of basic non interactive commandline usage, through comma separated commands as arguments, for examplempsyt "/searchterm, 1, q" to search, listen to first restult then quit.

Or are you thinking of some other form of commandline usage?

rocketinventor commented 7 years ago

@Razesdark not really. I was hoping for a method that returns something that I can parse easily. The method you described just returns the ascii from the exit screen and no method to get player state. There is no way to get playlist or config info. Also, mpsyt "url https://youtu.be/iS5WZoQGP4I, q" just exits.

ids1024 commented 7 years ago

I was hoping for a method that returns something that I can parse easily.

There is no such thing currently. Mpsyt is designed for interactive use; it supports the mpris2 API, but that will only allow retrieving metadata of the current track and playing/pausing.

Ideally mpsyt would have a plugin API to support implementing things like this, but but that never got finished (https://github.com/mps-youtube/mps-youtube/pull/316). Plugin loading of sorts works with that branch, but getting it to work in a sane way was blocked by designing and implementing a good content API (https://github.com/mps-youtube/mps-youtube/pull/423).

If that work was completed (refactoring much of mpsyt) things like this could be done by a plugin that provides a backend replacing the cli backend.

I don't think I can really help with the coding itself at present, but if you have questions about the code, feel free to ask; probably on the #mps-youtube Freenode channel.

rocketinventor commented 7 years ago

@ids1024 Can you provide some more details on using the mpris2 api? I had trouble getting it to work on my device. Any chance of accessing the que that way, also? That would help a lot.

Besides from those two things, I just need access to the config info (including api key) and saved playlist - everything else can be done client side.

Thanks!

ids1024 commented 7 years ago

Mpsyt's mpris2 support requires dbus-python and pygobject. I've used it with the playerctl program; you should also be able to find python libraries.

Mpris 2 seems to have APIs for playlists and the tracklist: https://specifications.freedesktop.org/mpris-spec/latest/Track_List_Interface.html, https://specifications.freedesktop.org/mpris-spec/latest/Playlists_Interface.html

But those APIs are not currently implemented by mpsyt. mpris.py has the code for the current mpris2 support.

It may not be ideal, but you should be able to read configuration and playlists from their files directly. See my first comment on #112 for a code snippet to read the playlists.

rocketinventor commented 7 years ago

Retrieving the playlists from the config file is okay, I think.

How much work would it be to implement those API's internally?

ids1024 commented 7 years ago

I haven't really looking into implementing that part of mpris2 yet. Probably not too hard... the mpris2 thread would have to trigger the main thread playing (perhaps sending a signal).;

andraantariksa commented 4 years ago

Sorry for bumping up. What is the current state of this issue?

tommysolsen commented 4 years ago

I dont think there has been any serious effort to make a MPSYT web interface. However there is a youtube web interface project that is much more active than this called invidious.

https://www.invidio.us/