Created
November 1, 2018 15:28
-
-
Save eliask/64bfa506fb38da80a79df21a34a1015d to your computer and use it in GitHub Desktop.
Extract audio/video parts from a HAR file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import base64 | |
import json | |
def main(path): | |
with open(path, 'rt') as fh: | |
j = json.load(fh) | |
for entry in j['log']['entries']: | |
if not 200 <= entry['response']['status'] < 300: | |
continue | |
content = entry['response']['content'] | |
mime = content['mimeType'] | |
print(entry['request']['url'], mime) | |
if mime.startswith('video/') or mime.startswith('audio/'): | |
yield content | |
if __name__ == '__main__': | |
for i,c in enumerate(main(sys.argv[-1])): | |
assert c['encoding'] == 'base64', c['encoding'] | |
content = base64.b64decode(c['text']) | |
with open('%05d.bin' % i, 'wb') as fh: | |
fh.write(content) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment