Skip to content

Commit

Permalink
Merge pull request #82 from vicwomg/development
Browse files Browse the repository at this point in the history
VLC default player, CDG support, cleanup
  • Loading branch information
vicwomg authored Dec 31, 2020
2 parents 6333feb + e221232 commit fe9ce1a
Show file tree
Hide file tree
Showing 7 changed files with 374 additions and 196 deletions.
103 changes: 67 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,30 @@

PiKaraoke is a "KTV"-style karaoke song search and queueing system. It connects to your TV, and shows a QR code for computers and smartphones to connect to a web interface. From there, multiple users can seamlessly search your local track library, queue up songs, add an endless selection of new karaoke tracks from YouTube, and more. ~For use with Raspberry Pi devices.~ Works on Raspberry Pi, OSX, Windows, and Linux!

If you want to support this project with a little monetary tip, it's much appreciated:
If you want to support this project with a little monetary tip, it's much appreciated: <br/>
<a href="https://www.buymeacoffee.com/vicwomg" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

## What's new (September 2020)
## What's new (January 2021)

- VLC support! Omxplayer is still default on raspberry pi, which can use both.
- Thanks to VLC and a lot of hacking, we now have cross platform support: Linux, OSX, and Windows!
- **Key Change / Pitch shifting!!** Also thanks to VLC. Not supported on omxplayer.
- python3 support! python 2.7 will still work for now, but it has gone the way of Latin. Python3 will become required in a near future revision.
- Basic hotkeys: "esc" exits app. "f" toggles fullscreen. This became necessary when working with windowed OS's
- VLC is now the default media player. You can still use omxplayer for slower pi devices with `--use-omxplayer`
- CDG file support! Also supports zipped cdg + mp3, just add the files to the root of the download directory (must be using vlc)
- Refresh song list manually from the info screen.
- Default download directories are now ~/pikaraoke-songs on MacOS, Windows, and Linux
- General overdue cleanup of libraries
- Removed the --show-overlay feature since it is omxplayer only and not supported on pi4

## Features

- Web interface for multiple users to queue tracks
- Searching song library via autocomplete
- Adding new tracks from Youtube
- Offline storage of video files
- mp3 + cdg support, including compressed .zip bundles (vlc only)
- Pause/Skip/Restart and volume control
- Now playing and Up Next display
- Basic editing of downloaded file names
- Queue editing
- Key Change / Pitch shifting (only available while using vlc)
- Key Change / Pitch shifting (vlc only)

## Screenshots

Expand Down Expand Up @@ -56,8 +58,8 @@ Also works on macs, PCs, and linux!

## Installation

Install git, if you haven't already.
Install python3/pip3: https://www.python.org/downloads/ (python 2.7 may work, but is not officially supported)
Install git, if you haven't already. (on raspberry pi: `sudo apt-get update; sudo apt-get install git`)
Install python3/pip3 (usually raspberry pis already have it, run `python3 --version` to check): https://www.python.org/downloads/ (python 2.7 may work, but is not officially supported)

Clone this repo:

Expand Down Expand Up @@ -127,14 +129,14 @@ This is optional, but you may want to make your raspberry pi a dedicated karaoke

```
# start pikaraoke on startup
/usr/bin/python /home/pi/pikaraoke/app.py &
/usr/bin/python3 /home/pi/pikaraoke/app.py &
```

Or if you're like me and want some logging for aiding debugging, the following stores output at: /var/log/pikaraoke.log:

```
# start pikaraoke on startup / logging
/usr/bin/python /home/pi/pikaraoke/app.py >> /var/log/pikaraoke.log 2>&1 &
/usr/bin/python3 /home/pi/pikaraoke/app.py >> /var/log/pikaraoke.log 2>&1 &
```

If you want to kill the pikaraoke process, you can do so from the PiKaraoke Web UI under: `Info > Quit pikaraoke`. Or you can ssh in and run `sudo killall python` or something similar.
Expand All @@ -143,21 +145,22 @@ Note that if your wifi/network is inactive pikaraoke will error out 10 seconds a

## Usage

Here is the full list of command line arguments:
Here is the full list of command line arguments on OSX as an example (may not be up to date, run `python3 app.py --help` for the latest):

