def _generate_audio_file(self): """ Generic method used as a Callback in TTSModule - must provided the audio file and write it on the disk .. raises:: FailToLoadSoundFile """ # Prepare payload payload = self.get_payload() # Get the mp3 URL from the page url = Acapela.get_audio_link(TTS_URL, payload) # getting the mp3 r = requests.get(url, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC) content_type = r.headers['Content-Type'] logger.debug( "Acapela : Trying to get url: %s response code: %s and content-type: %s", r.url, r.status_code, content_type) # Verify the response status code and the response content type if r.status_code != requests.codes.ok or content_type != TTS_CONTENT_TYPE: raise FailToLoadSoundFile( "Acapela : Fail while trying to remotely access the audio file" ) # OK we get the audio we can write the sound file FileManager.write_in_file(self.file_path, r.content)
def _generate_audio_file(self): """ Generic method used as a Callback in TTSModule - must provided the audio file and write it on the disk .. raises:: FailToLoadSoundFile """ payload = self.get_payload(self.voice, self.words) # getting the mp3 r = requests.get(TTS_URL, params=payload, stream=True, timeout=TTS_TIMEOUT_SEC) content_type = r.headers['Content-Type'] logger.debug( "Voxygen : Trying to get url: %s response code: %s and content-type: %s", r.url, r.status_code, content_type) if r.status_code == requests.codes.ok and content_type == TTS_CONTENT_TYPE: FileManager.write_in_file(self.file_path, r.content) else: logger.debug( "Unable to get a valid audio file. Returned code: %s" % r.status_code)
def get_audio(file_path, cache, payload, url, content_type_expected=TTS_CONTENT_TYPE, timeout_expected=TTS_TIMEOUT_SEC): if not cache or not os.path.exists( file_path) or FileManager.file_is_empty(file_path): r = requests.get(url, params=payload, stream=True, timeout=timeout_expected) content_type = r.headers['Content-Type'] logger.debug( "Trying to get url: %s response code: %s and content-type: %s", r.url, r.status_code, content_type) try: if r.status_code == requests.codes.ok and content_type == content_type_expected: return FileManager.write_in_file(file_path, r.content) else: return False except IOError as e: logger.error("I/O error(%s): %s", e.errno, e.strerror) except ValueError: logger.error("Could not convert data to an integer.") except: logger.error("Unexpected error: %s", sys.exc_info()[0]) else: return True
def __init__(self, url, headless=True): Scraper.__init__( self, browser=Browser(headless=headless).browser, url=url, xpath_expressions={ 'total_episodes': '//a[@class="numbers"][last()]/text()' }, ) file_name = self.url_parts.path.split('/')[1] FileManager.__init__(self, folder_name=self.url_parts.netloc, file_name=f'{file_name}.json')
def __init__(self, url, headless=True): Scraper.__init__( self, browser=Browser(headless=headless).browser, url=url, xpath_expressions={ 'total_episodes': '//ul[@id="episodeList"]/li[@class="fa-play-circle"][1]/a/p/text()' }, ) FileManager.__init__( self, folder_name=self.url_parts.netloc, file_name=f'{self.url_parts.path.replace("/anime/", "")}.json')
from core import FileManager from properties import FM_PATH fm = FileManager(FM_PATH) print("Current path: ", fm.get_curr_dir()) while True: command = input(">>> ") if command.split(' ')[0] == "make_dir": new_dir = command.split(' ')[1] fm.make_dir(new_dir) elif command.split(' ')[0] == "del_dir": dirname = command.split(' ')[1] fm.del_dir(dirname) elif command.split(' ')[0] == "ch_dir": dirname = command.split(' ')[1] fm.ch_dir(dirname) elif command.split(' ')[0] == "make_file": filename = command.split(' ')[1] fm.make_file(filename) elif command.split(' ')[0] == "write_file": filename = command.split(' ')[1] text = ' '.join(command.split(' ')[2:]) fm.write_file(filename, text) elif command.split(' ')[0] == "read_file": filename = command.split(' ')[1]