Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating test cases #74

Merged
merged 8 commits into from
Nov 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 11 additions & 29 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,32 @@
# Use the latest 2.1 version of CircleCI pipeline process engine.
# See: https://circleci.com/docs/2.0/configuration-reference
version: 2.1

# Orbs are reusable packages of CircleCI configuration that you may share across projects, enabling you to create encapsulated, parameterized commands, jobs, and executors that can be used across multiple projects.
# See: https://circleci.com/docs/2.0/orb-intro/
orbs:
# The python orb contains a set of prepackaged CircleCI configuration you can use repeatedly in your configuration files
# Orb commands and jobs help you with common scripting around a language/tool
# so you dont have to copy and paste it everywhere.
# See the orb documentation here: https://circleci.com/developer/orbs/orb/circleci/python
python: circleci/python@1.5.0
codecov: codecov/codecov@3.0.0


# Define a job to be invoked later in a workflow.
# See: https://circleci.com/docs/2.0/configuration-reference/#jobs
jobs:
build-and-test: # This is the name of the job, feel free to change it to better match what you're trying to do!
# These next lines defines a Docker executors: https://circleci.com/docs/2.0/executor-types/
# You can specify an image from Dockerhub or use one of the convenience images from CircleCI's Developer Hub
# A list of available CircleCI Docker convenience images are available here: https://circleci.com/developer/images/image/cimg/python
# The executor is the environment in which the steps below will be executed - below will use a python 3.10.2 container
# Change the version below to your required version of python
build-and-test:
docker:
- image: cimg/python:3.10.2
# Checkout the code as the first step. This is a dedicated CircleCI step.
# The python orb's install-packages step will install the dependencies from a Pipfile via Pipenv by default.
# Here we're making sure we use just use the system-wide pip. By default it uses the project root's requirements.txt.
# Then run your tests!
# CircleCI will report the results back to your VCS provider.
steps:
- checkout
- run: python --version
- run: sudo apt-get update
- run: sudo apt install libespeak-dev
- python/install-packages:
pkg-manager: pip
# app-dir: ~/project/package-directory/ # If you're requirements.txt isn't in the root directory.
# pip-dependency-file: test-requirements.txt # if you have a different name for your requirements file, maybe one that combines your runtime and test requirements.
- run:
name: Run tests
# This assumes pytest is installed via the install-package step above
command: pytest
codecov:
docker:
# replace with your preferred image
- image: cimg/base:stable
steps:
- codecov/upload

# Invoke jobs via workflows
# See: https://circleci.com/docs/2.0/configuration-reference/#workflows
workflows:
run_test_cases: # This is the name of the workflow, feel free to change it to better match your workflow.
# Inside the workflow, you define the jobs you want to run.
run_test_cases:
jobs:
- build-and-test
- codecov
6 changes: 0 additions & 6 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@ labels: bug
assignees: ''

---
**Are you using latest code**

**Describe the bug**
A clear and concise description of what the bug is.


**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Pythonversion**
- Python version

Expand Down
13 changes: 2 additions & 11 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@

# Pull Request Template

**script name** -

**What have you Changed**

what you changed in the codebase.write here


### Issue no.(must) - #

### Self Check(Tick After Making pull Request)

- [ ] This issue was assigned to me.
- [x] One Change in one Pull Request
- [x] My file is in proper folder
- [x] I am following clean code and Documentation and my code is well linted with flake8.
- [ ] I have added README.md and requirements.txt with my script

If issue was not assigned to you Please don't make a PR. It will marked as invalid.
- [ ] One Change in one Pull Request
- [ ] I am following clean code and Documentation and my code is well linted with flake8.

Join Us on Discord:- https://discord.gg/JfbK3bS
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ All notable changes to this project will be documented in this file. The format
## Proposed Changes/features

- [x] Search book in the library
- [x] Delete book from the library
- [x] Delete book from the library
- [x] Cythonize the code

## [V2.0.4]
## [V2.0.4] - 01-11-2022