```
usage: app.py [-h] [-p PORT] [-d DOWNLOAD_PATH] [-o OMXPLAYER_PATH]
[-y YOUTUBEDL_PATH] [-v VOLUME] [-s SPLASH_DELAY] [-l LOG_LEVEL]
[--show-overlay] [--hide-ip] [--hide-splash-screen] [--adev ADEV]
[--dual-screen] [--high-quality] [--use-vlc] [--vlc-path VLC_PATH]
[--vlc-port VLC_PORT]
[--hide-ip] [--hide-splash-screen] [--adev ADEV] [--dual-screen]
[--high-quality] [--use-omxplayer] [--use-vlc]
[--vlc-path VLC_PATH] [--vlc-port VLC_PORT]
[--logo_path LOGO_PATH]
optional arguments:
-h, --help show this help message and exit
-p PORT, --port PORT Desired http port (default: 5000)
-d DOWNLOAD_PATH, --download-path DOWNLOAD_PATH
Desired path for downloaded songs. (default:
~/pikaraoke/songs)
~/pikaraoke-songs)
-o OMXPLAYER_PATH, --omxplayer-path OMXPLAYER_PATH
Path of omxplayer. Only important to raspberry pi
hardware. (default: /usr/bin/omxplayer)
Expand All @@ -174,26 +177,32 @@ optional arguments:
-l LOG_LEVEL, --log-level LOG_LEVEL
Logging level int value (DEBUG: 10, INFO: 20, WARNING:
30, ERROR: 40, CRITICAL: 50). (default: 20 )
--show-overlay Show text overlay in omxplayer with song title and IP.
(feature is broken on Pi 4 omxplayer 12/24/2019)
--hide-ip Hide IP address from the screen.
--hide-splash-screen Hide splash screen before/between songs.
--adev ADEV Pass the audio output device argument to omxplayer.
Possible values: hdmi/local/both/alsa[:device]. If you
are using a rpi USB soundcard or Hifi audio hat, try:
'alsa:hw:0,0' Default 'both'
'alsa:hw:0,0' Default: 'both'
--dual-screen Output video to both HDMI ports (raspberry pi 4 only)
--high-quality Download higher quality video. Note: requires ffmpeg
and may cause CPU, download speed, and other
performance issues
--use-vlc Use VLC Player instead of the default OMX Player.
Enabled by default on non-pi hardware. Note: if you
want to play audio to the headphone jack on a rpi,
you'll need to configure this in raspi-config:
'Advanced Options > Audio > Force 3.5mm (headphone)'
--vlc-path VLC_PATH Full path to VLC (Defaults to standard installation
location)
--use-omxplayer Use OMX Player to play video instead of the default
VLC Player. This may be better-performing on older
raspberry pi devices. Certain features like key change
and cdg support wont be available. Note: if you want
to play audio to the headphone jack on a rpi, you'll
need to configure this in raspi-config: 'Advanced
Options > Audio > Force 3.5mm (headphone)'
--use-vlc Use VLC Player to play video. Enabled by default.
Note: if you want to play audio to the headphone jack
on a rpi, see troubleshooting steps in README.md
--vlc-path VLC_PATH Full path to VLC (Default:
/Applications/VLC.app/Contents/MacOS/VLC)
--vlc-port VLC_PORT HTTP port for VLC remote control api (Default: 5002)
--logo_path LOGO_PATH
Path to a custom logo image file for the splash
screen. Recommended dimensions ~ 500x500px
```

## Screen UI
Expand All @@ -210,7 +219,7 @@ Make sure you are connected to the same network/wifi. You can then enter the sho

- View Now Playing and Next tracks
- Access controls to repeat, pause, skip and control volume
- (only when --use-vlc option is used) Transpose slider to change playback pitch
- Transpose slider to change playback pitch

### Queue

Expand All @@ -229,6 +238,7 @@ Make sure you are connected to the same network/wifi. You can then enter the sho

- Shows the IP and QR code to share with others
- Shows CPU / Memory / Disk Use stats
- Allows updating the song list and youtube-dl version
- Allows user to quit to console, shut down, or reboot system. Always shut down from here before you pull the plug on pikaraoke!

## Troubleshooting
Expand All @@ -241,19 +251,30 @@ Advanced Options > Audio > Force 3.5mm (headphone)

See: https://www.raspberrypi.org/documentation/configuration/audio-config.md

### I'm having audio issues with the headphone jack, external sound card, or other audio device
If you're still having issues with hearing audio, it has been reported this helps on raspberry pi 4 devices:

Omxplayer tends to have some inconsistent results across different hardware combinations. Try experimenting with the --adev option, which specifies the audio device to omxplayer. Defaults to 'both' which is hdmi and headphone out. Other possible values are: hdmi/local/both/alsa[:device].
`sudo nano /usr/share/alsa/alsa.conf`

If you're hearing distorted audio out, try '--adev alsa'
Scroll down and change defaults.ctl.card and defaults.pcm.card to "1"

