4
from xl import collection, event, settings
5
import spydaap.parser.exaile
7
log = logging.getLogger(__file__)
10
# todo support multiple connections?
11
class CollectionWrapper:
13
def __init__(self, id, track):
16
self.parser = spydaap.parser.exaile.ExaileParser()
19
def get_dmap_raw(self):
21
self.daap = ''.join([d.encode() for d in self.parser.parse(self.track)[0]])
24
def get_original_filename(self):
25
return self.track.local_file_name()
27
def __init__(self, collection):
28
self.collection = collection
35
for t in self.collection:
36
self.map.append(self.TrackWrapper(i, t))
40
def get_item_by_id(self, id):
41
return self.map[int(id)]
43
def __getitem__(self, idx):
47
return len(self.collection)
49
from server import DaapServer
56
event.add_callback(on_settings_change, 'option_set')
58
port = int(settings.get_option('plugin/daapserver/port', 3689))
59
name = settings.get_option('plugin/daapserver/name', 'Exaile Share')
60
host = settings.get_option('plugin/daapserver/host', '0.0.0.0')
62
# DaapServer.init(exaile.collection,port=port,name=name)
63
ds = DaapServer(CollectionWrapper(exaile.collection), port=port, name=name, host=host)
64
if( settings.get_option('plugin/daapserver/enabled', True) ):
69
def __enb(evname, exaile, wat):
70
gobject.idle_add(_enable, exaile)
75
event.add_callback(__enb, 'gui_loaded')
77
__enb(None, exaile, None)
88
import daapserverprefs
91
return daapserverprefs
93
def on_settings_change(event, setting, option):
94
if option == 'plugin/daapserver/name' and ds is not None:
95
ds.set(name=settings.get_option(option,'Exaile Share'))
96
if option == 'plugin/daapserver/port' and ds is not None:
97
ds.set(port=settings.get_option(option,3689))
98
if option == 'plugin/daapserver/host' and ds is not None:
99
ds.set(host=settings.get_option(option,'0.0.0.0'))
100
if option == 'plugin/daapserver/enabled' and ds is not None:
101
enabled = setting.get_option(option, True)
105
# settings.set_option('plugin/daapserver/enabled', False) ?