def _get_html(url): user_agent = random_user_agent() try: return session.get(url, headers={'User-Agent': user_agent}).text except Exception as e: return session.get(url, verify=False, headers={ 'User-Agent': user_agent }).text
def get_author(author_id): """ Args: author_id: Returns: """ url = Librivox.authors_url % ("id=" + str(author_id), ) json_data = session.get(url).json()["authors"] return BookAuthor(from_data=json_data[0])
def scrap_all_audiobooks(cls, limit=2000, offset=0): """ Generator, yields LibrivoxAudioBook objects Args: limit: offset: """ url = cls.base_url % \ ("limit=" + str(limit) + "offset=" + str(offset) + "&extended=1") json_data = session.get(url).json()['books'] for k in json_data: yield LibrivoxAudioBook(from_data=json_data[k])
def get_audiobook(book_id): """ Args: book_id: Returns: LibrivoxAudioBook """ url = Librivox.base_url % ("id=" + str(book_id), ) json_data = session.get(url).json()['books'] return LibrivoxAudioBook(from_data=json_data[0])
def _request(url, params=None, user_agent=None): params = params or {} try: user_agent = user_agent or random_user_agent() response = session.get(url, params=params, headers={ 'User-Agent': user_agent, "Accept-Language": "en-US,en;q=0.5" }) except Exception as e: print(e) raise return response.text
def search_audiobooks(cls, since=None, author=None, title=None, tag=None, limit=25): """ Args: since: a UNIX timestamp; returns all projects cataloged since that time author: all records by that author last name title: all matching titles tag: all projects of the matching tag Returns: list : list of LibrivoxAudioBook objects """ searchterm = [] if limit: # TODO validate searchterm.append("limit=" + str(limit)) if since: # TODO validate searchterm.append("since=" + since) if author: searchterm.append("author=" + author) if title: searchterm.append("title=" + title) if tag: # TODO validate searchterm.append("tag=" + tag) if not searchterm: raise TypeError searchterm = "&".join(searchterm) url = cls.base_url % (searchterm, ) json_data = session.get(url).json() if "error" in json_data: return [] return [LibrivoxAudioBook(from_data=a) for a in json_data["books"]]
def get_author(cls, author_id): url = cls.authors_url % ("id=" + str(author_id), ) json_data = session.get(url).json()["authors"] return BookAuthor(from_data=json_data[0])
def get_audiobook(cls, book_id): url = cls.base_url % ("id=" + str(book_id), ) json_data = session.get(url).json()['books'] return LibrivoxAudioBook(from_data=json_data[0])