4 from .common
import InfoExtractor
16 class QDanceIE(InfoExtractor
):
17 _NETRC_MACHINE
= 'qdance'
18 _VALID_URL
= r
'https?://(?:www\.)?q-dance\.com/network/(?:library|live)/(?P<id>[\w-]+)'
21 'url': 'https://www.q-dance.com/network/library/146542138',
25 'title': 'Sound Rush [LIVE] | Defqon.1 Weekend Festival 2022 | Friday | RED',
26 'display_id': 'sound-rush-live-v3-defqon-1-weekend-festival-2022-friday-red',
27 'description': 'Relive Defqon.1 - Primal Energy 2022 with the sounds of Sound Rush LIVE at the RED on Friday! 🔥',
28 'season': 'Defqon.1 Weekend Festival 2022',
29 'season_id': '31840632',
31 'series_id': '31840378',
32 'thumbnail': 'https://images.q-dance.network/1674829540-20220624171509-220624171509_delio_dn201093-2.jpg',
33 'availability': 'premium_only',
36 'params': {'skip_download': 'm3u8'},
39 'url': 'https://www.q-dance.com/network/live/149170353',
43 'title': r
're:^Defqon\.1 2023 - Friday - RED',
44 'display_id': 'defqon-1-2023-friday-red',
45 'description': 'md5:3c73fbbd4044e578e696adfc64019163',
46 'season': 'Defqon.1 Weekend Festival 2023',
47 'season_id': '141735599',
49 'series_id': '31840378',
50 'thumbnail': 'https://images.q-dance.network/1686849069-area-thumbs_red.png',
51 'availability': 'subscriber_only',
52 'live_status': 'is_live',
53 'channel_id': 'qdancenetwork.video_149170353',
55 'skip': 'Completed livestream',
57 'note': 'vod with alphanumeric id',
58 'url': 'https://www.q-dance.com/network/library/WhDleSIWSfeT3Q9ObBKBeA',
60 'id': 'WhDleSIWSfeT3Q9ObBKBeA',
62 'title': 'Aftershock I Defqon.1 Weekend Festival 2023 I Sunday I BLUE',
63 'display_id': 'naam-i-defqon-1-weekend-festival-2023-i-dag-i-podium',
64 'description': 'Relive Defqon.1 Path of the Warrior with Aftershock at the BLUE 🔥',
66 'series_id': '31840378',
67 'season': 'Defqon.1 Weekend Festival 2023',
68 'season_id': '141735599',
70 'availability': 'premium_only',
71 'thumbnail': 'https://images.q-dance.network/1698158361-230625-135716-defqon-1-aftershock.jpg',
73 'params': {'skip_download': 'm3u8'},
75 'url': 'https://www.q-dance.com/network/library/-uRFKXwmRZGVnve7av9uqA',
76 'only_matching': True,
82 def _call_login_api(self
, data
, note
='Logging in'):
83 login
= self
._download
_json
(
84 'https://members.id-t.com/api/auth/login', None, note
, headers
={
85 'content-type': 'application/json',
87 'origin': 'https://www.q-dance.com',
88 'referer': 'https://www.q-dance.com/',
89 }, data
=json
.dumps(data
, separators
=(',', ':')).encode(),
90 expected_status
=lambda x
: True)
92 tokens
= traverse_obj(login
, ('data', {
93 '_id-t-accounts-token': ('accessToken', {str}
),
94 '_id-t-accounts-refresh': ('refreshToken', {str}
),
95 '_id-t-accounts-id-token': ('idToken', {str}
),
98 if not tokens
.get('_id-t-accounts-token'):
99 error
= ': '.join(traverse_obj(login
, ('error', ('code', 'message'), {str}
)))
100 if 'validation_error' not in error
:
101 raise ExtractorError(f
'Q-Dance API said "{error}"')
102 msg
= 'Invalid username or password' if 'email' in data
else 'Refresh token has expired'
103 raise ExtractorError(msg
, expected
=True)
105 for name
, value
in tokens
.items():
106 self
._set
_cookie
('.q-dance.com', name
, value
)
108 def _perform_login(self
, username
, password
):
109 self
._call
_login
_api
({'email': username
, 'password': password
})
111 def _real_initialize(self
):
112 cookies
= self
._get
_cookies
('https://www.q-dance.com/')
113 self
._refresh
_token
= try_call(lambda: cookies
['_id-t-accounts-refresh'].value
)
114 self
._access
_token
= try_call(lambda: cookies
['_id-t-accounts-token'].value
)
115 if not self
._access
_token
:
116 self
.raise_login_required()
119 if (try_call(lambda: jwt_decode_hs256(self
._access
_token
)['exp']) or 0) <= int(time
.time() - 120):
120 if not self
._refresh
_token
:
121 raise ExtractorError(
122 'Cannot refresh access token, login with yt-dlp or refresh cookies in browser')
123 self
._call
_login
_api
({'refreshToken': self
._refresh
_token
}, note
='Refreshing access token')
124 self
._real
_initialize
()
126 return {'Authorization': self
._access
_token
}
128 def _real_extract(self
, url
):
129 video_id
= self
._match
_id
(url
)
130 webpage
= self
._download
_webpage
(url
, video_id
)
131 data
= self
._search
_nuxt
_data
(webpage
, video_id
, traverse
=('data', 0, 'data'))
133 def extract_availability(level
):
134 level
= int_or_none(level
) or 0
135 return self
._availability
(
136 needs_premium
=(level
>= 20), needs_subscription
=(level
>= 15), needs_auth
=True)
138 info
= traverse_obj(data
, {
139 'title': ('title', {str.strip
}),
140 'description': ('description', {str.strip
}),
141 'display_id': ('slug', {str}
),
142 'thumbnail': ('thumbnail', {url_or_none}
),
143 'duration': ('durationInSeconds', {int_or_none}
, filter),
144 'availability': ('subscription', 'level', {extract_availability}
),
145 'is_live': ('type', {lambda x
: x
.lower() == 'live'}),
146 'artist': ('acts', ..., {str}
),
147 'series': ('event', 'title', {str.strip
}),
148 'series_id': ('event', 'id', {str_or_none}
),
149 'season': ('eventEdition', 'title', {str.strip
}),
150 'season_id': ('eventEdition', 'id', {str_or_none}
),
151 'channel_id': ('pubnub', 'channelName', {str}
),
154 stream
= self
._download
_json
(
155 f
'https://dc9h6qmsoymbq.cloudfront.net/api/content/videos/{video_id}/url',
156 video_id
, headers
=self
._get
_auth
(), expected_status
=401)
158 m3u8_url
= traverse_obj(stream
, ('data', 'url', {url_or_none}
))
159 if not m3u8_url
and traverse_obj(stream
, ('error', 'code')) == 'unauthorized':
160 raise ExtractorError('Your account does not have access to this content', expected
=True)
162 formats
= self
._extract
_m
3u8_formats
(
163 m3u8_url
, video_id
, fatal
=False, live
=True) if m3u8_url
else []
165 self
.raise_no_formats('No active streams found', expected
=bool(info
.get('is_live')))