If you're using an external USB sound card or hifi audio hat like the hifiberry, you'll need to add the argument '--adev alsa:hw:0,0' when you launch pikaraoke
```
defaults.ctl.card 1
defaults.pcm.card 1
```

Note this value might be different in older versions of Raspbian or if you have external audio hardware. See source article for details: https://raspberrypi.stackexchange.com/a/39942

You can also try vlc with the --use-vlc option. It sometimes handles audio more consistently.
### I'm still having audio issues with the headphone jack, external sound card, or other audio device with omxplayer

If using omxplayer with `--use-omxplayer`, it tends to have some inconsistent results across different hardware combinations. Try experimenting with the --adev option, which specifies the audio device to omxplayer. Defaults to 'both' which is hdmi and headphone out. Other possible values are: hdmi/local/both/alsa[:device].

If you're hearing distorted audio output, try '--adev alsa' with omxplauer.

If you're using an external USB sound card or hifi audio hat like the hifiberry, you'll need to add the argument '--adev alsa:hw:0,0' when you launch pikaraoke

### Songs aren't downloading!

Make sure youtube-dl is up to date, old versions have higher failure rates due to security changes in Youtube. You can see your current version installed by navigating to `Info > System Info > Youtube-dl version`. The version number is usually the date it was released. If this is older than a few months, chances are it will need an update.
Make sure youtube-dl is up to date, old versions have higher failure rates due to security changes in Youtube. You can see your current version installed by navigating to `Info > System Info > Youtube-dl version`. The version number is usually the date it was released. If this is older than a couple of months, chances are it will need an update.

You can update youtube-dl directly from the web UI. Go to `Info > Update Youtube-dl` (depending on how you installed, you may need to be running pikaraoke as sudo for this to work)

Expand Down Expand Up @@ -301,10 +322,20 @@ The pi doesn't have a hardware audio input. Technically, you should be able to r

### How do I change song pitch/key?

First of all, you must be running pikaraoke with the --use-vlc option.

While a song is playing, the home screen of the web interface will show a transpose slider. Slide it up or down based on your preference and press the "ok" button to restart the song in the given key.

If you don't see this option, you may be running the `--use-omxplayer` option. Omxplayer does not support key change.

### How do I add cdg or mp3+cdg zip files?

You'll need to add them manually by copying them to the root of your download folder. Run `python app.py --help` and look under DOWNLOAD_PATH to find out what the default folder is, or specify your own. Only cdg/mp3 pairs and .zip files are supported.

### My mp3/cdg file is not playing

CDG files must have an mp3 file with a exact matching file name. They can also be bundled together in a single zip file, but the filenames in the zip must still match. They must also be placed in the root of the download directory and not stashed away in sub-directories.

If you only hear audio, you may be running the `--use-omxplayer` option. Omxplayer does not support cdg.

### I'm on a laptop, how do I output just pikaraoke to an external monitor/screen?

You might be able to just drag the windows to the target screen (press 'f' to toggle fullscreen). But in my experience there can be issues figuring out which monitor to use once videos start playing. For now you'd probably have the most consistent experience using single-screen mirrored mode.
99 changes: 46 additions & 53 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,13 @@

import cherrypy
import psutil
from flask import (
Flask,
flash,
redirect,
render_template,
request,
send_file,
send_from_directory,
url_for,
)
from flask import (Flask, flash, redirect, render_template, request, send_file,
send_from_directory, url_for)

import karaoke
from constants import VERSION
from get_platform import get_platform
from vlcclient import get_default_vlc_path

try:
from urllib.parse import quote, unquote
Expand Down Expand Up @@ -60,20 +54,23 @@ def home():
transpose_value=k.now_playing_transpose,
)


@app.route("/nowplaying")
def nowplaying():
if len(k.queue) >= 1:
next_song = filename_from_path(k.queue[0])
else:
next_song = None
rc = {
"now_playing": k.now_playing,
"up_next": next_song,
"is_paused": k.is_paused,
"transpose_value": k.now_playing_transpose,
}
return json.dumps(rc)
try:
if len(k.queue) >= 1:
next_song = filename_from_path(k.queue[0])
else:
next_song = None
rc = {
"now_playing": k.now_playing,
"up_next": next_song,
"is_paused": k.is_paused,
"transpose_value": k.now_playing_transpose,
}
return json.dumps(rc)
except (Exception) as e:
logging.error("Problem loading /nowplaying, pikaraoke may still be starting up: " + str(e))
return ""


