File indexing completed on 2023-05-30 10:41:17

0001 #!/usr/bin/python3
0002 #
0003 # GCompris - download-assets.py
0004 #
0005 # SPDX-FileCopyrightText: 2016-2018 Johnny Jazeix <jazeix@gmail.com>
0006 #
0007 #   SPDX-License-Identifier: GPL-3.0-or-later
0008 import urllib.request
0009 import shutil
0010 import sys
0011 
0012 # see https://stackoverflow.com/questions/7243750/download-file-from-web-in-python-3/7244263#7244263
0013 def download_file(from_url, output_dir):
0014     file_name = output_dir + "/" + from_url.split('/')[-1]
0015     with urllib.request.urlopen(from_url) as response, open(file_name, 'wb') as out_file:
0016         shutil.copyfileobj(response, out_file)
0017 
0018 # argv[0]: program name
0019 # argv[1]: assets to download (words, full for full rccs, music, locale to get corresponding locale voices)
0020 # argv[2]: audio format (ogg, mp3, aac)
0021 # argv[3]: output directory (rcc directory)
0022 if len(sys.argv) != 4:
0023     print("Usage: download-assets.py \"words,full,music,en,fr,pt_BR\" ogg/mp3/aac outputFolder")
0024     sys.exit(0)
0025 
0026 """Download the voices and words assets depending on the wanted audio format
0027 """
0028 
0029 DOWNLOAD_PATH = "https://cdn.kde.org/gcompris/data2/"
0030 AUDIO_FORMAT = sys.argv[2]
0031 OUTPUT_FOLDER = sys.argv[3]+"/data2/"
0032 
0033 ALL_LANGUAGES = [x.strip() for x in sys.argv[1].split(",") if len(x)]
0034 DOWNLOAD_WORDS = "words" in ALL_LANGUAGES
0035 DOWNLOAD_FULL = "full" in ALL_LANGUAGES
0036 DOWNLOAD_MUSIC = "music" in ALL_LANGUAGES
0037 if DOWNLOAD_WORDS:
0038     ALL_LANGUAGES.remove("words")
0039     download_file(DOWNLOAD_PATH+"words/words.rcc", OUTPUT_FOLDER+"words/")
0040 
0041 if DOWNLOAD_FULL:
0042     ALL_LANGUAGES.remove("full")
0043     download_file(DOWNLOAD_PATH+"full-"+AUDIO_FORMAT+".rcc", OUTPUT_FOLDER)
0044 
0045 if DOWNLOAD_MUSIC:
0046     ALL_LANGUAGES.remove("music")
0047     download_file(DOWNLOAD_PATH+"backgroundMusic/backgroundMusic-"+AUDIO_FORMAT+".rcc", OUTPUT_FOLDER+"backgroundMusic/")
0048 
0049 for lang in ALL_LANGUAGES:
0050     lang_url = DOWNLOAD_PATH+"voices-"+AUDIO_FORMAT+"/voices-"+lang+".rcc"
0051     download_file(lang_url, OUTPUT_FOLDER+"voices-"+AUDIO_FORMAT+"/")