# Buggy code
def search(cls, query):
    results = helpers.get(
        "https://www4.ryuanime.com/search", params={"term": query}
    ).text
    soup = helpers.soupify(results)
    result_data = soup.find("ul", {"class": "list-inline"}).find_all("a")

    search_results = [
        SearchResult(title=result.text, url=result.get("href"))
        for result in result_data
    ]
    return search_results


# Traceback (json.decoder.JSONDecodeError)
matt@matt:~$ anime -ll DEBUG dl 'penguin highway' --provider ryuanime
2020-05-31 19:09:54 matt.local anime_downloader.util[41614] INFO anime-downloader 4.3.0
2020-05-31 19:09:54 matt.local anime_downloader.util[41614] DEBUG Platform: macOS-10.14.6-x86_64-i386-64bit
2020-05-31 19:09:54 matt.local anime_downloader.util[41614] DEBUG Python 3.8.2
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG GET https://www4.ryuanime.com/search
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {'params': {'term': 'penguin highway'}}
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'}
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
send: b'GET /search?term=penguin+highway HTTP/1.1\r\nHost: www4.ryuanime.com\r\nuser-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sun, 31 May 2020 18:09:54 GMT
header: Content-Type: text/html; charset=UTF-8
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Set-Cookie: __cfduid=d4d5081f03f192e51c4b768dc75a28b161590948594; expires=Tue, 30-Jun-20 18:09:54 GMT; path=/; domain=.ryuanime.com; HttpOnly; SameSite=Lax; Secure
header: Set-Cookie: PHPSESSID=r1mgv31e58tbi5e6vu211c3eoj; path=/
header: Expires: Thu, 19 Nov 1981 08:52:00 GMT
header: Cache-Control: no-store, no-cache, must-revalidate
header: Pragma: no-cache
header: CF-Cache-Status: DYNAMIC
header: cf-request-id: 030d861aca00006a0b5586e200000001
header: Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
header: Server: cloudflare
header: CF-RAY: 59c2a60ade546a0b-LHR
header: Content-Encoding: gzip
2020-05-31 19:09:54 matt.local anime_downloader.session[41614] DEBUG uncached request
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG https://www4.ryuanime.com/search?term=penguin+highway
2020-05-31 19:09:54 matt.local anime_downloader.sites.helpers.request[41614] DEBUG /var/folders/sy/jcz9n9dn2t98677rzpmyvkr00000gn/T/animedlg3sh2stl/tmppx3ctpjn
+--------+-----------------+--------+
|      1 | Penguin Highway |        |
|--------+-----------------+--------|
|   SlNo | Title           | Meta   |
+--------+-----------------+--------+
Enter the anime no:  [1]: 1
2020-05-31 19:09:55 matt.local anime_downloader.util[41614] INFO Selected Penguin Highway
2020-05-31 19:09:55 matt.local anime_downloader.sites.anime[41614] INFO Extracting episode info from page
2020-05-31 19:09:55 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
2020-05-31 19:09:55 matt.local anime_downloader.sites.helpers.request[41614] DEBUG GET https://www4.ryuanime.com/anime/3939-penguin-highway
2020-05-31 19:09:55 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {}
2020-05-31 19:09:55 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'}
2020-05-31 19:09:55 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
send: b'GET /anime/3939-penguin-highway HTTP/1.1\r\nHost: www4.ryuanime.com\r\nuser-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nCookie: __cfduid=d4d5081f03f192e51c4b768dc75a28b161590948594; PHPSESSID=r1mgv31e58tbi5e6vu211c3eoj\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sun, 31 May 2020 18:09:56 GMT
header: Content-Type: text/html; charset=UTF-8
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Expires: Thu, 19 Nov 1981 08:52:00 GMT
header: Cache-Control: no-store, no-cache, must-revalidate
header: Pragma: no-cache
header: CF-Cache-Status: DYNAMIC
header: cf-request-id: 030d86201900006a0b55880200000001
header: Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
header: Server: cloudflare
header: CF-RAY: 59c2a613593e6a0b-LHR
header: Content-Encoding: gzip
2020-05-31 19:09:56 matt.local anime_downloader.session[41614] DEBUG uncached request
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG https://www4.ryuanime.com/anime/3939-penguin-highway
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG /var/folders/sy/jcz9n9dn2t98677rzpmyvkr00000gn/T/animedlg3sh2stl/tmplpjqs5fs
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG GET https://www4.ryuanime.com/anime/3939-penguin-highway
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {}
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'}
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
2020-05-31 19:09:56 matt.local anime_downloader.session[41614] DEBUG cached request
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG https://www4.ryuanime.com/anime/3939-penguin-highway
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG /var/folders/sy/jcz9n9dn2t98677rzpmyvkr00000gn/T/animedlg3sh2stl/tmp2rcnd8h1
2020-05-31 19:09:56 matt.local anime_downloader.sites.anime[41614] DEBUG EPISODE IDS: length: 1, ids: ['https://www4.ryuanime.com/anime/watch/189328-penguin-highway-movie-english-sub']
2020-05-31 19:09:56 matt.local anime_downloader.commands.dl[41614] INFO Found anime: Penguin Highway
2020-05-31 19:09:56 matt.local anime_downloader.commands.dl[41614] INFO Downloading to /Users/matt/Downloads/1234_JD
2020-05-31 19:09:56 matt.local anime_downloader.sites.anime[41614] DEBUG Extracting stream info of id: https://www4.ryuanime.com/anime/watch/189328-penguin-highway-movie-english-sub
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG GET https://www4.ryuanime.com/anime/watch/189328-penguin-highway-movie-english-sub
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {}
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG {'user-agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2'}
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG -----
send: b'GET /anime/watch/189328-penguin-highway-movie-english-sub HTTP/1.1\r\nHost: www4.ryuanime.com\r\nuser-agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.2 (KHTML, like Gecko) Chrome/22.0.1216.0 Safari/537.2\r\nAccept-Encoding: gzip, deflate\r\nAccept: */*\r\nConnection: keep-alive\r\nCookie: __cfduid=d4d5081f03f192e51c4b768dc75a28b161590948594; PHPSESSID=r1mgv31e58tbi5e6vu211c3eoj\r\n\r\n'
reply: 'HTTP/1.1 200 OK\r\n'
header: Date: Sun, 31 May 2020 18:09:56 GMT
header: Content-Type: text/html; charset=UTF-8
header: Transfer-Encoding: chunked
header: Connection: keep-alive
header: Expires: Thu, 19 Nov 1981 08:52:00 GMT
header: Cache-Control: no-store, no-cache, must-revalidate
header: Pragma: no-cache
header: CF-Cache-Status: DYNAMIC
header: cf-request-id: 030d86219e00006a0b55887200000001
header: Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
header: Server: cloudflare
header: CF-RAY: 59c2a615ca036a0b-LHR
header: Content-Encoding: gzip
2020-05-31 19:09:56 matt.local anime_downloader.session[41614] DEBUG uncached request
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG https://www4.ryuanime.com/anime/watch/189328-penguin-highway-movie-english-sub
2020-05-31 19:09:56 matt.local anime_downloader.sites.helpers.request[41614] DEBUG /var/folders/sy/jcz9n9dn2t98677rzpmyvkr00000gn/T/animedlg3sh2stl/tmptjy94hcy
Traceback (most recent call last):
File "/usr/local/bin/anime", line 11, in <module>
load_entry_point('anime-downloader==4.3.0', 'console_scripts', 'anime')()
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/cli.py", line 53, in main
cli()
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/commands/dl.py", line 112, in command
for episode in animes:
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 198, in __iter__
yield episode_class(ep_id[1], parent=self, ep_no=ep_id[0])
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 293, in __init__
try_data()
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 289, in try_data
self.get_data()
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 349, in get_data
self._sources = self._get_sources()
File "/usr/local/Cellar/anime-downloader/HEAD-16c6268/libexec/lib/python3.8/site-packages/anime_downloader/sites/ryuanime.py", line 64, in _get_sources
hosts = json.loads(soup.find("div", {"class":"col-sm-9"}).find("script").text[30:-6])
File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/opt/python@3.8/Frameworks/Python.framework/Versions/3.8/lib/python3.8/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
matt@matt:~$

# Fixed code
def search(cls, query):
    soup = helpers.soupify(
        helpers.get("https://www4.ryuanime.com/search", params={"term": query})
    )
    result_data = soup.select("ul.list-inline")[0].select("a")

    search_results = [
        SearchResult(title=result.text, url=result.get("href"))
        for result in result_data
    ]
    return search_results