-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathmixcloud.py
More file actions
80 lines (68 loc) · 2.43 KB
/
Copy pathmixcloud.py
File metadata and controls
80 lines (68 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
$description British music live-streaming platform for radio shows and DJ mixes.
$url mixcloud.com
$type live
$metadata id
$metadata author
$metadata title
"""
import re
from streamlink.logger import getLogger
from streamlink.plugin import Plugin, pluginmatcher
from streamlink.plugin.api import validate
from streamlink.stream.hls import HLSStream
log = getLogger(__name__)
@pluginmatcher(re.compile(r"https?://(?:www\.)?mixcloud\.com/live/(?P<user>[^/]+)"))
class Mixcloud(Plugin):
def _get_streams(self):
data = self.session.http.post(
"https://www.mixcloud.com/graphql",
json={
"query": """
query streamData($user: UserLookup!) {
userLookup(lookup: $user) {
id
displayName
liveStream(isPublic: false) {
name
streamStatus
hlsUrl
}
}
}
""",
"variables": {"user": {"username": self.match.group("user")}},
},
schema=validate.Schema(
validate.parse_json(),
{
"data": {
"userLookup": validate.none_or_all(
{
"id": str,
"displayName": str,
"liveStream": {
"name": str,
"streamStatus": validate.any("ENDED", "LIVE"),
"hlsUrl": validate.none_or_all(validate.url()),
},
},
),
},
},
validate.get(("data", "userLookup")),
),
)
if not data:
log.error("User not found")
return
self.id = data.get("id")
self.author = data.get("displayName")
data = data.get("liveStream")
if data.get("streamStatus") == "ENDED":
log.info("This stream has ended")
return
self.title = data.get("name")
if data.get("hlsUrl"):
return HLSStream.parse_variant_playlist(self.session, data.get("hlsUrl"))
__plugin__ = Mixcloud