@app.route("/queue")
Expand Down Expand Up @@ -358,6 +355,7 @@ def info():
disk=disk,
youtubedl_version=youtubedl_version,
show_shutdown=show_shutdown,
pikaraoke_version=VERSION
)


Expand Down Expand Up @@ -391,6 +389,10 @@ def update_ytdl():
th.start()
return redirect(url_for("home"))

@app.route("/refresh")
def refresh():
k.get_available_songs()
return redirect(url_for("browse"))

@app.route("/quit")
def quit():
Expand Down Expand Up @@ -432,27 +434,21 @@ def get_default_youtube_dl_path(platform):
else:
return "/usr/local/bin/youtube-dl"


def get_default_vlc_path(platform):
if platform == "osx":
return "/Applications/VLC.app/Contents/MacOS/VLC"
elif platform == "windows":
alt_vlc_path = r"C:\\Program Files (x86)\\VideoLAN\VLC\\vlc.exe"
if os.path.isfile(alt_vlc_path):
return alt_vlc_path
else:
return r"C:\Program Files\VideoLAN\VLC\vlc.exe"
else:
return "/usr/bin/vlc"


def get_default_dl_dir(platform):
if platform == "raspberry_pi":
return "/usr/lib/pikaraoke/songs"
elif platform == "windows":
return "~\pikaraoke\songs"
legacy_directory = os.path.expanduser("~\pikaraoke\songs")
if os.path.exists(legacy_directory):
return legacy_directory
else:
return "~\pikaraoke-songs"
else:
return os.path.expanduser("~/pikaraoke/songs")
legacy_directory = "~/pikaraoke/songs"
if os.path.exists(legacy_directory):
return legacy_directory
else:
return "~/pikaraoke-songs"


if __name__ == "__main__":
Expand Down Expand Up @@ -526,12 +522,6 @@ def get_default_dl_dir(platform):
default=default_log_level,
required=False,
)
parser.add_argument(
"--show-overlay",
action="store_true",
help="Show text overlay in omxplayer with song title and IP. (feature is broken on Pi 4 omxplayer 12/24/2019)",
required=False,
)
parser.add_argument(
"--hide-ip",
action="store_true",
Expand Down Expand Up @@ -563,10 +553,16 @@ def get_default_dl_dir(platform):
help="Download higher quality video. Note: requires ffmpeg and may cause CPU, download speed, and other performance issues",
required=False,
)
parser.add_argument(
"--use-omxplayer",
action="store_true",
help="Use OMX Player to play video instead of the default VLC Player. This may be better-performing on older raspberry pi devices. Certain features like key change and cdg support wont be available. Note: if you want to play audio to the headphone jack on a rpi, you'll need to configure this in raspi-config: 'Advanced Options > Audio > Force 3.5mm (headphone)'",
required=False,
),
parser.add_argument(
"--use-vlc",
action="store_true",
help="Use VLC Player instead of the default OMX Player. Enabled by default on non-pi hardware. Note: if you want to play audio to the headphone jack on a rpi, you'll need to configure this in raspi-config: 'Advanced Options > Audio > Force 3.5mm (headphone)'",
help="Use VLC Player to play video. Enabled by default. Note: if you want to play audio to the headphone jack on a rpi, see troubleshooting steps in README.md",
required=False,
),
parser.add_argument(
Expand Down Expand Up @@ -603,14 +599,11 @@ def get_default_dl_dir(platform):
}
)

# force VLC on non-pi hardware
if not platform == "raspberry_pi" and not args.use_vlc:
print("Defaulting to VLC player")
# Handle OMX player if specified
if platform == "raspberry_pi" and args.use_omxplayer:
args.use_vlc = False
else:
args.use_vlc = True
# disallow overlay on VLC
if args.use_vlc and args.show_overlay:
print("Overlay not supported VLC. Disabling it.")
args.show_overlay = False

# check if required binaries exist
if not os.path.isfile(args.youtubedl_path):
Expand Down Expand Up @@ -648,12 +641,12 @@ def get_default_dl_dir(platform):
splash_delay=args.splash_delay,
log_level=args.log_level,
volume=args.volume,
hide_overlay=not args.show_overlay,
hide_ip=args.hide_ip,
hide_splash_screen=args.hide_splash_screen,
omxplayer_adev=args.adev,
dual_screen=args.dual_screen,
high_quality=args.high_quality,
use_omxplayer=args.use_omxplayer,
use_vlc=args.use_vlc,
vlc_path=args.vlc_path,
vlc_port=args.vlc_port,
Expand Down
1 change: 1 addition & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "1.0.0"
Loading

0 comments on commit fe9ce1a

Please sign in to comment.