From 7c76269acfd6013475473a07650b1e0eafa72187 Mon Sep 17 00:00:00 2001 From: girst Date: Mon, 26 Oct 2020 23:04:48 +0100 Subject: [PATCH] clean up broken-youtube-response handling --- app/browse/lib.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/app/browse/lib.py b/app/browse/lib.py index 396a7d5..a98a04e 100644 --- a/app/browse/lib.py +++ b/app/browse/lib.py @@ -17,14 +17,12 @@ def fetch_searchresults(q=None, sp=None): return None # Sometimes, youtube throws an exception after the response already begun. - # So the status code is 200, begins with JSON and switches to HTML half way - # through. WTF?! (This should be "fixed" by retrying, though) - if r.text.endswith(""): - continue # will return None once we break out of the loop - - # XXX: 2020-10-21: caught a youtube-response that just stopped mid-way through. - # response.text == '[\r\n{"page": "search","rootVe": "4724"},\r\n{"page": "search",' - + # This can manifest in two ways: + # 1) So the status code is 200, begins with JSON and switches to HTML half + # way through. WTF?! (This should be "fixed" by retrying, though) + # 2) The response just stopping mid-way through like this: response.text == + # '[\r\n{"page": "search","rootVe": "4724"},\r\n{"page": "search",' + # hence, just try-catching the decoding step is the easiest way out. try: return r.json() except: -- 2.39.3