# Buggy code
def _get_link(self, soup):
    """
    Matches something like
    f("MTE2MDIw&title=Yakusoku+no+Neverland");
    """
    sources_regex = r'>\s*?f\("(.*?)"\);'
    sources_url = re.search(sources_regex, str(soup)).group(1)
    sources_json = helpers.get(
        f"https://vidstreaming.io/ajax.php?id={sources_url}", referer=self.url
    ).json()

    logger.debug("Sources json: {}".format(str(sources_json)))
    """
        Maps config vidstreaming sources to json results.
        When adding config in the future make sure "vidstream"
        is in the name in order to pass the check above.
        """
    sources_keys = {"vidstream": "source", "vidstream_bk": "source_bk"}

    """
        Elaborate if statements to get sources_json["source"][0]["file"]
        based on order in config.
        """

    servers = Config._read_config()["siteconfig"]["vidstream"]["servers"]
    print(sources_json["source"][0]["file"])
    for i in servers:
        if i in sources_keys:
            if sources_keys[i] in sources_json:
                if "file" in sources_json[sources_keys[i]][0]:
                    return {
                        "stream_url": sources_json[sources_keys[i]][0]["file"],
                        "referer": self.url,
                    }

    return {"stream_url": ""}


# Traceback (AttributeError)
2020-08-22 13:17:39 arch anime_downloader.session[11021] DEBUG uncached request
2020-08-22 13:17:39 arch anime_downloader.sites.helpers.request[11021] DEBUG https://vidstreaming.io/load.php?id=NDkyNzA=&amp;title=Ansatsu+Kyoushitsu&amp;typesub=SUB&amp;sub=eyJlbiI6bnVsbCwiZXMiOm51bGx9&amp;cover=aW1hZ2VzL3VwbG9hZC82NDU5NS5qcGc=
2020-08-22 13:17:39 arch anime_downloader.sites.helpers.request[11021] DEBUG /tmp/animedlbudirp9b/tmppc8povqh
2020-08-22 13:17:39 arch anime_downloader.extractors.vidstream[11021] DEBUG Linkserver: []
Traceback (most recent call last):
File "/home/bl/.local/bin/anime", line 8, in <module>
sys.exit(main())
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/cli.py", line 53, in main
cli()
File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/bl/.local/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/home/bl/.local/lib/python3.8/site-packages/click/decorators.py", line 21, in new_func
return f(get_current_context(), *args, **kwargs)
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/commands/dl.py", line 120, in command
for episode in animes:
File "/home/bl/.local/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 "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 293, in __init__
try_data()
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/sites/anime.py", line 291, in try_data
self.source().stream_url
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/base_extractor.py", line 29, in stream_url
self.get_data()
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/base_extractor.py", line 41, in get_data
data = self._get_data()
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/vidstream.py", line 43, in _get_data
return self._get_link(soup)
File "/home/bl/.local/lib/python3.8/site-packages/anime_downloader/extractors/vidstream.py", line 63, in _get_link
sources_url = re.search(sources_regex,str(soup)).group(1)
AttributeError: 'NoneType' object has no attribute 'group'

# Fixed code
def _get_link(self, soup):
    # Gets:
    # <input type="hidden" id="id" value="MTEyMzg1">
    # <input type="hidden" id="title" value="Yakusoku+no+Neverland">
    # <input type="hidden" id="typesub" value="SUB">
    # Used to create a download url.
    soup_id = soup.select("input#id")[0]["value"]
    soup_title = soup.select("input#title")[0]["value"]
    soup_typesub = soup.select("input#typesub")[0].get("value", "SUB")

    sources_json = helpers.get(
        f"https://vidstreaming.io/ajax.php",
        params={
            "id": soup_id,
            "typesub": soup_typesub,
            "title": soup_title,
        },
        referer=self.url,
    ).json()

    logger.debug("Sources json: {}".format(str(sources_json)))
    """
        Maps config vidstreaming sources to json results.
        When adding config in the future make sure "vidstream"
        is in the name in order to pass the check above.
        """
    sources_keys = {"vidstream": "source", "vidstream_bk": "source_bk"}

    """
        Elaborate if statements to get sources_json["source"][0]["file"]
        based on order in config.
        """

    servers = Config._read_config()["siteconfig"]["vidstream"]["servers"]

    for i in servers:
        if i in sources_keys:
            if sources_keys[i] in sources_json:
                if "file" in sources_json[sources_keys[i]][0]:
                    return {
                        "stream_url": sources_json[sources_keys[i]][0]["file"],
                        "referer": self.url,
                    }

    return {"stream_url": ""}