Skip to content
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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

lkho
Copy link

@lkho lkho commented Oct 23, 2020

@blackjack4494
Copy link
Owner

related issues:
ytdl-org#26788

Copy link
Owner

@blackjack4494 blackjack4494 left a 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.

Comment on lines +278 to +279
'Referer': re.search(r'https?://[^/]+', url).group(0),
'Origin': re.search(r'https?://[^/]+', url).group(0),
Copy link
Owner

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?

Copy link
Author

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)
Copy link
Owner

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

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.

Copy link
Author

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?

Comment on lines 290 to 303
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)
Copy link
Owner

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.

Copy link
Author

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

'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']
Copy link
Owner

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

Copy link
Author

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?

Copy link
Author

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

@pukkandan
Copy link

@lkho I would like to merge this into yt-dlp. Could you make a PR there?

pukkandan pushed a commit to yt-dlp/yt-dlp that referenced this pull request Apr 15, 2021
* 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
nixxo pushed a commit to nixxo/yt-dlp that referenced this pull request Nov 22, 2021
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants