From 3b6737cd15bf7dab6595cdaade2bf4b3a1f530a5 Mon Sep 17 00:00:00 2001 From: kaliko Date: Thu, 16 May 2019 14:38:56 +0200 Subject: [PATCH] Massive refactoring * Switch to python3 * Switch to musicpd python module * Moved to git --- .gitignore | 4 ++ CHANGELOG.md | 9 +++ INSTALL | 14 ---- MANIFEST.in | 1 + Makefile | 52 --------------- README.md | 10 +++ src/crop => bin/mcrop | 59 +++++++++-------- bin/mfade | 146 ++++++++++++++++++++++++++++++++++++++++++ {src => bin}/mtime | 73 +++++++++------------ bin/nalbum | 137 +++++++++++++++++++++++++++++++++++++++ bin/wakeup | 85 ++++++++++++++++++++++++ misc/README | 2 - misc/config.py | 38 ----------- misc/jingle.py | 132 -------------------------------------- setup.cfg | 33 ++++++++++ setup.py | 14 ++++ src/lib/__init__.py | 0 src/lib/goodies.py | 50 --------------- src/lib/mpdclass.py | 64 ------------------ src/lib/startop.py | 117 --------------------------------- src/mfade | 121 ---------------------------------- src/mtopls | 106 ------------------------------ src/nalbum | 124 ----------------------------------- src/wakeup | 106 ------------------------------ 24 files changed, 499 insertions(+), 998 deletions(-) create mode 100644 .gitignore create mode 100644 CHANGELOG.md delete mode 100644 INSTALL create mode 100644 MANIFEST.in delete mode 100644 Makefile create mode 100644 README.md rename src/crop => bin/mcrop (55%) create mode 100755 bin/mfade rename {src => bin}/mtime (57%) mode change 100644 => 100755 create mode 100755 bin/nalbum create mode 100755 bin/wakeup delete mode 100644 misc/README delete mode 100644 misc/config.py delete mode 100755 misc/jingle.py create mode 100644 setup.cfg create mode 100755 setup.py delete mode 100644 src/lib/__init__.py delete mode 100755 src/lib/goodies.py delete mode 100755 src/lib/mpdclass.py delete mode 100644 src/lib/startop.py delete mode 100755 src/mfade delete mode 100755 src/mtopls delete mode 100755 src/nalbum delete mode 100755 src/wakeup diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3464f65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +dist +build +mpd_goodies.egg-info +__pycache__ diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..39d2ac9 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,9 @@ +mpd-goodies (0.1.0) + +Initial release. + + * Convert previous code to python3 + * Switch to python-musicpd + * Move to git + +UNRELEASED diff --git a/INSTALL b/INSTALL deleted file mode 100644 index 3311c4c..0000000 --- a/INSTALL +++ /dev/null @@ -1,14 +0,0 @@ -Default installation in /usr/{bin,share/,share/man}. - -Makefile supports both DESTDIR and PREFIX GNU standards. - -Just call install target to have mpd-goodies installed within /usr - - make install - -If you need to install it somewhere else use PREFIX variable. -For instance installing in /usr/local directory: - - make PREFIX=/usr/local install - -Run uninstall target to remove. diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..fc49293 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include CHANGELOG.md diff --git a/Makefile b/Makefile deleted file mode 100644 index 6bf3dfc..0000000 --- a/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -SHELL = /bin/sh -PREFIX = /usr -#DESTDIR = /tmp/mpd-goodies -LIBDIR = $(DESTDIR)$(PREFIX)/lib -BIN = $(DESTDIR)$(PREFIX)/bin -ETC = $(DESTDIR)$(PREFIX)/etc -DATADIR = $(DESTDIR)$(PREFIX)/share -LOCALEDIR = $(DATADIR)/locale -MANDIR = $(DATADIR)/man -PKGNAME = mpd-goodies - -all: man bin -#clean: -# rm -f mpd-goodies.1.gz - -mpd-goodies.1.gz: - cat data/mpd-goodies.1 | gzip > mpd-goodies.1.gz - -bash_completion: - install -d $(ETC)/bash_completion.d - install -m644 data/mpd-goodies.sh $(ETC)/bash_completion.d/ - mv $(ETC)/bash_completion.d/mpd-goodies.sh $(ETC)/bash_completion.d/$(PKGNAME) - -man: mpd-goodies.1.gz - -install: - install -d $(BIN) $(DATADIR)/$(PKGNAME) #$(MANDIR)/man1 - - #install -m644 mpd-goodies.1.gz $(MANDIR)/man1 - - # listing all sub folder to install (prevent a remaining .svn directory to be install) - for sourcedir in `find src/ -name .svn -prune -o -type d -print | sed 's:src/::g'` ; do \ - install -d $(DATADIR)/$(PKGNAME)/$$sourcedir; \ - for sourcefile in `find src/$$sourcedir -maxdepth 1 -name *pyc -o -name .svn -prune -o -print` ; do \ - install -m644 $$sourcefile $(DATADIR)/$(PKGNAME)/$$sourcedir; \ - done \ - done - # listing all command in ./src - for command in `find src/ -maxdepth 1 -name .svn -prune -o -type f -print` ; do \ - install -m 755 $$command $(DATADIR)/$(PKGNAME)/ ;\ - done - for command in `find $(DATADIR)/$(PKGNAME)/ -maxdepth 1 -name .svn -prune -o -type f -print` ; do \ - ln -sf $$command $(BIN) ;\ - done - -uninstall: - for command in `find $(DATADIR)/$(PKGNAME)/ -maxdepth 1 -name .svn -prune -o -type f -print` ; do \ - rm -rf $(BIN)/$$(basename $$command) ;\ - done - rm -f $(MANDIR)/man1/mpd-goodies.1.gz - rm -f $(ETC)/bash_completion.d/$(PKGNAME) - rm -rf $(DATADIR)/$(PKGNAME) diff --git a/README.md b/README.md new file mode 100644 index 0000000..43aa84d --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# MPD-GOODIES + +A collection of small commands to play with MusicPlayerDaemon: + + * Fading in/out over a specified time + * Jumping to next album en queue. + * Last modified artist/album + * Crop the queue + +[MusicPlayerDaemon]: https://www.musicpd.org/ diff --git a/src/crop b/bin/mcrop similarity index 55% rename from src/crop rename to bin/mcrop index 4829a65..ad2fecf 100755 --- a/src/crop +++ b/bin/mcrop @@ -1,7 +1,7 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # -*- coding: utf-8 -*- -# Copyright (c) 2009, 2010, 2012 Kaliko Jack +# Copyright (c) 2009,2010,2012,2019 kaliko # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -17,54 +17,53 @@ # along with this program. If not, see . # +import argparse import sys -from lib.goodies import Goodie +from os.path import basename -NAME = 'crop' -VERSION = '0.1' -USAGE = 'USAGE: %prog [--help] | [ ]' +import musicpd +VERSION = '0.2' -class Crop(Goodie): - """ - """ + +class Crop(musicpd.MPDClient): script_info = dict({ - 'version': VERSION, - 'prog_name': NAME, + 'prog': basename(__file__), 'description': 'Keep tracks before currently played, removed others. Default is to keep 6 tracks.', - 'usage': USAGE, - }) + 'epilog': 'Set MPD host/port in env. var' + }) def __init__(self): """""" - Goodie.__init__(self, self.__class__.script_info) + musicpd.MPDClient.__init__(self) self.nb_tracks = 6 - self._get_arg() + self._get_args() self._run() - def _get_arg(self): + def _get_args(self): """""" - if not self.cli_args: - return True - try: - self.nb_tracks = int(self.cli_args[0]) - except ValueError, err: - self.parser.error('invalid argument, not a natural number? (%s)' % err) + parser = argparse.ArgumentParser(**self.__class__.script_info) + parser.add_argument('--version', action='version', + version='v%s' % VERSION) + parser.add_argument('n', type=int, nargs='?', + help='how many titles to crop') + args = parser.parse_args() + if args.n: + self.nb_tracks = args.n def _run(self): """""" - print 'Connecting %s:%i' % (self.cli_options.host, self.cli_options.port) - print 'Keeping %i tracks' % self.nb_tracks - self.mpdConnect() - current_pos = int(self.client.currentsong().get('pos', 0)) + self.connect() + current_pos = int(self.currentsong().get('pos', 0)) if current_pos <= self.nb_tracks: - self.client.disconnect() + self.disconnect() sys.exit(0) + print('Keeping %i tracks' % self.nb_tracks) while current_pos > self.nb_tracks: - self.client.delete(0) - current_pos = int(self.client.currentsong().get('pos', 0)) - self.client.disconnect() + self.delete(0) + current_pos = int(self.currentsong().get('pos', 0)) + self.disconnect() sys.exit(0) diff --git a/bin/mfade b/bin/mfade new file mode 100755 index 0000000..61a68f3 --- /dev/null +++ b/bin/mfade @@ -0,0 +1,146 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Copyright (c) 2009,2010,2012,2019 kaliko +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +""" +DOC: + heavily borrowed from perl script mpdtoys and converted to python. + mpdtoys © 2007 Joey Hess + http://kitenet.net/~joey/code/mpdtoys +""" + +import argparse +import sys + +from time import sleep +from os.path import basename + +import musicpd + + +VERSION = '0.2' +DESC = """Fade in/out to over