diff options
author | James Taylor <user234683@users.noreply.github.com> | 2018-09-15 17:53:44 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2018-09-15 17:53:44 -0700 |
commit | 3de6c50c67f44df5e72196b2f0b060c27d36c185 (patch) | |
tree | 7d941cfdbdd4711e7d5a0b2c54d95b084628a881 /youtube/common.py | |
parent | 182c6c7c8ab559aead9adb578ea54ff8a69c94f5 (diff) | |
download | yt-local-3de6c50c67f44df5e72196b2f0b060c27d36c185.tar.lz yt-local-3de6c50c67f44df5e72196b2f0b060c27d36c185.tar.xz yt-local-3de6c50c67f44df5e72196b2f0b060c27d36c185.zip |
Check whether comment posting was successful
Diffstat (limited to 'youtube/common.py')
-rw-r--r-- | youtube/common.py | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/youtube/common.py b/youtube/common.py index 912cceb..76fd7c3 100644 --- a/youtube/common.py +++ b/youtube/common.py @@ -137,6 +137,16 @@ medium_channel_item_template = Template(''' </div> ''') +def decode_content(content, encoding_header): + encodings = encoding_header.replace(' ', '').split(',') + for encoding in reversed(encodings): + if encoding == 'identity': + continue + if encoding == 'br': + content = brotli.decompress(content) + elif encoding == 'gzip': + content = gzip.decompress(content) + return content def fetch_url(url, headers=(), timeout=15, report_text=None): if isinstance(headers, list): @@ -159,14 +169,7 @@ def fetch_url(url, headers=(), timeout=15, report_text=None): read_finish = time.time() if report_text: print(report_text, ' Latency:', response_time - start_time, ' Read time:', read_finish - response_time) - encodings = response.getheader('Content-Encoding', default='identity').replace(' ', '').split(',') - for encoding in reversed(encodings): - if encoding == 'identity': - continue - if encoding == 'br': - content = brotli.decompress(content) - elif encoding == 'gzip': - content = gzip.decompress(content) + content = decode_content(content, response.getheader('Content-Encoding', default='identity')) return content mobile_user_agent = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1' |