Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import getpass
- import requests
- import json
- from subprocess import Popen
- platforms = ['online_wv', 'online', 'android', 'ios']
- clientSecret = 'nZhkFGz8Zd8w'
- apiKey = ''
- username = ''
- password = ''
- payload = {'client_id': 'external', 'client_secret': clientSecret, 'response_type': 'code', 'scopes': []}
- headers = {'content-type': 'application/json', 'apikey': apiKey}
- getAccessCode = requests.post('https://api-viihde-gateway.dc1.elisa.fi/auth/authorize/access-code', json=payload, headers=headers)
- accessCode = json.loads(getAccessCode.text)['code']
- payload = {'grant_type': 'authorization_code', 'username': username, 'password': password, 'client_id': 'external', "code": accessCode}
- headers = {'content-type': 'application/x-www-form-urlencoded', 'apikey': apiKey}
- getAccessToken = requests.post('https://api-viihde-gateway.dc1.elisa.fi/auth/authorize/access-token', data=payload, headers=headers)
- accessToken = json.loads(getAccessToken.text)['access_token']
- def showFormats(recordingId, platform):
- headers = {'Authorization': 'Bearer '+ accessToken, 'apikey': apiKey}
- getRecordingUrl = requests.get('https://api-viihde-gateway.dc1.elisa.fi/rest/npvr/recordings/url/'+recordingId+'?v=2&platform='+platform+'&external&appVersion=1.0', headers=headers)
- recordingUrl = json.loads(getRecordingUrl.text)['url']
- # Popen(cmd).wait()
- file = open(platform + '.txt', 'w')
- file.write(recordingUrl)
- file.write('\n\nyoutube-dl output:\n')
- file.flush()
- cmd = 'youtube-dl -F \"' + recordingUrl + '\"'
- Popen(cmd, stdout=file, stderr=file).wait()
- file.write('\n\n\nstreamlink output:\n')
- file.flush()
- cmd = 'streamlink \"' + recordingUrl + '\"'
- Popen(cmd, stdout=file, stderr=file).wait()
- file.write('\n\n\n')
- file.flush()
- cmd = 'curl -L \"' + recordingUrl + '\"'
- Popen(cmd, stdout=file).wait()
- download = True
- while download == True:
- recording = input('Tallenteen osoite: ')
- recordingSplit = recording.rsplit('/', 1)
- if recordingSplit[0] == 'https://elisaviihde.fi/ohjelmaopas/ohjelma':
- for platform in platforms:
- showFormats(recordingSplit[1], platform)
- else:
- break
- # file.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement