Switch to unified view

a/src/mediaserver/cdplugins/tidal/tidal-app.py b/src/mediaserver/cdplugins/tidal/tidal-app.py
...
...
48
48
49
is_logged_in = False
49
is_logged_in = False
50
50
51
tidalidprefix = '0$tidal$'
51
tidalidprefix = '0$tidal$'
52
52
53
def maybelogin():
53
def maybelogin(a={}):
54
    global session
54
    global session
55
    global quality
55
    global quality
56
    global httphp
56
    global httphp
57
    global pathprefix
57
    global pathprefix
58
    global is_logged_in
58
    global is_logged_in
...
...
69
    if "UPMPD_PATHPREFIX" not in os.environ:
69
    if "UPMPD_PATHPREFIX" not in os.environ:
70
        raise Exception("No UPMPD_PATHPREFIX in environment")
70
        raise Exception("No UPMPD_PATHPREFIX in environment")
71
    pathprefix = os.environ["UPMPD_PATHPREFIX"]
71
    pathprefix = os.environ["UPMPD_PATHPREFIX"]
72
    if "UPMPD_CONFIG" not in os.environ:
72
    if "UPMPD_CONFIG" not in os.environ:
73
        raise Exception("No UPMPD_CONFIG in environment")
73
        raise Exception("No UPMPD_CONFIG in environment")
74
74
    upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
75
    upconfig = conftree.ConfSimple(os.environ["UPMPD_CONFIG"])
75
    
76
    if 'user' in a:
76
    username = upconfig.get('tidaluser')
77
        username = a['user']
77
    password = upconfig.get('tidalpass')
78
        password = a['password']
78
    qalstr = upconfig.get('tidalquality')
79
    else:
80
        username, password = getserviceuserpass(upconfig, 'tidal')
79
    if not username or not password:
81
    if not username or not password:
80
        raise Exception("tidaluser and/or tidalpass not set in configuration")
82
        raise Exception("tidaluser and/or tidalpass not set in configuration")
81
83
84
    qalstr = upconfig.get('tidalquality')
82
    if qalstr == 'lossless':
85
    if qalstr == 'lossless':
83
        quality = Quality.lossless
86
        quality = Quality.lossless
84
    elif qalstr == 'high':
87
    elif qalstr == 'high':
85
        quality = Quality.high
88
        quality = Quality.high
86
    elif qalstr == 'low':
89
    elif qalstr == 'low':
...
...
105
        return ('audio/flac', str(1411))
108
        return ('audio/flac', str(1411))
106
    elif quality == Quality.high:
109
    elif quality == Quality.high:
107
        return ('audio/mpeg', str(320))
110
        return ('audio/mpeg', str(320))
108
    else:
111
    else:
109
        return ('audio/mpeg', str(96))
112
        return ('audio/mpeg', str(96))
113
114
# This is not used by the media server. It's for use by the OpenHome
115
# Credentials service
116
@dispatcher.record('login')
117
def login(a):
118
    maybelogin(a)
119
    session_id, country_code = session.get_token_and_country()
120
    return {'token' : session_id, 'country' : country_code}
110
121
111
@dispatcher.record('trackuri')
122
@dispatcher.record('trackuri')
112
def trackuri(a):
123
def trackuri(a):
113
    maybelogin()
124
    maybelogin()
114
    msgproc.log("trackuri: [%s]" % a)
125
    msgproc.log("trackuri: [%s]" % a)