Skip to content

Instantly share code, notes, and snippets.

@blackjack4494
Created June 29, 2021 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blackjack4494/9051f8f904347540de8170dd38a3f5f7 to your computer and use it in GitHub Desktop.
Save blackjack4494/9051f8f904347540de8170dd38a3f5f7 to your computer and use it in GitHub Desktop.
Viki.com API Login revised
import requests
import sys
import getpass
import time
import hashlib
import hmac
import json
_API_QUERY_TEMPLATE = '/v4/%sapp=%s&t=%s&site=www.viki.com'
_API_URL_TEMPLATE = 'https://api.viki.io%s&sig=%s'
_APP = '100000a' # '100005a'
_APP_VERSION = '2.2.5.1428709186'
_APP_SECRET = 'MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95=Iad'
# _APP_SECRET_1 = '-$iJ}@p7!G@SyU/je1bEyWg}upLu-6V6-Lg9VD(]siH,r.,m-r|ulZ,U4LC/SeR)'
# _APP_SECRET_2 = 'MM_d*yP@`&1@]@!AVrXf_o-HVEnoTnm$O-ti4[G~$JDI/Dc-&piU&z&5.;:}95=Iad'
# _APP_SECRET_3 = '' ??
# raw_APP_SECRET_1 = '' ??
# raw_APP_SECRET_2 = 'a4e52e9b08620b7131d1830c71cde6cf03c4a7b00d664d9dec8ee27a19d13ba0'
# raw_APP_SECRET_3 = 'd96704b180208dbb2efa30fe44c48bd8690441af9f567ba8fd710a72badc85198f7472'
_token = None
def cred_login():
user = input("User: ")
password = getpass.getpass()
return login(user=user, password=password)
def login(user=None, password=None, login_json=None):
if user is None:
if login_json is None:
print("provide either user/pass or login json")
return
else:
login_form = login_json
else:
login_form_cred = {
"login_id": user,
"password": password,
}
login_form = login_form_cred
path = 'sessions.json'
path += '?' if '?' not in path else '&'
timestamp = ''
if not timestamp:
timestamp = int(time.time())
query = _API_QUERY_TEMPLATE % (path, _APP, timestamp)
sig = hmac.new(
_APP_SECRET.encode('ascii'),
query.encode('ascii'),
hashlib.sha1
).hexdigest()
url = _API_URL_TEMPLATE % (query, sig)
r = requests.post(url, json=login_form)
return r.json().get("token")
login_form = {
"login_id": "USERNAME",
"password": "SECRET",
}
# input user and password in terminal
print(cred_login())
# provide a login_form ~ useful for automated testing
#print(login(login_form))
# provide user and password directly ~ useful for automated testing
#print(login("USERNAME", "SECRET"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment