songmem

package module
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 9, 2020 License: MIT Imports: 6 Imported by: 1

README

GoDoc

Installation

Installation has been tested on OpenBSD and Ubuntu, but will probably run on any POSIX-compliant operating system, that is supported by golang.

To install songmem run go get -v -u 'github.com/codesoap/songmem/...' (this will take some time, because the dependency go-sqlite3 is big). The songmem binary will be placed at $HOME/go/bin/songmem. Add $HOME/go/bin/ to your $PATH for easy usage.

Usage

Usage:
    songmem --register [--no-add] <name>
    songmem
    songmem --added-at
    songmem --favourite
    songmem --frecent
    songmem --suggestions <name>
    songmem --remove-hearing [<name>]
    songmem --remove-song [<name>]
    songmem --rename <name> <newname>
Options:
    -h --help         Show this screen.
    -r --register     Register that you just heard a song. If the song does not
                      exist yet, it will be added to the database.
    -n --no-add       Do not add a song to the database, when registering that
                      you just heard it. If the song does not exist, nothing
                      will happen.
    -t --added-at     List songs by the date of their addition. Newest first.
    -f --favourite    List songs you heard the most. Most heard first.
    -c --frecent      List songs you recently heard a lot. Most frecent first.
    -s --suggestions  List songs, that you often hear before or after hearing
                      the given song. Best suggestions first.
    --remove-hearing  Remove the latest hearing from the database. If <name> is
                      given, remove the latest hearing of the given song.
    --remove-song     Remove the last added song from the database. If <name> is
                      given, remove this song. Fails if there are still hearings
                      of the song.
    --rename          Rename the song <name> to <newname>.

If songmem is called without any arguments, it will list all songs, last heard
first.

Music player integration

The following scripts assume that you store your songs like <artist> - <title>.

mpd (requires mpc)

This script registers when a song is played through mpd. Start it after launching mpd(1).

#!/usr/bin/env sh

while true
do
	song="$(mpc -f '%artist% - %title%' current --wait)"
	songmem --register "$song"
done

You can search for recently heard songs and play them in mpd (requires dmenu; alternatively you could use fzf):

#!/usr/bin/env sh

# Abort when dmenu is quit using <esc>:
set -e

song="$(songmem | dmenu -i -l 15 -p "Play song:")"
artist="$(printf '%s' "$song" | awk -F ' - ' '{print $1}')"
title="$(printf '%s' "$song" | awk '{i=index($0, " - "); print substr($0, i+3)}')"
songfile="$(mpc search artist "$artist" title "$title")"
if [ -n "$songfile" ]
then
	mpc clear
	mpc add "$songfile"
	mpc play
fi

Adapt these scripts to add songs to the queue, browse through song suggestions for the currently playing song, ...

Setting up keyboard shortcuts for your scripts could also prove useful.

ytools

#!/usr/bin/env sh

# Abort when dmenu is quit using <esc> or the song cannot be played:
set -e

song="$(songmem | dmenu -i -l 15 -p "Play song:")"
ytools-search "$song"
mpv --ytdl-format "bestaudio/best" --no-video "$(ytools-pick 1)"
songmem --register "$song"

You could add this as a fallback into the previous script for mpd.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type SongDB

type SongDB struct {
	*sql.DB
}

func InitDB

func InitDB(filepath string) (SongDB, error)

func (SongDB) AddHearing

func (db SongDB) AddHearing(song string) (err error)

AddHearing registers that the given song was listened to at the current timestamp.

song must exactly match an already existing song from the database.

The current timestamp will be stored with the local timezone, to enable sorting hearings by time of day, even when traveling around timezones.

func (SongDB) AddHearingAndSongIfNeeded

func (db SongDB) AddHearingAndSongIfNeeded(song string) error

AddHearingAndSongIfNeeded registers that the song was listened to and, if necessary, adds the song to the database before that.

func (SongDB) AddSong

func (db SongDB) AddSong(song string) (err error)

AddSong adds the song with the given name and the current timestamp to the database.

Feel free to include the artist's name in the song.

The current timestamp will be stored with the local timezone, to enable sorting songs by time of day, even when traveling around timezones.

func (SongDB) CreateSchemaIfNotExists

func (db SongDB) CreateSchemaIfNotExists() (err error)

func (SongDB) ListFavouriteSongs

func (db SongDB) ListFavouriteSongs() (songs []string, err error)

ListFavouriteSongs lists all songs, listing those first, that you heard most often.

func (SongDB) ListFrecentSongs

func (db SongDB) ListFrecentSongs() (songs []string, err error)

ListFrecentSongs lists songs you lately heard a lot, most frecent first.

func (SongDB) ListSongsInOrderOfAddition

func (db SongDB) ListSongsInOrderOfAddition() (songs []string, err error)

ListSongsInOrderOfAddition lists all songs in the order they were added. Newest additions will be listed first.

func (SongDB) ListSongsInOrderOfLastHearing

func (db SongDB) ListSongsInOrderOfLastHearing() (songs []string, err error)

ListSongsInOrderOfLastHearing lists all songs in the order they were last heard. The songs that were heard last will be listed first.

func (SongDB) ListSuggestions

func (db SongDB) ListSuggestions(song string) (songs []string, err error)

ListSuggestions lists songs that you aften hear before or after hearing the given song. Best suggestions first.

func (SongDB) RemoveLastAddedSong

func (db SongDB) RemoveLastAddedSong() (song string, err error)

RemoveLastAddedSong removes the last added song from the database. Fails if there is still an entry in the hearing table, that references the song.

Returns the removed song's name.

func (SongDB) RemoveLastHearing

func (db SongDB) RemoveLastHearing() (song string, err error)

RemoveLastHearing removes the latest hearing. Fails if there is no hearing in the database.

func (SongDB) RemoveLastHearingOf

func (db SongDB) RemoveLastHearingOf(song string) (err error)

RemoveLastHearingOf removes the latest hearing of the given song. Fails if the song was never heard or the song does not exist.

func (SongDB) RemoveSong

func (db SongDB) RemoveSong(song string) (err error)

RemoveSong removes the song with the given name from the database. Fails if there is still an entry in the hearing table, that references the song.

func (SongDB) RenameSong

func (db SongDB) RenameSong(song, newName string) (err error)

RenameSong renames the given song to newName.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL