示例#1
0
    def _getTokenFromAPI(self):
        headers = {'user-agent': userAgent, 'Host': baseApi.split('/')[2]}
        r = requests.get(f'{baseApi}/oauth/getApiToken', headers=headers)
        wwwAuth = r.headers['WWW-Authenticate']

        realm = re.compile('Digest realm="(.+?)"',
                           re.DOTALL).findall(wwwAuth)[0]
        qop = re.compile('qop="(.+?)"', re.DOTALL).findall(wwwAuth)[0]
        nonce = re.compile('nonce="(.+?)"', re.DOTALL).findall(wwwAuth)[0]
        uri = f'{baseApi}/oauth/getApiToken'
        nonceCount = '00000002'
        cnonce = ''.join(
            random.choice(string.ascii_lowercase + string.digits)
            for _ in range(16))

        HA1 = hashlib.md5(
            f'{self.API_CLIENT_ID}:{realm}:{self.API_CLIENT_KEY}').hexdigest()
        HA2 = hashlib.md5(f'GET:{uri}').hexdigest()
        response = hashlib.md5(
            f'{HA1}:{nonce}:{nonceCount}:{cnonce}:{qop}:{HA2}').hexdigest()

        headers[
            'authorization'] = f'Digest username="******", realm="{realm}", nonce="{nonce}", uri="{uri}", response="{response}", opaque="null", qop={qop}, nc={nonceCount}, cnonce="{cnonce}"'

        j = requests.get(f'{baseApi}/oauth/getApiToken',
                         headers=headers).json()

        token = j['apiToken'].encode('utf-8')
        lm4utils.f_mkdir(lm4utils.pathUserdata(''))
        lm4utils.f_write(lm4utils.pathUserdata('token'), token)
        return token
示例#2
0
	def _getU(self,url,Menu=False):
		token = lm4utils.f_open(lm4utils.pathUserdata('token'))
		if token == '':
			token = self._getToken()
		header = {'Api-Auth': f'Bearer {token}', 'Accept-Encoding': 'gzip, deflate'}
		response = requests.get(url,headers=header)
		if response.status_code == 404 or response.text == '':
			token = lm4utils.f_open(lm4utils.pathUserdata('token'))
			header = {'Api-Auth': f'Bearer {token}', 'Accept-Encoding': 'gzip, deflate'}
			response = requests.get(url,headers=header)
		return response.text
示例#3
0
def webvtt2Srt(url):
    webvtt = requests.get(url).text
    webvtt = webvtt.replace('\r', '')
    s = webvtt.split('\n\n')
    i = 1
    if s[1].strip() == '':
        i = 2
    srt = ''
    n = 1
    while i < len(s):
        j = 0
        for line in s[i].split('\n'):
            if j == 0:
                srt += f'{str(n)}\n'
                n += 1

            if j == 1:
                t = line.split('-->')
                srt += t[0].strip().replace(
                    '.', ',') + ' --> ' + t[1].strip().replace('.', ',') + '\n'

            if j > 1:
                for bracket in bracketLookup:
                    line = line.replace(bracket, bracketLookup[bracket])
                srt += line + '\n'
            j += 1
        srt += '\n'
        i += 1

    subFile = lm4utils.pathUserdata('/webvtt.srt')
    lm4utils.f_write(subFile, srt)
    return subFile
示例#4
0
 def getAZ(self,
           uri='/content/documents/sendungen-100.json?contentTypes=teaser'):
     response = self._getU(self.baseApi + uri, True)
     lm4utils.f_write(lm4utils.pathUserdata('response.json'), response)
     j = json.loads(response)
     letters = {}
     l = []
     for brand in j['brand']:
         if 'title' in brand:
             if 'teaser' in brand:
                 for teaser in brand['teaser']:
                     target = teaser['http://zdf.de/rels/target']
                     self._grepItem(target)
     return self.result
示例#5
0
 def _getU(self, url, Menu=False):
     try:
         header = {
             'Api-Auth':
             'Bearer ' + lm4utils.f_open(lm4utils.pathUserdata('token')),
             'Accept-Encoding':
             'gzip, deflate'
         }
         response = requests.get(url, headers=header).text
     except:
         if tokenUrl:
             header = {
                 'Api-Auth': 'Bearer ' + self._getTokenFromUrl(),
                 'Accept-Encoding': 'gzip, deflate'
             }
         else:
             header = {
                 'Api-Auth': 'Bearer ' + self._getTokenFromAPI(),
                 'Accept-Encoding': 'gzip, deflate'
             }
         response = requests.get(url, headers=header).text
     return response
示例#6
0
 def _getTokenFromUrl(self):
     r = requests.get(tokenUrl)
     token = r.json()['token'].encode('utf-8')
     lm4utils.f_mkdir(lm4utils.pathUserdata(''))
     lm4utils.f_write(lm4utils.pathUserdata('token'), token)
     return token