mirror of
https://github.com/beetbox/beets.git
synced 2026-03-01 18:55:50 +01:00
commit
a6c4f0a7a3
4 changed files with 120 additions and 0 deletions
82
beetsplug/subsonicupdate.py
Normal file
82
beetsplug/subsonicupdate.py
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# This file is part of beets.
|
||||
# Copyright 2016, Adrian Sampson.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
|
||||
"""Updates Subsonic library on Beets import
|
||||
Your Beets configuration file should contain
|
||||
a "subsonic" section like the following:
|
||||
subsonic:
|
||||
host: 192.168.x.y (Subsonic server IP)
|
||||
port: 4040 (default)
|
||||
user: <your username>
|
||||
pass: <your password>
|
||||
"""
|
||||
from __future__ import division, absolute_import, print_function
|
||||
|
||||
from beets.plugins import BeetsPlugin
|
||||
from beets import config
|
||||
import requests
|
||||
import string
|
||||
import hashlib
|
||||
import random
|
||||
|
||||
__author__ = 'https://github.com/maffo999'
|
||||
|
||||
|
||||
class SubsonicUpdate(BeetsPlugin):
|
||||
def __init__(self):
|
||||
super(SubsonicUpdate, self).__init__()
|
||||
|
||||
# Set default configuration values
|
||||
config['subsonic'].add({
|
||||
u'host': u'localhost',
|
||||
u'port': 4040,
|
||||
u'user': u'admin',
|
||||
u'pass': u'admin',
|
||||
})
|
||||
config['subsonic']['pass'].redact = True
|
||||
self.register_listener('import', self.loaded)
|
||||
|
||||
def loaded(self):
|
||||
host = config['subsonic']['host'].as_str()
|
||||
port = config['subsonic']['port'].as_str()
|
||||
user = config['subsonic']['user'].as_str()
|
||||
passw = config['subsonic']['pass'].as_str()
|
||||
|
||||
# To avoid sending plaintext passwords, authentication will be
|
||||
# performed via username, a token, and a 6 random
|
||||
# letters/numbers sequence.
|
||||
# The token is the concatenation of your password and the 6 random
|
||||
# letters/numbers (the salt) which is hashed with MD5.
|
||||
|
||||
# Pick the random sequence and salt the password
|
||||
r = string.ascii_letters + string.digits
|
||||
salt = "".join([random.choice(r) for n in range(6)])
|
||||
t = passw + salt
|
||||
token = hashlib.md5()
|
||||
token.update(t.encode('utf-8'))
|
||||
|
||||
# Put together the payload of the request to the server and the URL
|
||||
payload = {
|
||||
'u': user,
|
||||
't': token.hexdigest(),
|
||||
's': salt,
|
||||
'v': '1.15.0',
|
||||
'c': 'beets'
|
||||
}
|
||||
url = "http://{}:{}/rest/startScan".format(host, port)
|
||||
response = requests.post(url, params=payload)
|
||||
|
||||
if response.status_code != 200:
|
||||
self._log.error(u'Generic error, please try again later.')
|
||||
|
|
@ -30,6 +30,9 @@ New features:
|
|||
* :doc:`/plugins/replaygain`: albumpeak on large collections is calculated as
|
||||
the average, not the maximum.
|
||||
:bug:`3008` :bug:`3009`
|
||||
* A new :doc:`/plugins/subsonicupdate` can automatically update your Subsonic library.
|
||||
Thanks to :user:`maffo999`.
|
||||
:bug:`3001`
|
||||
|
||||
Fixes:
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ like this::
|
|||
smartplaylist
|
||||
sonosupdate
|
||||
spotify
|
||||
subsonicupdate
|
||||
the
|
||||
thumbnails
|
||||
types
|
||||
|
|
|
|||
34
docs/plugins/subsonicupdate.rst
Normal file
34
docs/plugins/subsonicupdate.rst
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
SubsonicUpdate Plugin
|
||||
=====================
|
||||
|
||||
``subsonicupdate`` is a very simple plugin for beets that lets you automatically
|
||||
update `Subsonic`_'s index whenever you change your beets library.
|
||||
|
||||
.. _Subsonic: http://www.subsonic.org
|
||||
|
||||
To use ``subsonicupdate`` plugin, enable it in your configuration
|
||||
(see :ref:`using-plugins`).
|
||||
Then, you'll probably want to configure the specifics of your Subsonic server.
|
||||
You can do that using a ``subsonic:`` section in your ``config.yaml``,
|
||||
which looks like this::
|
||||
|
||||
subsonic:
|
||||
host: X.X.X.X
|
||||
port: 4040
|
||||
user: username
|
||||
pass: password
|
||||
|
||||
With that all in place, beets will send a Rest API to your Subsonic
|
||||
server every time you change your beets library.
|
||||
|
||||
This plugin requires Subsonic v6.1 or higher and an active Premium license (or trial).
|
||||
|
||||
Configuration
|
||||
-------------
|
||||
|
||||
The available options under the ``subsonic:`` section are:
|
||||
|
||||
- **host**: The Subsonic server name/IP. Default: ``localhost``
|
||||
- **port**: The Subsonic server port. Default: ``4040``
|
||||
- **user**: The Subsonic user. Default: ``admin``
|
||||
- **pass**: The Subsonic user password. Default: ``admin``
|
||||
Loading…
Reference in a new issue