106 lines
3.6 KiB
Python
106 lines
3.6 KiB
Python
import requests
|
|
import hashlib
|
|
from apps.bitwarden.utils import bitwardenUtils
|
|
|
|
class betaserieUtils():
|
|
url = "https://api.betaseries.com/members/auth"
|
|
|
|
username_UID="7bc7ebd2-9c95-487f-9ba2-b47301591ef0"
|
|
password_UID="262c3246-203b-44e0-854b-b47301599730"
|
|
token_UID="2cf4be0f-f26f-473f-b8f1-b473016139e4"
|
|
|
|
#Adding __ to make the variable private and can't be access outside the class,
|
|
# only by the class itself ot the subclass
|
|
|
|
__access_token = "0.7720f24b-4328-41ef-b70b-b419018270a3.nhBoRMSkfrlxqJVZ9W0W1g3lNFrmfI:35muVQz2mO3coR46bIZgcQ=="
|
|
__organization_id = "a6361589-badd-4bde-9cb4-af8901161c0d"
|
|
|
|
bw = bitwardenUtils(__access_token,__organization_id)
|
|
|
|
__betaserie_username = bw.read_value_secret(username_UID)
|
|
__betaserie_md5_password = bw.read_value_secret(password_UID)
|
|
__betaserie_apikey = bw.read_value_secret(token_UID)
|
|
|
|
payload = {
|
|
'login': __betaserie_username, # username or email
|
|
'password': __betaserie_md5_password # MD5 hashed password
|
|
}
|
|
|
|
headers = {
|
|
'X-BetaSeries-Key': __betaserie_apikey,
|
|
}
|
|
response = requests.post(url, headers=headers, data=payload)
|
|
|
|
#now set with the correct value
|
|
__betaserie_token = response.json()['token']
|
|
|
|
#set the __betaserie_token to the doct headers now
|
|
headers.update({'X-BetaSeries-Token': __betaserie_token})
|
|
|
|
def status_code(self):
|
|
print("Status code:", self.response.status_code)
|
|
print("Response:", self.response.json())
|
|
|
|
|
|
def identify_serie(self,serie_name,verbose=False):
|
|
#
|
|
# Usage
|
|
# show_id = beta.identify_serie("The simpsons")
|
|
# show_id = beta.identify_serie("The simpsons",verbose=True)
|
|
#
|
|
url = "https://api.betaseries.com/shows/search?title="+serie_name
|
|
|
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
|
if verbose:
|
|
print("Url request: "+str(url))
|
|
print(response.text)
|
|
|
|
show_id = response.json()['shows'][0]['id']
|
|
|
|
return show_id
|
|
|
|
def identify_episode(self,show_id,episode_number,verbose=False):
|
|
#
|
|
# Usage
|
|
# episode_id = beta.identify_episode(show_id,"S01E01",True)
|
|
#
|
|
url = "https://api.betaseries.com/episodes/search?show_id="+str(show_id)+"&number="+str(episode_number)
|
|
|
|
response = requests.request("GET", url, headers=self.headers, data=self.payload)
|
|
|
|
episode_id = response.json()['episode']['id']
|
|
if verbose:
|
|
print("Url request: "+str(url))
|
|
print(response.text)
|
|
|
|
return episode_id
|
|
|
|
def mark_episodes_watched(self,episode_id,verbose=False):
|
|
#
|
|
# Usage
|
|
# response = beta.mark_episodes_watched(episode_id,True)
|
|
#
|
|
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)
|
|
|
|
response = requests.request("POST", url, headers=self.headers, data=self.payload)
|
|
if verbose:
|
|
print("Url request: "+str(url))
|
|
print(response.text)
|
|
|
|
return response.status_code
|
|
|
|
def unmark_episodes_watched(self,episode_id,verbose=False):
|
|
#
|
|
# Usage
|
|
# response = beta.unmark_episodes_watched(episode_id,True)
|
|
#
|
|
url = "https://api.betaseries.com/episodes/watched?id="+str(episode_id)
|
|
|
|
response = requests.request("DELETE", url, headers=self.headers, data=self.payload)
|
|
|
|
if verbose:
|
|
print("Url request: "+str(url))
|
|
print(response.text)
|
|
|
|
return response.status_code
|