223 lines
8.5 KiB
HTML
223 lines
8.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en-us">
|
|
|
|
<head>
|
|
<link href="http://gmpg.org/xfn/11" rel="profile">
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
<meta http-equiv="content-type" content="text/html; charset=utf-8">
|
|
|
|
<!-- Enable responsiveness on mobile devices-->
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1">
|
|
|
|
<title>
|
|
|
|
Kyuss Music Player · Caught in the Net
|
|
|
|
</title>
|
|
|
|
<!-- CSS -->
|
|
<link rel="stylesheet" href="/public/css/poole.css">
|
|
<link rel="stylesheet" href="/public/css/syntax.css">
|
|
<link rel="stylesheet" href="/public/css/hyde.css">
|
|
|
|
<!-- Icons -->
|
|
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="/public/apple-touch-icon-144-precomposed.png">
|
|
<link rel="shortcut icon" href="/public/favicon.ico">
|
|
|
|
<!-- RSS -->
|
|
<link rel="alternate" type="application/rss+xml" title="RSS" href="/atom.xml">
|
|
</head>
|
|
|
|
|
|
<body class="theme-base-09">
|
|
|
|
<div class="sidebar">
|
|
<div class="container sidebar-sticky">
|
|
<div class="sidebar-about">
|
|
<h1>
|
|
<a href="/">
|
|
Caught in the Net
|
|
</a>
|
|
</h1>
|
|
<p class="lead"></p>
|
|
</div>
|
|
|
|
<nav class="sidebar-nav">
|
|
<a class="sidebar-nav-item" href="/">Home</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="sidebar-nav-item" href="/about/">About</a>
|
|
|
|
|
|
|
|
|
|
|
|
<a class="sidebar-nav-item" href="/archive/">Archive</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="sidebar-nav-item" href="/contattami/">Contattami</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<a class="sidebar-nav-item" href="/atom.xml">RSS</a>
|
|
<a class="sidebar-nav-item" href="http://francescomecca.eu:3000">Personal Git</a>
|
|
<a cleass="sidebar-nav-item" href="https://github.com/s211897-studentipolito">github</a>
|
|
<span class="sidebar-nav-item" href="" >Powered by Jekyll and Hyde</span>
|
|
</nav>
|
|
|
|
<p>© 2016. CC BY-SA 4.0 International </p>
|
|
</div>
|
|
</div>
|
|
|
|
<h3 class="masthead-title">
|
|
<a href="/" title="Home">Caught in the Net</a>
|
|
|
|
|
|
</h3>
|
|
|
|
<div class="content container">
|
|
<div class="post">
|
|
<h1 class="post-title">Kyuss Music Player</h1>
|
|
<span class="post-date">17 Apr 2016</span>
|
|
<p>For a long time I have been using Clementine music player on my workstation. Recently I reinstalled Gentoo on my desktop and I wanted to avoid installing QT libraries of any sort.
|
|
So I switched to <a href="https://www.musicpd.org/">mpd</a> and I have fallen in love with it. It is very flexible, fast and enriched by a lot of community software.
|
|
For some weeks I used mpc client as my primary client for mpd but I was not satisfied with it. Even though it is pretty minimal but packed with every feature mpd permits, the search feels uncomfortable because is case sensitive and need artist, album, etc. flags before any entry.
|
|
This is why I have written kpd together with Francesco Gallà</p>
|
|
|
|
<h2>Kyuss Player Client</h2>
|
|
|
|
<p>kpd is an acronym for Kyuss Player Client because we have been listening only to <a href="https://en.wikipedia.org/wiki/Kyuss">Kyuss</a> while programming this client.
|
|
We have reimplemented the search functions to suit our habits. No more case sensitive, optional 'artist, album, title' flags.
|
|
kpd accepts only one string as the search argument and implements optional filter arguments to narrow the search in a grep like way.
|
|
I welcome you to read the <a href="http://francescomecca.eu:3000/pesceWanda/kpd">readme</a> in my git to understand how the search works.
|
|
Anyway in this post I want to explain bits of the code.</p>
|
|
|
|
<h3>Main</h3>
|
|
|
|
<p>The main kpd file invoked when the command is run in the console is kpd.py
|
|
The most interesting part in this file IMHO is these lines:</p>
|
|
|
|
<figure class="highlight"><pre><code class="language-python" data-lang="python">
|
|
<span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">argsOrder</span><span class="p">:</span>
|
|
<span class="k">if</span> <span class="n">dictArgs</span><span class="p">[</span><span class="n">el</span><span class="p">]</span> <span class="o">!=</span> <span class="bp">False</span><span class="p">:</span>
|
|
<span class="n">client</span><span class="o">.</span><span class="n">update_status</span> <span class="p">()</span>
|
|
<span class="n">methodToCall</span> <span class="o">=</span> <span class="nb">getattr</span> <span class="p">(</span><span class="n">util</span><span class="p">,</span> <span class="n">el</span><span class="p">)</span>
|
|
<span class="n">retUtil</span> <span class="o">=</span> <span class="n">methodToCall</span> <span class="p">(</span><span class="n">client</span><span class="p">,</span> <span class="n">dictArgs</span><span class="p">[</span><span class="n">el</span><span class="p">],</span> <span class="n">searchRes</span><span class="p">)</span></code></pre></figure>
|
|
|
|
<p>argsOrder is a list of the arguments on the command line in the order the user wrote them.
|
|
kpd uses a dictionary to store for every argument the corrispective string for the function that will be invoked using getattr.
|
|
In this way any argument can be added to the main file without writing any other line of code. WE used this method to avoid using switch alike solutions.</p>
|
|
|
|
<h3>Util</h3>
|
|
|
|
<p>The util.py source file is a pretty easy source file to read. It contains every function that can be invoked by command line arguments. Every function has the same 'prototypes' so that they can be called using the method explained above.
|
|
To implement <code>no-output</code> and <code>output</code> function I have used a class:
|
|
to suppress the output on the console the program assign to <em>sys.stdout</em> a dummy class that save the original stdout on a variable and replaces write and flush functions so that they are just pass. and no output is written.
|
|
To permit output after suppression the program just reassing the original value to sys.stdout.</p>
|
|
|
|
<h3>Database Search</h3>
|
|
|
|
<p>In MPDdatabase.py we have written the search functions.
|
|
Originally we intended to just read and import in a dictionary the whole mpd database that is stored compressed in the home directory.
|
|
This list of dictionaries stores every entry related to the song and if any of them matches the search string or the filter string (considering also flags if any) the related song is printed on the output and saved in a list so it can be added by the add function.
|
|
This approach result very efficent in term of precision but it lacked speed. For a database of about 77 thousand songs (about 550k lines) a search query could last almost 2 seconds.
|
|
To improve the speed of the search we used the pickle module. The pickle module allows kpd to dump the data structure used to store the database in memory on a file that can be read easily by using the <code>pickle.load</code> function.
|
|
In this way the search lasts about 40 milliseconds on the same database that wastes about 16MiB of memory on disk.</p>
|
|
|
|
<h2>Conclusion</h2>
|
|
|
|
<p>This was really fun. It was our first hand on python project and the first real program we have written since we started learning programming at our university.
|
|
I discovered that programming allows me to relax and that is really cool to have custom software for activities you do every day.
|
|
The source for our program is stored in my git <a href="http://francescomecca.eu:3000/pesceWanda/kpd">here</a> and you are free to modify it.</p>
|
|
|
|
</div>
|
|
|
|
<div class="related">
|
|
<h2>Related Posts</h2>
|
|
<ul class="related-posts">
|
|
|
|
<li>
|
|
<h3>
|
|
<a href="/pescewanda/2016/05/15/genetic-alg/">
|
|
Interpolation using a genetic algorithm
|
|
<small>15 May 2016</small>
|
|
</a>
|
|
</h3>
|
|
</li>
|
|
|
|
<li>
|
|
<h3>
|
|
<a href="/pescewanda/2016/05/03/satoshisignature/">
|
|
Why Wright's proof is a fake
|
|
<small>03 May 2016</small>
|
|
</a>
|
|
</h3>
|
|
</li>
|
|
|
|
<li>
|
|
<h3>
|
|
<a href="/pescewanda/2016/04/17/wright-nakamoto/">
|
|
#JeSuisSatoshiNakamoto
|
|
<small>17 Apr 2016</small>
|
|
</a>
|
|
</h3>
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</body>
|
|
</html>
|