src/syncabook/download_files.py
def download_files(librivox_url, output_dir, skip_text=False, skip_audio=False):
    """
    Downloads files needed to create an ebook.

    The downloading process looks as follows:
    Download files from the synclibrivox repository.
    If a book is not found there, download plaintext transcript from gutenberg.org.
    Download audio files from librivox.org.
    """
    os.makedirs(output_dir, exist_ok=True)

    with urllib.request.urlopen(librivox_url) as f:
        librivox_soup = BeautifulSoup(f.read(), 'lxml')

    if not skip_text:
        found = _download_synclibrivox_files(librivox_url, output_dir)
        if not found:
            print(
                f'❗ The synclibrivox repository doesn\'t contain this book.\n'
                'Downloading text from gutenberg.org...'
            )
            gutenberg_link = librivox_soup.find(
                'a', {'href': re.compile(r'http://www.gutenberg.org/.*')}
            )
            if gutenberg_link is None:
                print('❗ Link to the gutenberg.org is not found. Text won\'t be downloaded.')
            else:
                gutenberg_url = gutenberg_link['href']
                _download_gutenberg_text(gutenberg_url, output_dir)

    if not skip_audio:
        print('Downloading audio files...')
        audiobook_url = librivox_soup.find('a', class_='book-download-btn')['href']
        _download_audio_files(audiobook_url, output_dir)

    Downloads files needed to create an ebook.

    The downloading process looks as follows:
    Download files from the synclibrivox repository.
    If a book is not found there, download plaintext transcript from gutenberg.org.
    Download audio files from librivox.org.
    
Downloads files needed to create an ebook.
The downloading process looks as follows:
Download files from the synclibrivox repository.
If a book is not found there, download plaintext transcript from gutenberg.org.
Download audio files from librivox.org.
Downloads files needed to create an ebook . The downloading process looks as follows : Download files from the synclibrivox repository . If a book is not found there download plaintext transcript from gutenberg . org . Download audio files from librivox . org .
def download_files(librivox_url, output_dir, skip_text=False, skip_audio=False):
    os.makedirs(output_dir, exist_ok=True)
    with urllib.request.urlopen(librivox_url) as f:
        librivox_soup = BeautifulSoup(f.read(), 'lxml')
    if not skip_text:
        found = _download_synclibrivox_files(librivox_url, output_dir)
        if not found:
            print(
                f'❗ The synclibrivox repository doesn\'t contain this book.\n'
                'Downloading text from gutenberg.org...'
            )
            gutenberg_link = librivox_soup.find(
                'a', {'href': re.compile(r'http://www.gutenberg.org/.*')}
            )
            if gutenberg_link is None:
                print('❗ Link to the gutenberg.org is not found. Text won\'t be downloaded.')
            else:
                gutenberg_url = gutenberg_link['href']
                _download_gutenberg_text(gutenberg_url, output_dir)
    if not skip_audio:
        print('Downloading audio files...')
        audiobook_url = librivox_soup.find('a', class_='book-download-btn')['href']
        _download_audio_files(audiobook_url, output_dir)
def download_files ( librivox_url , output_dir , skip_text = False , skip_audio = False ) : os . makedirs ( output_dir , exist_ok = True ) with urllib . request . urlopen ( librivox_url ) as f : librivox_soup = BeautifulSoup ( f . read ( ) , 'lxml' ) if not skip_text : found = _download_synclibrivox_files ( librivox_url , output_dir ) if not found : print ( f'❗ The synclibrivox repository doesn\'t contain this book.\n' 'Downloading text from gutenberg.org...' ) gutenberg_link = librivox_soup . find ( 'a' , { 'href' : re . compile ( r'http://www.gutenberg.org/.*' ) } ) if gutenberg_link is None : print ( '❗ Link to the gutenberg.org is not found. Text won\'t be downloaded.') else : gutenberg_url = gutenberg_link [ 'href' ] _download_gutenberg_text ( gutenberg_url , output_dir ) if not skip_audio : print ( 'Downloading audio files...' ) audiobook_url = librivox_soup . find ( 'a' , class_ = 'book-download-btn' ) [ 'href' ] _download_audio_files ( audiobook_url , output_dir )
Downloads files needed to create an ebook.
Downloads files needed to create an ebook .
"""
    Downloads files needed to create an ebook.

    The downloading process looks as follows:
    Download files from the synclibrivox repository.
    If a book is not found there, download plaintext transcript from gutenberg.org.
    Download audio files from librivox.org.
    """
librivox_url
output_dir
skip_text
skip_audio