Created
June 1, 2021 14:56
-
-
Save itszechs/67660a966876cea771e31b6ec5463521 to your computer and use it in GitHub Desktop.
Python function to check is crunchyroll account is premium or not
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| def test_account(email, password): | |
| user_login = requests.post('https://beta-api.crunchyroll.com/auth/v1/token', | |
| { | |
| 'username': email, | |
| 'password': password, | |
| 'grant_type': 'password', | |
| 'scope': 'offline_access' | |
| }, | |
| headers={'User-Agent': 'Crunchyroll/3.0.0 Android/5.1.1 okhttp/3.12.1'}, | |
| auth=('cr_android', '1cf35dc5-b286-4551-8835-d4b1b4258445')) | |
| if user_login.status_code != 200: | |
| return False | |
| user_login = user_login.json() | |
| access_token = user_login.get('access_token') | |
| user_profile = requests.get('https://beta-api.crunchyroll.com/accounts/v1/me', headers={ | |
| 'User-Agent': 'Crunchyroll/3.0.0 Android/5.1.1 okhttp/3.12.1', | |
| 'Authorization': 'Bearer ' + access_token | |
| }) | |
| if user_profile.status_code != 200: | |
| return False | |
| user_profile = user_profile.json() | |
| external_id = user_profile.get('external_id') | |
| benefits = requests.get( | |
| f'https://beta-api.crunchyroll.com/subs/v1/subscriptions/{external_id}/benefits', | |
| headers={ | |
| 'User-Agent': 'Crunchyroll/3.0.0 Android/5.1.1 okhttp/3.12.1', | |
| 'Authorization': 'Bearer ' + access_token | |
| }) | |
| if benefits.status_code != 200 and benefits.json().get('code') == 'subscription.not_found': | |
| return False | |
| benefits = benefits.json() | |
| if benefits.get('items')[0]['benefit'] == 'cr_premium': | |
| return True | |
| return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment