Closed gboudreau closed 7 years ago
The claims queries seems to be duplicated:
2 DEBUG:requests.packages.urllib3.connectionpool:https://services.radio-canada.ca:443 "GET /media/validation/v2/?deviceType=iphone4&idMedia=126337&output=json&appCode=toutv&connectionType=wifi&claims=... HTTP/1.1" 200 400
2 DEBUG:requests.packages.urllib3.connectionpool:https://services.radio-canada.ca:443 "GET /media/validation/v2/GetClaims?token=... HTTP/1.1" 200 388
It looks like they are fetched for every request by the Auth object (in auth.py). I suppose that we could save the result of the first request for the other ones?
Yes, did that. And same for playlist and cookies in Episode. And will try to check for the local file existence before the other two API calls; I doubt that is needed...
End result:
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): services.radio-canada.ca
DEBUG:requests.packages.urllib3.connectionpool:https://services.radio-canada.ca:443 "GET /media/validation/v2/GetClaims?token=d3a90209-8d0a-449d-b920-6573cf8a90cc HTTP/1.1" 200 388
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): services.radio-canada.ca
DEBUG:requests.packages.urllib3.connectionpool:https://services.radio-canada.ca:443 "GET /media/validation/v2/?deviceType=iphone4&appCode=toutv&output=json&claims=FF991AC02DA2277DD55C46CECC7BD2D8A51A9B3845611C3F229F6C5D4AF2B755A7C245A4EB9AD090F56CB9A765EAD68AAC638751CE90500AC51F09445E90029918637AB59692D0B3D292ABDDC09A8AD698366AC306585D42152350C03A2AE7E8AB61E41F1A6CFE65359E91A8568F4C58C7BF3F0DF020919149AAC6F190971078&idMedia=126970&connectionType=wifi HTTP/1.1" 200 392
DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): toutvuniver1-vh.akamaihd.net
DEBUG:requests.packages.urllib3.connectionpool:https://toutvuniver1-vh.akamaihd.net:443 "GET /i/012/mp4/r/2017-01-07_07_59_40_rangerrob_0003_,500,800,1200,2000,3000,.mp4.csmil/master.m3u8?hdnea=st=1484597202~exp=1484597267~acl=/i/012/mp4/r/2017-01-07_07_59_40_rangerrob_0003_*~hmac=1d55416a8bc16c316085d5370a227dab03733e37542cf8a844320b37bfcf2862 HTTP/1.1" 200 2587
DEBUG:Downloader:starting download
DEBUG:FilesystemSegmentHandler:episode: Épisode 03 (2425170576)
DEBUG:FilesystemSegmentHandler:bitrate: 561000
DEBUG:FilesystemSegmentHandler:output path: /Users/gb/git/pytoutv/toutvcli/Ranger.Rob.S01E03.Épisode.03.561kbps.ts
DEBUG:FilesystemSegmentHandler:overwrite: False
And the Claims API call will not be repeated until the app is restarted, so trying to download multiple episodes will only call that API endpoint once.
What was previously 405 API calls to try to see if any new episodes of a few different shows were now available is now 100 API calls! Hooray.
Wow, that's significant! Depending on the number of episodes, 100 still sounds quite a lot.
It's two API calls per episode: one to get the playlist URL and cookies, and the other one to load that playlist, to get the available qualities. Plus three API calls only executed on start, to load all shows, the specified show, and get the claims.
It looks like we do too many API calls when trying to download episodes, especially when logged in.
There's a few API calls that are exactly the same that I'm pretty sure we could skip, while others are very similar, and I'll try to validate if they can be skipped.
Verbose log: