# Buggy code
def blocks_r(filename, size=64 * 1024, reset_offset=True, encoding="utf-8"):
    """
    Yields the data within a file in reverse-ordered blocks of given size.

    This code is part of the flyingcircus package: https://pypi.org/project/flyingcircus/
    The code was adapted for our use case.
    All credits go to the original author.

    Note that:
     - the content of the block is NOT reversed.

    Args:
        filename (str): The input file name.
        size (int|None): The block size.
            If int, the file is yielded in blocks of the specified size.
            If None, the file is yielded at once.
        reset_offset (bool): Reset the file offset.
            If True, starts reading from the end of the file.
            Otherwise, starts reading from where the file current position is.
        encoding (str|None): The encoding for correct block size computation.
            If `str`, must be a valid string encoding.
            If None, the default encoding is used.

    Yields:
        block (str): The data within the blocks.

    """
    with io.open(filename, "r", encoding=encoding) as file_obj:
        offset = 0
        if reset_offset:
            file_size = remaining_size = file_obj.seek(0, os.SEEK_END)
        else:
            file_size = remaining_size = file_obj.tell()
        rounding = 0
        while remaining_size > 0:
            offset = min(file_size, offset + size)
            file_obj.seek(file_size - offset)
            block = file_obj.read(min(remaining_size, size))
            remaining_size -= size
            yield block[: len(block) + rounding] if rounding else block


# Traceback (UnicodeDecodeError)
2019-07-09 08:24:58 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', "\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 1080p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '1080p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [", 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=DEBUG&amp;thread=TORNADO&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 0: invalid start byte
2019-07-09 08:22:53 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', "\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ SDTV ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Ignoring found result for 'Barry' S02E01 with unwanted quality 'SDTV'\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.Gears.Media because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 1080p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '1080p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.1080p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Using cached parse result for \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: Allowed, Preferred = [ 720p WEB-DL, 1080p WEB-DL, 720p BluRay, 1080p BluRay ] [ 1080p BluRay ] Found = [ 720p WEB-DL ]\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] 333072: 'Barry' S02E01 status is: 'Downloaded'. Ignoring result with quality '720p WEB-DL'. Reason: New quality is same/lower quality (and not preferred). Ignoring new quality\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY-SEARCH :: [Zooqle] :: [74c3f12] Ignoring \xd0\x91\xd0\xb0\xd1\x80\xd1\x80\xd0\xb8./.Barry.[02x01-07.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.IdeaFilm because one or more episodes are unwanted\n2019-07-09 08:13:14 DEBUG    SEARCHQUEUE-DAILY", 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=WARNING&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb8 in position 0: invalid start byte
2019-07-09 07:55:01 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', '\xb7.13].(2019).WEBRip.720p.|.Kerob is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-04.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Kerob is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.Gears.Media is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-05.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.BigSinema is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.1080p.|.LakeFilms is 1080p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.|.LakeFilms is SDTV\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.LakeFilms is 720p WEB-DL\n2019-07-08 19:49:43 INFO     SEARCHQUEUE-BACKLOG-268592 :: [Zooqle] :: [74c3f12] Quality of \xd0\xa1\xd0\xbe\xd1\x82\xd0\xbd\xd1\x8f./.The.100.[06x01-06.\xd0\xb8\xd0\xb7.13].(2019).WEBRip.720p.|.Gears.Media is 720p WEB-DL\n2019-07-08 19:49:43 INFO    ', 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=ERROR&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info
UnicodeDecodeError: 'utf8' codec can't decode byte 0xb7 in position 0: invalid start byte
2019-07-09 07:54:26 ERROR	TORNADO :: 74c3f12] Uncaught exception in APIv2: UnicodeDecodeError('utf8', '\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip-AVC.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.|.Profix.Media is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-05.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip-AVC.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-04.\xd0\xb8\xd0\xb7.08].(2019).WEB-DLRip.|.\xd0\x9f\xd0\xb8\xd1\x84\xd0\xb0\xd0\xb3\xd0\xbe\xd1\x80 is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.720p.|.OmskBird is 720p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.08].(2019).WEBRip.|.OmskBird is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.|.Profix.Media is SDTV\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5.\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb0./.\xd0\x97\xd0\xb0\xd0\xb3\xd0\xb0\xd0\xb4\xd0\xbe\xd1\x87\xd0\xbd\xd1\x8b\xd0\xb5.\xd1\x81\xd0\xbe\xd0\xb1\xd1\x8b\xd1\x82\xd0\xb8\xd1\x8f./.Stranger.Things.[03x01-03.\xd0\xb8\xd0\xb7.8].(2019).WEBRip.1080p.|.Profix.Media is 1080p WEB-DL\n2019-07-08 20:27:27 INFO     SEARCHQUEUE-BACKLOG-305288 :: [Zooqle] :: [74c3f12] Quality of \xd0\x9e\xd1\x87\xd0\xb5\xd0\xbd\xd1\x8c.\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0', 0, 1, 'invalid start byte')
Request: GET /api/v2/log?level=WARNING&amp;thread=&amp;period=one_day&amp;query=&amp;limit=1000 (24.254.133.76)
Traceback (most recent call last):
File "/home6/**********/.apps/medusa/medusa/ext/tornado/web.py", line 1592, in _execute
result = yield result
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1141, in run
yielded = self.gen.throw(*exc_info)
File "/home6/**********/.apps/medusa/medusa/medusa/server/api/v2/base.py", line 64, in async_call
content = yield IOLoop.current().run_in_executor(executor, prepared)
File "/home6/**********/.apps/medusa/medusa/ext/tornado/gen.py", line 1133, in run
value = future.result()
File "/home6/**********/.apps/medusa/medusa/ext/tornado/concurrent.py", line 261, in result
raise_exc_info(self._exc_info)
File "<string>", line 3, in raise_exc_info

# Fixed code
def blocks_r(file_path, size=64 * 1024):
    """
    Yields the data within a file in reverse-ordered blocks of given size.

    This code is part of the flyingcircus package: https://pypi.org/project/flyingcircus/
    The code was adapted for our use case.
    All credits go to the original author.

    Note that:
     - the content of the block is NOT reversed.

    Args:
        file_path (str): The input file path.
        size (int): The block size.

    Yields:
        block (bytes): The data within the blocks.

    """
    with io.open(file_path, "rb") as file_obj:
        remaining_size = file_obj.seek(0, os.SEEK_END)
        while remaining_size > 0:
            block_size = min(remaining_size, size)
            file_obj.seek(remaining_size - block_size)
            block = file_obj.read(block_size)
            remaining_size -= block_size
            yield block