/ TIDALDL-PY / tidal_dl / apiKey.py
apiKey.py
  1  #!/usr/bin/env python
  2  # -*- encoding: utf-8 -*-
  3  """
  4  @File    :  apiKey.py
  5  @Date    :  2021/11/30
  6  @Author  :  Yaronzz
  7  @Version :  3.0
  8  @Contact :  yaronhuang@foxmail.com
  9  @Desc    :
 10  """
 11  import json
 12  import requests
 13  
 14  __KEYS_JSON__ = '''
 15  {
 16      "version": "1.0.1",
 17      "keys": [
 18          {
 19              "platform": "Fire TV",
 20              "formats": "Normal/High/HiFi(No Master)",
 21              "clientId": "OmDtrzFgyVVL6uW56OnFA2COiabqm",
 22              "clientSecret": "zxen1r3pO0hgtOC7j6twMo9UAqngGrmRiWpV7QC1zJ8=",
 23              "valid": "False",
 24              "from": "Fokka-Engineering (https://github.com/Fokka-Engineering/libopenTIDAL/blob/655528e26e4f3ee2c426c06ea5b8440cf27abc4a/README.md#example)"
 25          },
 26          {
 27              "platform": "Fire TV",
 28              "formats": "Master-Only(Else Error)",
 29              "clientId": "7m7Ap0JC9j1cOM3n",
 30              "clientSecret": "vRAdA108tlvkJpTsGZS8rGZ7xTlbJ0qaZ2K9saEzsgY=",
 31              "valid": "True",
 32              "from": "Dniel97 (https://github.com/Dniel97/RedSea/blob/4ba02b88cee33aeb735725cb854be6c66ff372d4/config/settings.example.py#L68)"
 33          },
 34          {
 35              "platform": "Android TV",
 36              "formats": "Normal/High/HiFi(No Master)",
 37              "clientId": "Pzd0ExNVHkyZLiYN",
 38              "clientSecret": "W7X6UvBaho+XOi1MUeCX6ewv2zTdSOV3Y7qC3p3675I=",
 39              "valid": "False",
 40              "from": ""
 41          },
 42          {
 43              "platform": "TV",
 44              "formats": "Normal/High/HiFi/Master",
 45              "clientId": "8SEZWa4J1NVC5U5Y",
 46              "clientSecret": "owUYDkxddz+9FpvGX24DlxECNtFEMBxipU0lBfrbq60=",
 47              "valid": "False",
 48              "from": "morguldir (https://github.com/morguldir/python-tidal/commit/50f1afcd2079efb2b4cf694ef5a7d67fdf619d09)"
 49          },
 50          {
 51              "platform": "Android Auto",
 52              "formats": "Normal/High/HiFi/Master",
 53              "clientId": "zU4XHVVkc2tDPo4t",
 54              "clientSecret": "VJKhDFqJPqvsPVNBV6ukXTJmwlvbttP7wlMlrc72se4=",
 55              "valid": "True",
 56              "from": "1nikolas (https://github.com/yaronzz/Tidal-Media-Downloader/pull/840)"
 57          }
 58      ]
 59  }
 60  '''
 61  __API_KEYS__ = json.loads(__KEYS_JSON__)
 62  __ERROR_KEY__ = {
 63      'platform': 'None',
 64      'formats': '',
 65      'clientId': '',
 66      'clientSecret': '',
 67                      'valid': 'False',
 68  },
 69  
 70  
 71  def getNum():
 72      return len(__API_KEYS__['keys'])
 73  
 74  
 75  def getItem(index: int):
 76      if index < 0 or index >= len(__API_KEYS__['keys']):
 77          return __ERROR_KEY__
 78      return __API_KEYS__['keys'][index]
 79  
 80  
 81  def isItemValid(index: int):
 82      item = getItem(index)
 83      return item['valid'] == 'True'
 84  
 85  
 86  def getItems():
 87      return __API_KEYS__['keys']
 88  
 89  
 90  def getLimitIndexs():
 91      array = []
 92      for i in range(len(__API_KEYS__['keys'])):
 93          array.append(str(i))
 94      return array
 95  
 96  
 97  def getVersion():
 98      return __API_KEYS__['version']
 99  
100  
101  # Load from gist
102  try:
103      respond = requests.get('https://api.github.com/gists/48d01f5a24b4b7b37f19443977c22cd6')
104      if respond.status_code == 200:
105          content = respond.json()['files']['tidal-api-key.json']['content']
106          __API_KEYS__ = json.loads(content)
107  except:
108      pass