Coder Social home page Coder Social logo

ondras / cyp Goto Github PK

View Code? Open in Web Editor NEW
94.0 5.0 20.0 904 KB

Control Your Player: a Web-based MPD client

License: MIT License

HTML 2.15% JavaScript 48.00% Makefile 0.67% Shell 0.53% Dockerfile 0.22% Less 6.67% TypeScript 41.76%
web-app custom-elements

cyp's Introduction

CYP: Control Your Player

CYP is a web-based frontend for MPD, the Music Player Daemon. You can use it to control the playback without having to install native application(s). It works in modern web browsers, both desktop and mobile.

Screenshots

Features

  • Control the playback, queue, volume
  • Save and load playlists
  • Browse the library by artists/albums/directories
  • Display album art via native MPD calls (no need to access the library; requires MPD >= 0.21)
  • Youtube-dl integration
  • Dark/Light themes

Installation

Make sure you have a working MPD setup first and Node version >= 10

git clone https://github.com/ondras/cyp.git && cd cyp
npm i
node .

Point your browser to http://localhost:8080 to open the interface. Specifying a custom MPD address can be done:

  1. using MPD_HOST and MPD_PORT environment variables, or
  2. via a server querystring argument (?server=localhost:6655).

Instalation - Docker

Alternatively, you can use Docker to run CYP.

git clone https://github.com/ondras/cyp.git && cd cyp
docker build -t cyp .
docker run --network=host cyp

Installation - Apache ProxyPass

If you want to run CYP as a service and proxy it through Apache2, you will need to enable several modules.

# a2enmod proxy
# a2enmod proxy_http
# a2enmod proxy_wstunnel
# a2enmod proxypass

