-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[viu:ott] add support for premium account, add language_flag_id query param #211
base: master
Are you sure you want to change the base?
Conversation
related issues: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what you think of my comments.
'Referer': re.search(r'https?://[^/]+', url).group(0), | ||
'Origin': re.search(r'https?://[^/]+', url).group(0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So Referer
and Origin
are the same? Why is url
not valid/possible to use?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i just reproduced exactly what the browser sent out. haven't checked if it will work when you pass the full url.
except (ExtractorError, KeyError): | ||
stream_data = None | ||
if video_data.get('user_level', 0) > 0: | ||
user = self._login(country_code, video_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use
def _real_initialize(self):
self._login()
above line 230 so before defining _login()
Have a look here how it's done
youtube-dlc/youtube_dlc/extractor/viki.py
Lines 88 to 107 in 7eff09d
def _real_initialize(self): | |
self._login() | |
def _login(self): | |
username, password = self._get_login_info() | |
if username is None: | |
return | |
login_form = { | |
'login_id': username, | |
'password': password, | |
} | |
login = self._call_api( | |
'sessions.json', None, | |
'Logging in', post_data=login_form) | |
self._token = login.get('token') | |
if not self._token: | |
self.report_warning('Unable to get session token, login has probably failed') |
You need some _USER = None
or so at the top of the extractor then
That way login will automatically executed whenever you supply credentials.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wrote like this since I don't want to login unless really necessary. @zackmark29 has once mentioned the server counts the login sessions such that one user cannot login into more a limited devices at the same time. is it not the common way to do or should I make it always login if credentials is provided?
youtube_dl/extractor/viu.py
Outdated
if user: | ||
query['identity'] = user['identity'] | ||
stream_data = self._download_json( | ||
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code, | ||
video_id, 'Downloading stream info', query=query, headers=headers) | ||
stream_data = self._detect_error(stream_data).get('stream') | ||
else: | ||
# preview is limited to 3min for non-members | ||
# try to bypass the duration limit | ||
duration_limit = True | ||
query['duration'] = '180' | ||
stream_data = self._download_json( | ||
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code, | ||
video_id, 'Downloading stream info', query=query, headers=headers) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could avoid to use the exact same code twice here since all that changes seems to be the query. So you can alter the query in if
statements and do the json download outside of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the really repeating code is only one line, so here I extracted that specific line into a separated function:
2290860
youtube_dl/extractor/viu.py
Outdated
'https://d1k2us671qcoau.cloudfront.net/distribute_web_%s.php' % country_code, | ||
video_id, 'Downloading stream info', query=query, headers=headers) | ||
try: | ||
stream_data = self._detect_error(stream_data)['stream'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could use .get('stream')
here as well as you do on line 295
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line relies on the KeyError thrown if stream
is not in the dict. do you prefer writing an explicit if?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i changed this check to the boolean flag instead of catching the exception in 2290860
* add language_flag_id query param * add support for premium account (untested since I dont have a premium account) * support entire series Code from: blackjack4494/youtube-dlc#211 ytdl-org/youtube-dl#15182 ytdl-org/youtube-dl#26775 Fixes: #219 ytdl-org/youtube-dl#27946 ytdl-org/youtube-dl#27863 ytdl-org/youtube-dl#27812 ytdl-org/youtube-dl#27464 ytdl-org/youtube-dl#26788 blackjack4494/yt-dlc#136 Possibly also fixes (untested): ytdl-org/youtube-dl#16992 ytdl-org/youtube-dl#26701 Co-authored by: lkho, pukkandan
* add language_flag_id query param * add support for premium account (untested since I dont have a premium account) * support entire series Code from: blackjack4494/youtube-dlc#211 ytdl-org/youtube-dl#15182 ytdl-org/youtube-dl#26775 Fixes: yt-dlp#219 ytdl-org/youtube-dl#27946 ytdl-org/youtube-dl#27863 ytdl-org/youtube-dl#27812 ytdl-org/youtube-dl#27464 ytdl-org/youtube-dl#26788 blackjack4494/yt-dlc#136 Possibly also fixes (untested): ytdl-org/youtube-dl#16992 ytdl-org/youtube-dl#26701 Co-authored by: lkho, pukkandan
ytdl-org#26775