Guest User

Untitled

a guest
Oct 2nd, 2018
175
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import getpass
  2. import requests
  3. import json
  4. from subprocess import Popen
  5.  
  6. platforms = ['online_wv', 'online', 'android', 'ios']
  7.  
  8. clientSecret = 'nZhkFGz8Zd8w'
  9. apiKey = ''
  10.  
  11. username = ''
  12. password = ''
  13.  
  14. payload = {'client_id': 'external', 'client_secret': clientSecret, 'response_type': 'code', 'scopes': []}
  15. headers = {'content-type': 'application/json', 'apikey': apiKey}
  16. getAccessCode = requests.post('https://api-viihde-gateway.dc1.elisa.fi/auth/authorize/access-code', json=payload, headers=headers)
  17. accessCode = json.loads(getAccessCode.text)['code']
  18.  
  19. payload = {'grant_type': 'authorization_code', 'username': username, 'password': password, 'client_id': 'external', "code": accessCode}
  20. headers = {'content-type': 'application/x-www-form-urlencoded', 'apikey': apiKey}
  21. getAccessToken = requests.post('https://api-viihde-gateway.dc1.elisa.fi/auth/authorize/access-token', data=payload, headers=headers)
  22. accessToken = json.loads(getAccessToken.text)['access_token']
  23.  
  24. def showFormats(recordingId, platform):
  25.     headers = {'Authorization': 'Bearer '+ accessToken,  'apikey': apiKey}
  26.     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)
  27.     recordingUrl = json.loads(getRecordingUrl.text)['url']
  28.     # Popen(cmd).wait()
  29.     file = open(platform + '.txt', 'w')
  30.     file.write(recordingUrl)
  31.     file.write('\n\nyoutube-dl output:\n')
  32.     file.flush()
  33.     cmd = 'youtube-dl -F \"' + recordingUrl + '\"'
  34.     Popen(cmd, stdout=file, stderr=file).wait()
  35.     file.write('\n\n\nstreamlink output:\n')
  36.     file.flush()
  37.     cmd = 'streamlink \"' + recordingUrl + '\"'
  38.     Popen(cmd, stdout=file, stderr=file).wait()
  39.     file.write('\n\n\n')
  40.     file.flush()
  41.     cmd = 'curl -L \"' + recordingUrl + '\"'
  42.     Popen(cmd, stdout=file).wait()
  43.    
  44. download = True
  45. while download == True:
  46.     recording = input('Tallenteen osoite: ')
  47.     recordingSplit = recording.rsplit('/', 1)
  48.     if recordingSplit[0] == 'https://elisaviihde.fi/ohjelmaopas/ohjelma':
  49.         for platform in platforms:
  50.             showFormats(recordingSplit[1], platform)
  51.     else:
  52.         break
  53.        
  54. # file.close()
RAW Paste Data