]> kaliko git repositories - python-musicpd.git/commitdiff
Add a "Library overview" section in doc
authorKaliko Jack <kaliko@azylum.org>
Thu, 31 Jan 2019 14:56:42 +0000 (15:56 +0100)
committerKaliko Jack <kaliko@azylum.org>
Thu, 31 Jan 2019 14:56:42 +0000 (15:56 +0100)
doc/source/index.rst

index c55d08dfe8be591c89a42f09363bddac9f3e1e5a..fdfeb70df3ac357ba1d57d322705054eec25e6ea 100644 (file)
@@ -16,6 +16,31 @@ Installation
     pip install git+https://gitlab.com/kaliko/python-musicpd.git
 
 
+Library overview
+----------------
+Here is a snippet allowing to list the last modified artists in the media library:
+
+.. code:: python3
+
+        #!/usr/bin/env python3
+        # coding: utf-8
+        import musicpd
+
+        def main():
+            cli = musicpd.MPDClient()
+            cli.connect()
+            # Gets files count in the library
+            nb_files = int(cli.stats()['songs'])
+            # Gets the last 100 files modified
+            files = cli.search('file', '', 'sort', 'Last-Modified', 'window', (nb_files-100,))
+            # Print last modified artists in media library
+            print(' / '.join({f.get('albumartist') for f in files}))
+            cli.disconnect()
+
+        # Script starts here
+        if __name__ == '__main__':
+            main()
+
 
 Build documentation
 --------------------