28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65 | def client():
global conn
if not conn:
conn = soundcloud.Client(client_id="f0aea6e0484043f6638cb5bf35d43312")
return conn
# Capture play events for faux MIME type
def sndcl_convert(row={}, audioformat="audio/mpeg", source="pls", url=None, assoc={}):
if audioformat==fmt or rx_url.match(url):
# find streaming address
try:
log.DATA_CONVERT_SOUNDCLOUD(url)
track = client().get('/resolve', url=url)
track_str = "/tracks/{}/stream".format(track.id)
url = client().get(track_str, allow_redirects=False).location
# override attributes
row["url"] = url
source = "srv"
audioformat = "audio/mpeg"
except Exception as e:
log.ERR_SOUNDCLOUD("URL resolving failed:", e)
# let web browser run
audioformat = "url/http"
# let primary handler take over
if audioformat != fmt:
return action.run_fmt_url(row, audioformat, source, url, assoc)
# Hook up custom action.handler for soundcloud URLs
#
# Still somewhat hodgepodge. The action module just lets .play() params
# rewrite by above handler. Should turn faux "audio/soundcloud" URL into
# plain/longwinded MP3 streaming address. |
|
|
>
|
| 28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66 | def client():
global conn
if not conn:
conn = soundcloud.Client(client_id="f0aea6e0484043f6638cb5bf35d43312")
return conn
# Capture play events for faux MIME type
def sndcl_convert(row={}, audioformat="audio/mpeg", source="pls", assoc={}):
if audioformat==fmt or rx_url.match(url):
# find streaming address
try:
log.DATA_CONVERT_SOUNDCLOUD(url)
track = client().get('/resolve', url=url)
track_str = "/tracks/{}/stream".format(track.id)
url = client().get(track_str, allow_redirects=False).location
# override attributes
row["url"] = url
row["format"] = "audio/mpeg"
audioformat = "audio/mpeg"
source = "srv"
except Exception as e:
log.ERR_SOUNDCLOUD("URL resolving failed:", e)
# let web browser run
audioformat = "url/http"
# let primary handler take over
if audioformat != fmt:
return action.run_fmt_url(row, audioformat, source, assoc)
# Hook up custom action.handler for soundcloud URLs
#
# Still somewhat hodgepodge. The action module just lets .play() params
# rewrite by above handler. Should turn faux "audio/soundcloud" URL into
# plain/longwinded MP3 streaming address. |