You are not logged in.

#1 2018-06-28 17:17:13

arnaudv6
Member
Registered: 2016-02-25
Posts: 28

lizzy (music player) python script that feeds your music to mpv

Dear community, may I happily present you my intended replacement for m?

Its name is lizzy, it is a single file, written in python + curses, featuring more consistency and more features than its ancestor.

I am much eager to hear from you about:

  • thoughts about the usage : bring on your best workflow obsessions : we might share them big_smile

  • feature propositions (please acknowledge the vision though before hitting too wide)

  • more pythonistic ways to code (hobbyist still learning the trade here)

  • faster code paths (we love speed, do not we?)


edit: I -> we, line 4, changing the title

Last edited by arnaudv6 (2018-06-29 07:44:46)

Offline

#2 2018-06-28 18:09:18

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 15,923

Re: lizzy (music player) python script that feeds your music to mpv

It looked really good until I reached elif hell  hmm

You are looking to be more Pythonic.  Might I suggest a data structure, say a dictionary in which the key is the key stroke, and defines the operation to perform using lambda functions?

Kind of like this:

theDict = { "a" : lambda x: someFunctionThatHandles_a (x),
                   "b" : lambda x: someFunctionThatHandles_b (x),
                   "c" : lambda x: someFunctionThatHandles_c (x),
                }

keyStroke = someFunctionToReadTheKey()
theDict[keyStroke]()

Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

#3 2018-06-28 20:36:24

Xyne
Moderator/TU
Registered: 2008-08-03
Posts: 6,349
Website

Re: lizzy (music player) python script that feeds your music to mpv

ewaller wrote:
theDict = { "a" : lambda x: someFunctionThatHandles_a (x),
                   "b" : lambda x: someFunctionThatHandles_b (x),
                   "c" : lambda x: someFunctionThatHandles_c (x),
                }

You could omit the lambdas in that example, e.g.

key_funcs = {
  'a': some_function_that_handles_a,
  'b': some_function_that_handles_b,
  ...
}

@arnaudv6
Use a try-except block to catch key errors if you take that approach (see EAFP):

key = read_the_key()
try:
  func = key_funcs[key]
except KeyError:
  pass # Ignore unhandled keys.
else:
  func() # or func(key) or func(<other data>), depending on what the function expects.

My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2018-06-29 07:35:20

arnaudv6
Member
Registered: 2016-02-25
Posts: 28

Re: lizzy (music player) python script that feeds your music to mpv

Thanks you both for reading the code and proposing enhancements. cool

ewaller wrote:

It looked really good until I reached elif hell  hmm

@ewaller: Now you say it, I was not proud with this part of the code, and... a dictionary is the obvious way to go: thanks!

Xyne wrote:

Use a try-except block to catch key errors if you take that approach.

@Xyne: I will, thanks!

I fear I won't have time to refactor this and test regressions before a fortnight though.

Offline

#5 2018-07-14 10:07:04

arnaudv6
Member
Registered: 2016-02-25
Posts: 28

Re: lizzy (music player) python script that feeds your music to mpv

OK, Lizzy got quite an overhaul, in an attempt for more pythonistic style.
Feature-wise, expect accents to work as they should. smile
(Search is insensitive to case and accents.)
I had very little time for testing but it should be a pleasant ride: please report any odd behaviour.

Offline

Board footer

Powered by FluxBB