- [x] Extended pdf_parser to extract table of contents
- [x] Command line Support added
- [x] Updated test cases
- [x] Added support for CircleCi CI/CD
- [x] Added support for CircleCi CI/CD

## [V2.0.3]

Expand Down
127 changes: 9 additions & 118 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
<h2 align="center">👉 CLI tool to listen to your favourite book in Python 👈</h2>
</p>

![](https://circleci.com/gh/pycontributors/audiobook.svg?style=svg)

![CircleCI](https://circleci.com/gh/circleci/circleci-docs.svg?style=svg)

<p align="center">
<img src="https://img.shields.io/badge/Python-3.8.5-lightgrey?style=for-the-badge" alt="repo language">
<a href="https://github.com/py-contributors/audiobook/stargazers"><img src="https://img.shields.io/github/stars/py-contributors/audiobook?style=for-the-badge" alt="github stars"></a>
Expand Down Expand Up @@ -30,71 +34,10 @@ Install using [pypi](https://pypi.org/project/audiobook/)
pip install audiobook
```

## Usages

The audiobook is a python module for listening to your favourite PDF (and not only) book.

Basic usage is exposed via CLI, type `python audiobook -h` for help.

More advanced features are exposed via the API:

```bash
usage: audiobook [-h] [-p [PATH]] [-l | -c | -s | -r]

AudioBook - listen to any PDF book

optional arguments:
-h, --help show this help message and exit
-p [PATH], --path [PATH]
book file path
-l, --library get all books in library
-c, --create-json create json file from input file
-s, --save-audio save audio files from input file
-r, --read-book read the book from input file
```

#### Example

```bash
# to read the book
audiobook -p "C:\Users\user\Documents\book.pdf" -r
```

```bash
# to create json file
audiobook -p "C:\Users\user\Documents\book.pdf" -c
```

```bash
# to save audio files
audiobook -p "C:\Users\user\Documents\book.pdf" -s
```

```bash
# to get all books in library
audiobook -l
```


```python
from audiobook import AudioBook
# argument: Speech-Speed="slow/normal/fast", volume = 0.0 to 1.0
ab = AudioBook(speed="normal", volume=1.0)

# if file is password protected, pass password as argument
# save_page_wise audio/whole book in one mp3 file
ab.save_audio(self, input_book_path, password=None, save_page_wise=False):

- input_book_path: path to pdf file
- password: password to pdf file
- save_page_wise: if True, saves each page as a separate mp3 file
- extraction_engine: "pypdf2/pdfminor" for extracting text from pdf file
## Documentation

ab.read_book(file_path) # listen to the book
ab.create_json_book(file_path) # create json file of the book
Check the full documentation here:- [Read the docs](https://pycontributors.readthedocs.io/projects/Audiobook/en/latest/)

ab.get_library() # get all the books in your library
```

## Supported File Formats

Expand All @@ -108,66 +51,14 @@ ab.get_library() # get all the books in your library
| DOCX | :white_check_mark: | not required |
| ODT | :white_check_mark: | not required |

## Test

Run tests:

```sh
pip install -r requirements.txt
python -m unittest tests
```

## Documentation

Read Detailed [Documentation here](https://audiobook.readthedocs.io/)

### Linux Installation Requirements

- If you are using a Linux system and the voice output is not working, then :
Install espeak , ffmpeg and libespeak1 as shown below:

```sh
sudo apt update && sudo apt install espeak ffmpeg libespeak1
```

## Roadmap
## Changelog and Release Notes

- Speech-Speed Control
- Support more extensions
- Save the audiobook for future
Check the changelog and release notes [here](/CHANGELOG.md)

## Project status

This project is currently in development. Any contributions are welcome.

## Changelog

**V2.0.2**

- [x] Docs files support added
- [x] Pdfminor as engine added
- [x] ODT file support added

**V2.0.1**

- [x] Mobi file support
- [x] Epub file support
- [x] User can now save the audiobook for future
- [x] User can now listen to the book from the library

**V2.0.0**

- [x] Save Audio Book locally
- [x] Listen to the book
- [x] Speech-speed control
- [x] Read password-protected PDF
- [x] Create JSON file for the book

** Upcoming changes**

- [ ] Change the voice of the narrator
- [ ] Support more extensions

This project is currently in development. contributions are welcome.

## Author

Expand Down
7 changes: 1 addition & 6 deletions assets/output.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
{
"txt": {"0": "this is a sample file"},
"pdf": {"0": "this is a sample file"},
"epub": {"0": "this is a sample file"},
"odt": {"0": "this is a sample file"},
"mobi": {"0": "this is a sample file"},
"docs": {"0": "this is a sample file"}
"extracted_txt": {"0": "this is a sample file"}
}
1 change: 1 addition & 0 deletions audiobook/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

__version__ = "2.0.4"


def main():
parser = argparse.ArgumentParser(description="AudioBook - listen to any PDF book")
parser.add_argument("-p", "--path", nargs="?", default=None, help="book file path")
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@

html_static_path = ['_static']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.venv']
html_sidebars = { '**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html'] }
html_sidebars = {'**': ['globaltoc.html', 'relations.html', 'sourcelink.html', 'searchbox.html']}
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@
url="https://github.com/codePerfectPlus/audiobook",
keywords="audiobook",
packages=setuptools.find_packages(),
project_urls= {
"Documentation": "https://pycontributors.readthedocs.io/projects/Audiobook/en/latest/",
"Source": "https://github.com/Py-Contributors/AudioBook",
"Tracker": "https://github.com/Py-Contributors/AudioBook/issues"
},
classifiers=[
"Development Status :: 3 - Alpha",
"Development Status :: 4 - Beta",
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
Expand Down
1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .test_audiobook import * # noqa
14 changes: 7 additions & 7 deletions tests/test_audiobook.py → tests/test_create_json_book.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
import unittest
import json

from audiobook import AudioBook

import json


def load_json(filename):
with open(filename, "r") as fp:
return json.load(fp)


output = load_json("assets/output.json")
output_txt = (output['extracted_txt'], {'book_name': 'sample', 'pages': 1})

ab = AudioBook(speed="normal")


class TestAudioBook(unittest.TestCase):

def test_txt_to_json_pdf_miner(self):
self.assertEqual(ab.create_json_book("assets/sample.txt"), (output['txt'], {'book_name': 'sample', 'pages': 1}))
self.assertEqual(ab.create_json_book("assets/sample.txt"), output_txt)

def test_pdf_to_json_pdf_miner(self):
self.assertEqual(ab.create_json_book("assets/sample.pdf", extraction_engine="pdfminer"), (output['pdf'], {'book_name': 'sample', 'pages': 1}))
self.assertEqual(ab.create_json_book("assets/sample.pdf", extraction_engine="pdfminer"), output_txt)

def test_pdf_to_json_pypdf2(self):
self.assertEqual(ab.create_json_book("assets/sample.pdf", extraction_engine="pypdf2"), (output['pdf'], {'book_name': 'sample', 'pages': 1}))
self.assertEqual(ab.create_json_book("assets/sample.pdf", extraction_engine="pypdf2"), output_txt)

def test_odt_to_json(self):
self.assertEqual(ab.create_json_book("assets/sample.odt"), (output['odt'], {'book_name': 'sample', 'pages': 1}))
self.assertEqual(ab.create_json_book("assets/sample.odt"), output_txt)

def test_mobi_to_json(self):
self.assertEqual(ab.create_json_book("assets/sample.mobi"), (output['mobi'], {'book_name': 'sample', 'pages': 1}))
self.assertEqual(ab.create_json_book("assets/sample.mobi"), output_txt)

# def test_docs_to_json(self):
# self.assertEqual(ab.create_json_book("assets/sample.doc"), (output['docs'], {'book_name': 'sample', 'pages': 1}))
Expand Down