from bs4 import BeautifulSoup
from typing import List
import re


def get_track_urls(soup: BeautifulSoup) -> List[str]:
    """
    Returns list of URLs for audio tracks

    :param soup: page content
    :returns: list with URLs for audio tracks
    """
    script_with_mp3 = None

    # Iterate over <script>s and find the right one
    scripts = soup.find_all('script')
    for script in scripts:
        if script.string is not None and script.string.find("mp3") != -1:
            script_with_mp3 = script.string

    if script_with_mp3 is None:
        raise Exception('Track URLs were not found!')

    # Find all URLs with mp3s
    results = re.findall('https:.*?mp3', script_with_mp3)

    track_urls = []
    for result in results:
        if not result.endswith(r'\/0.mp3'):
            track_urls.append(result.replace('\\', ''))

    if len(track_urls) == 0:
        raise Exception('Track URLs were not found!')

    return track_urls