import re


def parse_csfd(csfd):
    """
    Takes value of the ``--csfd`` option, parses it and returns CSFD.cz URL.
    """
    try:
        csfd_id = int(csfd)
    except (TypeError, ValueError):
        match = re.search(r'/film/(\d+)', csfd)
        if not match:
            raise ValueError('Invalid CSFD.cz link or ID: ' + csfd)
        csfd_id = int(match.group(1))
    return 'https://www.csfd.cz/film/{}/'.format(csfd_id)