To present CYP in a virutal folder named "music" (https://example.com/music/) add the following to your site config.

# MPD daemon
RewriteEngine on						# Enable the RewriteEngine
RewriteCond %{REQUEST_FILENAME} !-f		# If the requested file isn't a file
RewriteCond %{REQUEST_FILENAME} !-d		# And if it isn't a directory
RewriteCond %{REQUEST_URI} .*/music$	# And if they only requested /music instead of /music/
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [QSA,L,R=301] # Then append a trailing slash

ProxyPass /music/ http://localhost:3366/	# Proxy all request to /music/ to the CYP server (running on the same server as apache)
ProxyWebsocketFallbackToProxyHttp Off		# Don't fallback to http for WebSocket requests

# Rewrite WebSocket requests to CYP WebSocket requets, (also converts wss to ws)
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/music/?(.*) "ws://localhost:3366/$1" [P,L]

Installation - nginx

location /music/ {
  proxy_pass_header  Set-Cookie;
  proxy_set_header   Host               $host;
  proxy_set_header   X-Real-IP          $remote_addr;
  proxy_set_header   X-Forwarded-Proto  $scheme;
  proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "Upgrade";
  proxy_set_header Host $host;
  proxy_pass http://localhost:8080/;
}

Youtube-dl integration

You will need a working youtube-dl installation. Audio files are downloaded into the _youtube directory, so make sure it is available to your MPD library (use a symlink).

If you use Docker, you need to mount the _youtube directory into the image:

docker run --network=host -v "$(pwd)"/_youtube:/cyp/_youtube cyp

Changing the port

...is done via the PORT environment variable. If you use Docker, the -e switch does the trick:

docker run --network=host -e PORT=12345 cyp

Password-protected MPD

Create a passwords.json file in CYPs home directory. Specify passwords for available MPD servers:

{
  "localhost:6600": "my-pass-1",
  "some.other.server.or.ip:12345": "my-pass-2"
}

Make sure that hostnames and ports match those specified via the server querystring argument (defaults to localhost:6600).

Technology

  • TypeScript
  • Connected to MPD via WebSockets (using the ws2mpd bridge)
  • Token-based access to the WebSocket endpoint (better than an Origin check)
  • Written using Custom Elements
  • Responsive layout via Flexbox
  • CSS Custom Properties
  • SVG icons (Material Design)
  • Can spawn Youtube-dl to search/download audio files
  • Album art retrieved directly from MPD (and cached via localStorage)

cyp's People

Contributors

jfox-sk avatar netmindz avatar ondras avatar stuporglue avatar supersandro2000 avatar tincho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

cyp's Issues

How to build JS and CSS?

Hi,
please, can you provide some instructions about how to build JavaScript (app/js/.js > app/cyp.js) and CSS (app/css/.less > app/cyp.css)?
Thank you!

bin script entry point

A bin script entry point would be very helpful so that installation and usage can be simpler (npm install --global cyp)

This bin script would need to at least support configuration for passwords.json location and _youtube location, perhaps via command line arguments or via a configuration file (one file for passwords and other configs including _youtube?)
Also helpful if it opens the cyp URL in a browser.

A user can then just simply run cyp

Artist now shown in CurrentSong or Queue

As i installed the cyp the artists were not showing at current song overview or inside the queue.

In the /app/cyp.js i changed line 899 (function subtitle)

data["Artist"] && tokens.push(data["Artist"]);
to
data["AlbumArtist"] && tokens.push(data["AlbumArtist"]);

and it got fixed.

Support downloading specified YT URLs (skipping search)

It would be nice if I could paste in a YouTube playlist URL into the search, and cyp would download the specified item(s).

eg 1. If I search for "https://www.youtube.com/watch?v=zKmWd8DPrEc", then that song should be downloaded

eg 2. If I search for "https://www.youtube.com/watch?v=uJ_1HMAGb4k&list=PLELP0qeHrI9hzsK4zlNraYm6SKYssnU0X" then the entire playlist should be downloaded (youtube-dl supports this, of course)

I started taking a look at how to do this, but don't have time dive too deep. This code might be helpful though. It takes a string, tries to make a URL and then checks it against known YouTube URL domains to see if it looks like a YouTube link.

If query isn't a URL, "new URL" will throw an exception.

        // If our query is already a youtube URL, then just download it.
        try {
            var url = new URL(query);
            if ( url.host.match(/(youtubeeducation.com|youtubekids.com|yt.be|yt3.ggpht.com|ytimg.com|googlevideo.com|gvt1.com|youtu.be|youtube-nocookie.com|youtube-ui.l.google.com|video.google.com|youtubeembeddedplayer.googleapis.com|youtubei.googleapis.com|youtube\.(com?.)?([a-zA-Z]{2,3}))$/) ) {
                // Do the direct download route. Or show the Item for the link (The song or playlist title)
            }
        } catch (_) {
            // Not a URL? Do the usual routine
        }
```

Add nginx config example to README

Very nice project!
Solution for #17 and might be nice in case someone else wants to know:

location /music/ {
    proxy_pass_header  Set-Cookie;
    proxy_set_header   Host               $host;
    proxy_set_header   X-Real-IP          $remote_addr;
    proxy_set_header   X-Forwarded-Proto  $scheme;
    proxy_set_header   X-Forwarded-For    $proxy_add_x_forwarded_for;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_set_header Host $host;
    proxy_pass http://localhost:8080/;
  }

it opens port 8080 to ipv6 only

Hi, how can I get rid completely of IPv6? it's useless for me and makes me crazy, unfortunately also your program what to deal only with that.
root@orangepizero:~/cyp# node .
no passwords.json found
1670083525741 ws2mpd attached to a http server { address: '::', family: 'IPv6', port: 8080 }

On /etc/sysctl.conf are already preset these lines:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

I rebooted, I don't know how can I kill it
I've an orangepi with latest armbian. Thank you

Is there merit to making CYP a Volumio/Moode plugin?

First off, great work!

I don't like the Volumio/Moode interfaces. Behind the times compared to yours. I suspect this interface can run on an Rpi. Is there merit to making CYP easily installable on those distros, perhaps like a Volumio plugin? Thanks for your answer :)

Unexpected behavior

In the Library view, if I select a directory and after that click on the button ">>", select a subdirectory and press "Play", then not only the selected subdirectory is added to the queue, but all directories on the same level as the selected subdirectory, i.e. the first selected directory.

I would expect that only the last selected directory is added to the queue in this case.

JS error in Search for Safari 12.1

I've only tested on Safari 12.1 and Chrome 74 on macOS 10.14.4. Works nicely in Chrome but I'm getting the below JS error when the app loads in Safari:

[Error] Unhandled Promise Rejection: TypeError: function is not a constructor (evaluating 'super()')
	Search (search.js:9)
	init (library.js:109)
	(anonymous function) (app.js:58)
	asyncFunctionResume
	(anonymous function)
	promiseReactionJob

Installation crashed because of ws2mpd

Hi,
I tried to install cyp following your instruction, but when executing npm i, it crashed with the following message:

npm WARN package.json [email protected] No repository field.
npm ERR! notarget No compatible version found: ws2mpd@'>=2.0.0 <3.0.0'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.0.0"]
npm ERR! notarget 
npm ERR! notarget This is most likely not a problem with npm itself.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! System Linux 4.14.98-v7+
npm ERR! command "/usr/bin/node" "/usr/bin/npm" "i"
npm ERR! cwd /home/pi/Bureau/cyp
npm ERR! node -v v8.11.1
npm ERR! npm -v 1.4.21
npm ERR! code ETARGET
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /home/pi/Bureau/cyp/npm-debug.log
npm ERR! not ok code 0

I attached the file npm-debug.log for detailed information.
npm-debug.log

I also tried to get ws2mpd from your git repo, I cloned it and made npm i in the repo which ran successfully, but even after that the installation of cyp still fails.

Do you have any idea on how to solve this issue?
Cheers,

Étienne

Queue is not updated

If another mpd client changes the queue, it is not updated, if the queue is currently visible. After changing to another tab and back to the queue, it is updated and shows the correct information.

FR: Option to set default server

While selecting the server via the query string is possible, would it be possible to add an environment variable to allow you to set the default server?

Server crashes at first request

Hi, I followed the instructions:

npm install
node . 

server starts but on first access to port 8080, it crashes:

1557694931111 'ws2mpd attached to a http server' { address: '::', family: 'IPv6', port: 8080 }
/home/tincho/cyp/node_modules/ws2mpd/commands.js:22
			this._mpd.off("data", this._dataListener);
			          ^

TypeError: this._mpd.off is not a function
    at Welcome._done (/home/tincho/cyp/node_modules/ws2mpd/commands.js:22:14)
    at Welcome._processBuffer (/home/tincho/cyp/node_modules/ws2mpd/commands.js:57:20)
    at Welcome._onData (/home/tincho/cyp/node_modules/ws2mpd/commands.js:16:8)
    at Socket.Command._dataListener.data (/home/tincho/cyp/node_modules/ws2mpd/commands.js:9:37)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at addChunk (_stream_readable.js:263:12)
    at readableAddChunk (_stream_readable.js:250:11)
    at Socket.Readable.push (_stream_readable.js:208:10)
    at TCP.onread (net.js:601:20)

mpd is running

Node v8.16
Debian 9.9

Support deleting downloaded YouTube items

It would be nice if there were a way to delete downloaded YouTube items.

My users can access cyp through the web, but don't have disk access to manage files.

I think this could/should only apply to YouTube files. Since cyp is responsible for downloading them, I see no problem with it also having permissions to delete them.

Failed to connect to mpd

Hi there !
I am really interested on trying your project, however once I point my browser to the webpage of my mpd server, I am getting : Failed to connect to MPD after 3 attempts. Please reload the page to try again.

The server output is : ws2mpd attached to a http server { address: '::', family: 'IPv6', port: 3399 } (Why IPv6 though ..)
Bear in mind that cyp and mpd run on the same remote server, and I am trying to reach cyp through a different computer.

Documentation how to specify remote server

By default cyp seems to try to find the mpd server on localhost. A common scenario are mpd servers hosted somewhere else in the network.

If there is a straightforward way to configure a remote mpd server host please document it :)

FR: Outputs

Hi

It would be very nice if one can also enable disable defined MPD outputs. I am sure most users have multiple MPD outputs to control like Pulse, http, Icecast etc.

Docker?

is it possible to provide a proxyable Docker image for this?

thanks

How to specify password for MPD server?

Hello,

I cannot seem to find documentation on how to setup the connection to my mpd server. It is running on the same host as cyp on the default port, but it is configured to require password authentication.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.