From ad4f0144b82a0e881ac7b0a8f1cdb0232775e43a Mon Sep 17 00:00:00 2001 From: David Luevano Alvarado <55825613+luevano@users.noreply.github.com> Date: Mon, 13 Sep 2021 01:54:59 -0600 Subject: change to using pbr and restructure directories --- LICENSE | 2 +- MANIFEST.in | 1 - Makefile | 2 - pyproject.toml | 6 ++ requirements.txt | 6 +- setup.cfg | 37 +++++++++++ setup.py | 104 ++---------------------------- src/tirante/__init__.py | 3 + src/tirante/__main__.py | 3 + src/tirante/chapter_images_manager.py | 33 ++++++++++ src/tirante/chapters_manager.py | 31 +++++++++ src/tirante/create_database.py | 65 +++++++++++++++++++ src/tirante/download_manager.py | 28 ++++++++ src/tirante/download_manga.py | 94 +++++++++++++++++++++++++++ src/tirante/get_chapter_image_list.py | 35 ++++++++++ src/tirante/get_chapters_list.py | 65 +++++++++++++++++++ src/tirante/tirante.py | 23 +++++++ src/tirante/update_database.py | 78 +++++++++++++++++++++++ tirante/__init__.py | 32 ---------- tirante/__main__.py | 43 ------------- tirante/chapter_images_manager.py | 55 ---------------- tirante/chapters_manager.py | 55 ---------------- tirante/create_database.py | 87 ------------------------- tirante/download_manager.py | 50 --------------- tirante/download_manga.py | 116 ---------------------------------- tirante/get_chapter_image_list.py | 57 ----------------- tirante/get_chapters_list.py | 87 ------------------------- tirante/update_database.py | 101 ----------------------------- tirante/version.py | 23 ------- 29 files changed, 509 insertions(+), 813 deletions(-) delete mode 100644 MANIFEST.in delete mode 100644 Makefile create mode 100644 pyproject.toml create mode 100644 setup.cfg create mode 100644 src/tirante/__init__.py create mode 100644 src/tirante/__main__.py create mode 100644 src/tirante/chapter_images_manager.py create mode 100644 src/tirante/chapters_manager.py create mode 100644 src/tirante/create_database.py create mode 100644 src/tirante/download_manager.py create mode 100644 src/tirante/download_manga.py create mode 100644 src/tirante/get_chapter_image_list.py create mode 100644 src/tirante/get_chapters_list.py create mode 100644 src/tirante/tirante.py create mode 100644 src/tirante/update_database.py delete mode 100644 tirante/__init__.py delete mode 100644 tirante/__main__.py delete mode 100644 tirante/chapter_images_manager.py delete mode 100644 tirante/chapters_manager.py delete mode 100644 tirante/create_database.py delete mode 100644 tirante/download_manager.py delete mode 100644 tirante/download_manga.py delete mode 100644 tirante/get_chapter_image_list.py delete mode 100644 tirante/get_chapters_list.py delete mode 100644 tirante/update_database.py delete mode 100644 tirante/version.py diff --git a/LICENSE b/LICENSE index 309014e..b6490af 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 David Luevano Alvarado +Copyright (c) 2021 David Luevano Alvarado Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/MANIFEST.in b/MANIFEST.in deleted file mode 100644 index 7152b80..0000000 --- a/MANIFEST.in +++ /dev/null @@ -1 +0,0 @@ -include README.md LICENSE \ No newline at end of file diff --git a/Makefile b/Makefile deleted file mode 100644 index 1a05b92..0000000 --- a/Makefile +++ /dev/null @@ -1,2 +0,0 @@ -init: - pip install -r requirements.txt \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5a3c46 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 16f6f23..cabc158 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ -beautifulsoup4==4.8.1 -requests==2.22.0 -urllib3==1.26.5 +beautifulsoup4==4.10.0 +requests==2.26.6 +urllib3==1.26.6 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..5edcbfb --- /dev/null +++ b/setup.cfg @@ -0,0 +1,37 @@ +[metadata] +name = tirante +author = David Luevano Alvarado +author_email = david@luevano.xyz +summary = A (wannabe) manga download manager +description_file = README.md +license = GPLv3 +home_page = https://github.com/luevano/tirante +classifiers = + Programming Language :: Python :: 3 + License :: OSI Approved :: GNU General Public License v3 (GPLv3) + Operating System :: Microsoft :: Windows +keywords = + python + manga + download + manager + +[files] +packages = + tirante + +[bdist_wheel] +universal = 0 + +[entry_points] +console_scripts = + tirante = tirante:main + +[options] +package_dir = + = src +packages = find: +include_package_data = True + +[options.packages.find] +where = src \ No newline at end of file diff --git a/setup.py b/setup.py index 4d9bd8b..f7c9db6 100644 --- a/setup.py +++ b/setup.py @@ -1,102 +1,6 @@ -"""MIT License +from setuptools import setup -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -# This setup.py template was obtained from -# https://github.com/navdeep-G/setup.py/blob/master/setup.py -# ---------------------------------------------------------------------- -# Note: To use the 'upload' functionality of this file, you must: -# $ pipenv install twine --dev - -import io -import os - -from setuptools import find_packages, setup - -from tirante.version import __version__ - -# Package meta-data. -NAME = 'tirante' -DESCRIPTION = 'A (wannabe) manga downloader manager.' -URL = 'https://github.com/luevano/tirante' -EMAIL = 'lorentzeus@gmail.com' -AUTHOR = 'David Luevano Alvarado' -REQUIRES_PYTHON = '>=3.7' -VERSION = __version__ -# VERSION = '0.0.1' - -# What packages are required for this module to be executed? -REQUIRED = [ - # 'requests', 'maya', 'records', -] - -# What packages are optional? -EXTRAS = { - # 'fancy feature': ['django'], -} - -# The rest you shouldn't have to touch too much :) -# ------------------------------------------------ -# Except, perhaps the License and Trove Classifiers! -# If you do change the License, remember to change -# the Trove Classifier for that! - -here = os.path.abspath(os.path.dirname(__file__)) - -# Import the README and use it as the long-description. -# Note: this will only work if 'README.md' -# is present in your MANIFEST.in file! -try: - with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f: - long_description = '\n' + f.read() -except FileNotFoundError: - long_description = DESCRIPTION - -# Where the magic happens: setup( - name=NAME, - version=VERSION, - description=DESCRIPTION, - long_description=long_description, - long_description_content_type='text/markdown', - author=AUTHOR, - author_email=EMAIL, - python_requires=REQUIRES_PYTHON, - url=URL, - packages=find_packages(exclude=["tests", - "*.tests", - "*.tests.*", - "tests.*"]), - # If your package is a single module, use this instead of 'packages': - # py_modules=['mypackage'], - install_requires=REQUIRED, - extras_require=EXTRAS, - include_package_data=True, - license='MIT', - classifiers=[ - # Trove classifiers - # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.7' - ] -) + setup_requires=['pbr'], + pbr=True +) \ No newline at end of file diff --git a/src/tirante/__init__.py b/src/tirante/__init__.py new file mode 100644 index 0000000..168b24e --- /dev/null +++ b/src/tirante/__init__.py @@ -0,0 +1,3 @@ +from .tirante import main + +__all__ = ['main'] \ No newline at end of file diff --git a/src/tirante/__main__.py b/src/tirante/__main__.py new file mode 100644 index 0000000..f56161e --- /dev/null +++ b/src/tirante/__main__.py @@ -0,0 +1,3 @@ +from .tirante import main + +main() \ No newline at end of file diff --git a/src/tirante/chapter_images_manager.py b/src/tirante/chapter_images_manager.py new file mode 100644 index 0000000..1b8afbc --- /dev/null +++ b/src/tirante/chapter_images_manager.py @@ -0,0 +1,33 @@ +from tirante.get_chapter_image_list import get_chapter_image_list + + +def chapter_images_list_to_csv(chapter_data): + """ + Creates csv file for a chapter, given the list. + chapter_data: A list containing a url and a title. + """ + + ch_name = ''.join([chapter_data[1], '.csv']) + + chapter_image_list = get_chapter_image_list(chapter_data) + + with open(ch_name, 'w') as outcsv: + for image in chapter_image_list: + outcsv.write(''.join([image[0], ',', image[1], '\n'])) + + +def chapter_images_csv_to_list(chapter_image_csv): + """ + Returns a list given the csv file. + chapter_image_csv: csv containing data for the chapter. + """ + + out_chapter_image_list = [] + + with open(chapter_image_csv, 'r') as incsv: + lines = incsv.readlines() + for line in lines: + # print(line.strip().split(',')) + out_chapter_image_list.append(line.strip().split(',')) + + return out_chapter_image_list diff --git a/src/tirante/chapters_manager.py b/src/tirante/chapters_manager.py new file mode 100644 index 0000000..3d99c3f --- /dev/null +++ b/src/tirante/chapters_manager.py @@ -0,0 +1,31 @@ +def chapters_list_to_csv(chapters_list, + manga_name): + """ + Creates a csv file from the input chapter_list. + chapters_list: List of data of the chapters. + manga_name: Name of the manga, folder naming friendly. + """ + + # Adding '.csv' for csv creation. + m_name_ext = ''.join([manga_name, '.csv']) + # print(m_name) + + with open(m_name_ext, 'w') as outcsv: + for chapter in chapters_list: + outcsv.write(''.join([chapter[0], ',', chapter[1], '\n'])) + + +def chapters_csv_to_list(chapter_csv): + """ + Gives a list of chaptesrs from a csv file. + chapters_list: List of data of the chapters. + """ + + out_chapters_list = [] + + with open(chapter_csv, 'r') as incsv: + lines = incsv.readlines() + for line in lines: + out_chapters_list.append(line.strip().split(',')) + + return out_chapters_list diff --git a/src/tirante/create_database.py b/src/tirante/create_database.py new file mode 100644 index 0000000..22d8230 --- /dev/null +++ b/src/tirante/create_database.py @@ -0,0 +1,65 @@ +import os + +# Project specific imports. +from tirante.get_chapters_list import get_chapters_list +from tirante.chapters_manager import chapters_list_to_csv +from tirante.chapters_manager import chapters_csv_to_list +from tirante.chapter_images_manager import chapter_images_list_to_csv + + +def create_database(main_url, + manga_name_url, + manga_name, + manga_dir, + manga_data_dir): + """ + Creates a database from zero, made of csv files. + main_url: Main webpage name (source). + manga_name_url: Name of the manga in the url format + that's used by the webpage. + manga_name: Actual name of the manga, as it appears in the webpage. + manga_dir: Main manga folder in computer, subfolders here will be created. + manga_data_dir: Main manga data folder in computer. + NOTE: This does not updates the database. + If a database already exists, omits the creation of new files. + """ + + # A better "naming" for the manga, for use with folder creation. + # As well as the name of the main database. + m_name = '_'.join(word.lower() for word in manga_name.split()) + m_name_ext = ''.join([m_name, '.csv']) + + # Navigate to where the main data folder is, + # then to where the manga folder is. + os.chdir(manga_data_dir) + try: + os.mkdir(m_name) + os.chdir(m_name) + except FileExistsError: + print(''.join([m_name, + ' folder already exists.'])) + os.chdir(m_name) + + # List of files and folders in the current path. + data_list_dir = os.listdir() + + # Get the list of chapters, if this already exists, + # read it from the database. + # This is the main manga data. + if m_name_ext not in data_list_dir: + chapters_list = get_chapters_list(main_url=main_url, + manga_name_url=manga_name_url, + manga_name=manga_name) + chapters_list_to_csv(chapters_list=chapters_list, manga_name=m_name) + else: + print(''.join([m_name_ext, ' already exists.'])) + chapters_list = chapters_csv_to_list(m_name_ext) + + # Data for each chapter. + for chapter in chapters_list: + # Get the list for the images of each chapter. + chapter_name_ext = ''.join([chapter[1], '.csv']) + if chapter_name_ext not in data_list_dir: + chapter_images_list_to_csv(chapter) + else: + print(''.join([chapter_name_ext, ' already exists.'])) diff --git a/src/tirante/download_manager.py b/src/tirante/download_manager.py new file mode 100644 index 0000000..2d833e6 --- /dev/null +++ b/src/tirante/download_manager.py @@ -0,0 +1,28 @@ +import requests + + +def download_image(image_list): + """ + Downloads an image from the specified url, + and saves it with the specified name. + image_list: list that contains url and name. + """ + + # Gets the content of an image from its url. + img_data = requests.get(image_list[0]).content + + # Opens a file with its corresponding name as 'wb' (write, binary), + # and then, writes the img_data. + with open(image_list[1], 'wb') as handler: + handler.write(img_data) + + +def download_chapter(image_list): + """ + Downloads the whole chapter as images. + image_url_list: List containing urls and file names for each image. + """ + + for image in image_list: + print(image) + download_image(image) diff --git a/src/tirante/download_manga.py b/src/tirante/download_manga.py new file mode 100644 index 0000000..50e2755 --- /dev/null +++ b/src/tirante/download_manga.py @@ -0,0 +1,94 @@ +import os + +# Project specific imports. +from tirante.chapters_manager import chapters_csv_to_list +from tirante.chapter_images_manager import chapter_images_csv_to_list +from tirante.download_manager import download_chapter + + +def download_manga(manga_name, + manga_dir, + manga_data_dir): + """ + Downloads a whole manga, saving it to subfolders. + Uses the database already created. + that's used by the webpage. + manga_name: Actual name of the manga, as it appears in the webpage. + manga_dir: Main manga folder in computer, subfolders here will be created. + manga_data_dir: Main manga data folder in computer. + NOTE: This updates the manga, downloading the missing chapters + if they're listed in the database. + """ + + # A better "naming" for the manga, for use with folder creation. + # As well as the name of the main database. + m_name = '_'.join(word.lower() for word in manga_name.split()) + m_name_ext = ''.join([m_name, '.csv']) + + # Go to where the database is located. + os.chdir(manga_data_dir) + try: + os.chdir(m_name) + except FileNotFoundError: + print(''.join([m_name, + ' folder doesn\'t exist.', + ' Most likely, the database hasn\'t been created.'])) + raise NameError('Create database first.') + + # Get info of the files in the database. + data_list_dir = os.listdir() + + # Reads data from the main database. + if m_name_ext not in data_list_dir: + print(''.join([m_name, + ' database hasn\'t been created.', + ' Most likely, the database hasn\'t been created.'])) + raise NameError('Create database first.') + else: + chapters_list = chapters_csv_to_list(m_name_ext) + + # Navigate to the main manga dir, + # and either create or go to manga folder. + os.chdir(manga_dir) + try: + os.mkdir(manga_name) + os.chdir(manga_name) + except FileExistsError: + print(''.join([manga_name, + ' folder already exists.'])) + os.chdir(manga_name) + + # Get data of the folders in the manga folder. + manga_list_dir = os.listdir() + + for chapter in chapters_list: + # chapter_url = chapter[0] + chapter_name = chapter[1] + ch_name_ext = ''.join([chapter_name, '.csv']) + + if chapter_name not in manga_list_dir: + print(''.join(['Downloading ', + chapter_name, + ' now.'])) + # First, create the chapter folder. + os.mkdir(chapter_name) + + # Go to where the database is located. + os.chdir(manga_data_dir) + os.chdir(m_name) + chapter_image_list = chapter_images_csv_to_list(ch_name_ext) + + # Go back to where the manga is going ot be downloaded. + os.chdir(manga_dir) + os.chdir(manga_name) + os.chdir(chapter_name) + + # Download all the chapter images on its respective folder. + download_chapter(chapter_image_list) + + # Go back one folder to repeat the process + # for the next chapter. + os.chdir('..') + else: + print(''.join([chapter_name, + ' already downloaded.'])) diff --git a/src/tirante/get_chapter_image_list.py b/src/tirante/get_chapter_image_list.py new file mode 100644 index 0000000..a0881c6 --- /dev/null +++ b/src/tirante/get_chapter_image_list.py @@ -0,0 +1,35 @@ +import urllib3 +from bs4 import BeautifulSoup + + +def get_chapter_image_list(chapter_data): + """ + Gets the links for each image in the chapter, + and returns a list of the links. + Returns a list of the image urls and its file name. + chapter_data: A list containing a url and a title. + NOTE: Not for direct use with the result of 'get_chapters_list' + """ + + # Not actually a file, but the content of the html. + html = urllib3.PoolManager().request('GET', chapter_data[0]) + + # Get the data from the html and parse it. + soup = BeautifulSoup(html.data, 'html.parser') + + # Get the "vung-doc" class, this contains a url for each page, + # which redirects to the source of the image. + # Deletes the first and last items, since they're trash. + soup_img = soup.find_all('img') + del soup_img[0] + del soup_img[len(soup_img)-1] + + # Stores each image url in a list. + image_url_list = [] + for img in soup_img: + # Gets the sring of the url, splits it by the char '/', + # and gets the last item, which is the name of the file. + + image_url_list.append([img['src'], img['src'].split('/')[-1]]) + + return image_url_list diff --git a/src/tirante/get_chapters_list.py b/src/tirante/get_chapters_list.py new file mode 100644 index 0000000..83cefc7 --- /dev/null +++ b/src/tirante/get_chapters_list.py @@ -0,0 +1,65 @@ +import urllib3 +from bs4 import BeautifulSoup + + +def get_chapters_list(main_url, + manga_name_url, + manga_name, + reverse_sorted=True): + """ + Retrieves chapter urls and names. Returns a list of lists + containing the url and the title of the chapter. + main_url: Main webpage name (source). + manga_name_url: Name of the manga in the url format + that's used by the webpage. + manga_name: Actual name of the manga, as it appears in the webpage. + reverse_sorted: Sorting of the final array. + """ + + manga_url = ''.join([main_url, manga_name_url]) + + # Not actually a file, but the content of the html. + html = urllib3.PoolManager().request('GET', manga_url) + + # Get the data from the html and parse it. + soup = BeautifulSoup(html.data, 'html.parser') + + # Get the "rows" class, this contains the url + # and title data for each chapter. + # Deletes the first tag, since it's not useful. + soup_rows = soup.find_all('div', {'class': 'row'}) + del soup_rows[0] + + # Creates a list to store date for each url and chapter name. + chapter_list = [] + + for row in soup_rows: + + # Gets the url name from the a tag. + href = row.a['href'] + # Same, for the title. Deletes every ocurrance of the manga name, + # unwanted characters and then gets everyword. + title_words = row.a['title'].replace(manga_name, '').replace('?', '') + title_words = title_words.replace(':', '').replace('-', '') + title_words = title_words.replace('...', '').replace(',', '').split() + + # Doing all the work in oneliner doesn't work for some chapters, + # for some reason. + # title = '_'.join(row.a['title'].replace(manga_name, '') + # .replace(':', '').replace('-', '').lower().split()) + + # Lowers every word and appends it to a new list, + # then it gets joined with '_' as a sep. + title_words_lower = [] + for word in title_words: + title_words_lower.append(word.lower()) + + title = '_'.join(title_words_lower) + + # print(href, title) + chapter_list.append([href, title]) + + if reverse_sorted: + return chapter_list[::-1] + else: + return chapter_list diff --git a/src/tirante/tirante.py b/src/tirante/tirante.py new file mode 100644 index 0000000..108154a --- /dev/null +++ b/src/tirante/tirante.py @@ -0,0 +1,23 @@ +from tirante.create_database import create_database + + +def main() -> None: + # Main manga source. + MAIN_URL = 'https://manganelo.com/manga/' + # Manga name. + MANGA_NAME = 'Kimetsu no Yaiba' + # Manga name in the form of how appears in the url. + MANGA_NAME_URL = 'kimetsu_no_yaiba/' + + # PC main file location. + MANGA_DIR = 'E:\\Mangas\\' + # PC main manga data location. + MANGA_DATA_DIR = ''.join(['C:\\Users\\Lorentzeus\\Google Drive\\', + 'Personal\\Python\\tirante\\test_data']) + + if __name__ == "__main__": + create_database(main_url=MAIN_URL, + manga_name_url=MANGA_NAME_URL, + manga_name=MANGA_NAME, + manga_dir=MANGA_DIR, + manga_data_dir=MANGA_DATA_DIR) \ No newline at end of file diff --git a/src/tirante/update_database.py b/src/tirante/update_database.py new file mode 100644 index 0000000..5d7fd8c --- /dev/null +++ b/src/tirante/update_database.py @@ -0,0 +1,78 @@ +import os + +# Project specific imports. +from tirante.get_chapters_list import get_chapters_list +from tirante.chapters_manager import chapters_csv_to_list +from tirante.chapter_images_manager import chapter_images_list_to_csv + + +def update_database(main_url, + manga_name_url, + manga_name, + manga_dir, + manga_data_dir): + """ + Updates the database already created, adding missing ones. + main_url: Main webpage name (source). + manga_name_url: Name of the manga in the url format + that's used by the webpage. + manga_name: Actual name of the manga, as it appears in the webpage. + manga_dir: Main manga folder in computer, subfolders here will be created. + manga_data_dir: Main manga data folder in computer. + """ + + # A better "naming" for the manga, for use with folder creation. + # As well as the name of the main database. + m_name = '_'.join(word.lower() for word in manga_name.split()) + m_name_ext = ''.join([m_name, '.csv']) + + # Navigate to where the main data folder is, + # then to where the manga folder is. + os.chdir(manga_data_dir) + try: + os.mkdir(m_name) + os.chdir(m_name) + except FileExistsError: + print(''.join([m_name, + ' folder already exists.'])) + os.chdir(m_name) + + # Get a list of files present in path. + data_list_dir = os.listdir() + + # First, download the data from the web. + new_chapter_list = get_chapters_list(main_url=main_url, + manga_name_url=manga_name_url, + manga_name=manga_name, + reverse_sorted=False) + + # And then, read the current database. + last_chapter = chapters_csv_to_list(m_name_ext)[-1] + + # The missing chapters. + missing_chapters = [] + for chapter in new_chapter_list: + # If we get to the last acquired chapter, exit loop. + if chapter == last_chapter: + break + missing_chapters.append(chapter) + + # Reverse the order. + missing_chapters = missing_chapters[::-1] + + # Write the last chapters to already existing csv file. + # No need for checking if items are present, + # since that's checked on the last steps, + # that's how missing_chapters is acquired. + with open(m_name_ext, 'a') as outcsv: + for chapter in missing_chapters: + outcsv.write(''.join([chapter[0], ',', chapter[1], '\n'])) + + # Create the missing csv data files for each chapter. + for chapter in missing_chapters: + # Get the list for the images of each chapter. + chapter_name_ext = ''.join([chapter[1], '.csv']) + if chapter_name_ext not in data_list_dir: + chapter_images_list_to_csv(chapter) + else: + print(''.join([chapter_name_ext, ' already exists.'])) diff --git a/tirante/__init__.py b/tirante/__init__.py deleted file mode 100644 index 1cee674..0000000 --- a/tirante/__init__.py +++ /dev/null @@ -1,32 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -# from version import __version__ -from tirante.create_database import create_database -from tirante.update_database import update_database -from tirante.download_manga import download_manga - -# If somebody does "from package import *", this is what they will -# be able to access: -__all__ = ['create_database', - 'update_database', - 'download_manga'] diff --git a/tirante/__main__.py b/tirante/__main__.py deleted file mode 100644 index 8738da0..0000000 --- a/tirante/__main__.py +++ /dev/null @@ -1,43 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -from tirante.create_database import create_database - -# Main manga source. -MAIN_URL = 'https://manganelo.com/manga/' -# Manga name. -MANGA_NAME = 'Kimetsu no Yaiba' -# Manga name in the form of how appears in the url. -MANGA_NAME_URL = 'kimetsu_no_yaiba/' - -# PC main file location. -MANGA_DIR = 'E:\\Mangas\\' -# PC main manga data location. -MANGA_DATA_DIR = ''.join(['C:\\Users\\Lorentzeus\\Google Drive\\', - 'Personal\\Python\\tirante\\test_data']) - -if __name__ == "__main__": - create_database(main_url=MAIN_URL, - manga_name_url=MANGA_NAME_URL, - manga_name=MANGA_NAME, - manga_dir=MANGA_DIR, - manga_data_dir=MANGA_DATA_DIR) diff --git a/tirante/chapter_images_manager.py b/tirante/chapter_images_manager.py deleted file mode 100644 index bd8aa07..0000000 --- a/tirante/chapter_images_manager.py +++ /dev/null @@ -1,55 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -from tirante.get_chapter_image_list import get_chapter_image_list - - -def chapter_images_list_to_csv(chapter_data): - """ - Creates csv file for a chapter, given the list. - chapter_data: A list containing a url and a title. - """ - - ch_name = ''.join([chapter_data[1], '.csv']) - - chapter_image_list = get_chapter_image_list(chapter_data) - - with open(ch_name, 'w') as outcsv: - for image in chapter_image_list: - outcsv.write(''.join([image[0], ',', image[1], '\n'])) - - -def chapter_images_csv_to_list(chapter_image_csv): - """ - Returns a list given the csv file. - chapter_image_csv: csv containing data for the chapter. - """ - - out_chapter_image_list = [] - - with open(chapter_image_csv, 'r') as incsv: - lines = incsv.readlines() - for line in lines: - # print(line.strip().split(',')) - out_chapter_image_list.append(line.strip().split(',')) - - return out_chapter_image_list diff --git a/tirante/chapters_manager.py b/tirante/chapters_manager.py deleted file mode 100644 index d5cbe80..0000000 --- a/tirante/chapters_manager.py +++ /dev/null @@ -1,55 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" - - -def chapters_list_to_csv(chapters_list, - manga_name): - """ - Creates a csv file from the input chapter_list. - chapters_list: List of data of the chapters. - manga_name: Name of the manga, folder naming friendly. - """ - - # Adding '.csv' for csv creation. - m_name_ext = ''.join([manga_name, '.csv']) - # print(m_name) - - with open(m_name_ext, 'w') as outcsv: - for chapter in chapters_list: - outcsv.write(''.join([chapter[0], ',', chapter[1], '\n'])) - - -def chapters_csv_to_list(chapter_csv): - """ - Gives a list of chaptesrs from a csv file. - chapters_list: List of data of the chapters. - """ - - out_chapters_list = [] - - with open(chapter_csv, 'r') as incsv: - lines = incsv.readlines() - for line in lines: - out_chapters_list.append(line.strip().split(',')) - - return out_chapters_list diff --git a/tirante/create_database.py b/tirante/create_database.py deleted file mode 100644 index 8c9b43b..0000000 --- a/tirante/create_database.py +++ /dev/null @@ -1,87 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -import os - -# Project specific imports. -from tirante.get_chapters_list import get_chapters_list -from tirante.chapters_manager import chapters_list_to_csv -from tirante.chapters_manager import chapters_csv_to_list -from tirante.chapter_images_manager import chapter_images_list_to_csv - - -def create_database(main_url, - manga_name_url, - manga_name, - manga_dir, - manga_data_dir): - """ - Creates a database from zero, made of csv files. - main_url: Main webpage name (source). - manga_name_url: Name of the manga in the url format - that's used by the webpage. - manga_name: Actual name of the manga, as it appears in the webpage. - manga_dir: Main manga folder in computer, subfolders here will be created. - manga_data_dir: Main manga data folder in computer. - NOTE: This does not updates the database. - If a database already exists, omits the creation of new files. - """ - - # A better "naming" for the manga, for use with folder creation. - # As well as the name of the main database. - m_name = '_'.join(word.lower() for word in manga_name.split()) - m_name_ext = ''.join([m_name, '.csv']) - - # Navigate to where the main data folder is, - # then to where the manga folder is. - os.chdir(manga_data_dir) - try: - os.mkdir(m_name) - os.chdir(m_name) - except FileExistsError: - print(''.join([m_name, - ' folder already exists.'])) - os.chdir(m_name) - - # List of files and folders in the current path. - data_list_dir = os.listdir() - - # Get the list of chapters, if this already exists, - # read it from the database. - # This is the main manga data. - if m_name_ext not in data_list_dir: - chapters_list = get_chapters_list(main_url=main_url, - manga_name_url=manga_name_url, - manga_name=manga_name) - chapters_list_to_csv(chapters_list=chapters_list, manga_name=m_name) - else: - print(''.join([m_name_ext, ' already exists.'])) - chapters_list = chapters_csv_to_list(m_name_ext) - - # Data for each chapter. - for chapter in chapters_list: - # Get the list for the images of each chapter. - chapter_name_ext = ''.join([chapter[1], '.csv']) - if chapter_name_ext not in data_list_dir: - chapter_images_list_to_csv(chapter) - else: - print(''.join([chapter_name_ext, ' already exists.'])) diff --git a/tirante/download_manager.py b/tirante/download_manager.py deleted file mode 100644 index e7e7285..0000000 --- a/tirante/download_manager.py +++ /dev/null @@ -1,50 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -import requests - - -def download_image(image_list): - """ - Downloads an image from the specified url, - and saves it with the specified name. - image_list: list that contains url and name. - """ - - # Gets the content of an image from its url. - img_data = requests.get(image_list[0]).content - - # Opens a file with its corresponding name as 'wb' (write, binary), - # and then, writes the img_data. - with open(image_list[1], 'wb') as handler: - handler.write(img_data) - - -def download_chapter(image_list): - """ - Downloads the whole chapter as images. - image_url_list: List containing urls and file names for each image. - """ - - for image in image_list: - print(image) - download_image(image) diff --git a/tirante/download_manga.py b/tirante/download_manga.py deleted file mode 100644 index 3bcd947..0000000 --- a/tirante/download_manga.py +++ /dev/null @@ -1,116 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -import os - -# Project specific imports. -from tirante.chapters_manager import chapters_csv_to_list -from tirante.chapter_images_manager import chapter_images_csv_to_list -from tirante.download_manager import download_chapter - - -def download_manga(manga_name, - manga_dir, - manga_data_dir): - """ - Downloads a whole manga, saving it to subfolders. - Uses the database already created. - that's used by the webpage. - manga_name: Actual name of the manga, as it appears in the webpage. - manga_dir: Main manga folder in computer, subfolders here will be created. - manga_data_dir: Main manga data folder in computer. - NOTE: This updates the manga, downloading the missing chapters - if they're listed in the database. - """ - - # A better "naming" for the manga, for use with folder creation. - # As well as the name of the main database. - m_name = '_'.join(word.lower() for word in manga_name.split()) - m_name_ext = ''.join([m_name, '.csv']) - - # Go to where the database is located. - os.chdir(manga_data_dir) - try: - os.chdir(m_name) - except FileNotFoundError: - print(''.join([m_name, - ' folder doesn\'t exist.', - ' Most likely, the database hasn\'t been created.'])) - raise NameError('Create database first.') - - # Get info of the files in the database. - data_list_dir = os.listdir() - - # Reads data from the main database. - if m_name_ext not in data_list_dir: - print(''.join([m_name, - ' database hasn\'t been created.', - ' Most likely, the database hasn\'t been created.'])) - raise NameError('Create database first.') - else: - chapters_list = chapters_csv_to_list(m_name_ext) - - # Navigate to the main manga dir, - # and either create or go to manga folder. - os.chdir(manga_dir) - try: - os.mkdir(manga_name) - os.chdir(manga_name) - except FileExistsError: - print(''.join([manga_name, - ' folder already exists.'])) - os.chdir(manga_name) - - # Get data of the folders in the manga folder. - manga_list_dir = os.listdir() - - for chapter in chapters_list: - # chapter_url = chapter[0] - chapter_name = chapter[1] - ch_name_ext = ''.join([chapter_name, '.csv']) - - if chapter_name not in manga_list_dir: - print(''.join(['Downloading ', - chapter_name, - ' now.'])) - # First, create the chapter folder. - os.mkdir(chapter_name) - - # Go to where the database is located. - os.chdir(manga_data_dir) - os.chdir(m_name) - chapter_image_list = chapter_images_csv_to_list(ch_name_ext) - - # Go back to where the manga is going ot be downloaded. - os.chdir(manga_dir) - os.chdir(manga_name) - os.chdir(chapter_name) - - # Download all the chapter images on its respective folder. - download_chapter(chapter_image_list) - - # Go back one folder to repeat the process - # for the next chapter. - os.chdir('..') - else: - print(''.join([chapter_name, - ' already downloaded.'])) diff --git a/tirante/get_chapter_image_list.py b/tirante/get_chapter_image_list.py deleted file mode 100644 index 9b0397b..0000000 --- a/tirante/get_chapter_image_list.py +++ /dev/null @@ -1,57 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -import urllib3 -from bs4 import BeautifulSoup - - -def get_chapter_image_list(chapter_data): - """ - Gets the links for each image in the chapter, - and returns a list of the links. - Returns a list of the image urls and its file name. - chapter_data: A list containing a url and a title. - NOTE: Not for direct use with the result of 'get_chapters_list' - """ - - # Not actually a file, but the content of the html. - html = urllib3.PoolManager().request('GET', chapter_data[0]) - - # Get the data from the html and parse it. - soup = BeautifulSoup(html.data, 'html.parser') - - # Get the "vung-doc" class, this contains a url for each page, - # which redirects to the source of the image. - # Deletes the first and last items, since they're trash. - soup_img = soup.find_all('img') - del soup_img[0] - del soup_img[len(soup_img)-1] - - # Stores each image url in a list. - image_url_list = [] - for img in soup_img: - # Gets the sring of the url, splits it by the char '/', - # and gets the last item, which is the name of the file. - - image_url_list.append([img['src'], img['src'].split('/')[-1]]) - - return image_url_list diff --git a/tirante/get_chapters_list.py b/tirante/get_chapters_list.py deleted file mode 100644 index f8c3d9d..0000000 --- a/tirante/get_chapters_list.py +++ /dev/null @@ -1,87 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -import urllib3 -from bs4 import BeautifulSoup - - -def get_chapters_list(main_url, - manga_name_url, - manga_name, - reverse_sorted=True): - """ - Retrieves chapter urls and names. Returns a list of lists - containing the url and the title of the chapter. - main_url: Main webpage name (source). - manga_name_url: Name of the manga in the url format - that's used by the webpage. - manga_name: Actual name of the manga, as it appears in the webpage. - reverse_sorted: Sorting of the final array. - """ - - manga_url = ''.join([main_url, manga_name_url]) - - # Not actually a file, but the content of the html. - html = urllib3.PoolManager().request('GET', manga_url) - - # Get the data from the html and parse it. - soup = BeautifulSoup(html.data, 'html.parser') - - # Get the "rows" class, this contains the url - # and title data for each chapter. - # Deletes the first tag, since it's not useful. - soup_rows = soup.find_all('div', {'class': 'row'}) - del soup_rows[0] - - # Creates a list to store date for each url and chapter name. - chapter_list = [] - - for row in soup_rows: - - # Gets the url name from the a tag. - href = row.a['href'] - # Same, for the title. Deletes every ocurrance of the manga name, - # unwanted characters and then gets everyword. - title_words = row.a['title'].replace(manga_name, '').replace('?', '') - title_words = title_words.replace(':', '').replace('-', '') - title_words = title_words.replace('...', '').replace(',', '').split() - - # Doing all the work in oneliner doesn't work for some chapters, - # for some reason. - # title = '_'.join(row.a['title'].replace(manga_name, '') - # .replace(':', '').replace('-', '').lower().split()) - - # Lowers every word and appends it to a new list, - # then it gets joined with '_' as a sep. - title_words_lower = [] - for word in title_words: - title_words_lower.append(word.lower()) - - title = '_'.join(title_words_lower) - - # print(href, title) - chapter_list.append([href, title]) - - if reverse_sorted: - return chapter_list[::-1] - else: - return chapter_list diff --git a/tirante/update_database.py b/tirante/update_database.py deleted file mode 100644 index e33cce0..0000000 --- a/tirante/update_database.py +++ /dev/null @@ -1,101 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" - -import os - -# Project specific imports. -from tirante.get_chapters_list import get_chapters_list -from tirante.chapters_manager import chapters_csv_to_list -from tirante.chapter_images_manager import chapter_images_list_to_csv - - -def update_database(main_url, - manga_name_url, - manga_name, - manga_dir, - manga_data_dir): - """ - Updates the database already created, adding missing ones. - main_url: Main webpage name (source). - manga_name_url: Name of the manga in the url format - that's used by the webpage. - manga_name: Actual name of the manga, as it appears in the webpage. - manga_dir: Main manga folder in computer, subfolders here will be created. - manga_data_dir: Main manga data folder in computer. - """ - - # A better "naming" for the manga, for use with folder creation. - # As well as the name of the main database. - m_name = '_'.join(word.lower() for word in manga_name.split()) - m_name_ext = ''.join([m_name, '.csv']) - - # Navigate to where the main data folder is, - # then to where the manga folder is. - os.chdir(manga_data_dir) - try: - os.mkdir(m_name) - os.chdir(m_name) - except FileExistsError: - print(''.join([m_name, - ' folder already exists.'])) - os.chdir(m_name) - - # Get a list of files present in path. - data_list_dir = os.listdir() - - # First, download the data from the web. - new_chapter_list = get_chapters_list(main_url=main_url, - manga_name_url=manga_name_url, - manga_name=manga_name, - reverse_sorted=False) - - # And then, read the current database. - last_chapter = chapters_csv_to_list(m_name_ext)[-1] - - # The missing chapters. - missing_chapters = [] - for chapter in new_chapter_list: - # If we get to the last acquired chapter, exit loop. - if chapter == last_chapter: - break - missing_chapters.append(chapter) - - # Reverse the order. - missing_chapters = missing_chapters[::-1] - - # Write the last chapters to already existing csv file. - # No need for checking if items are present, - # since that's checked on the last steps, - # that's how missing_chapters is acquired. - with open(m_name_ext, 'a') as outcsv: - for chapter in missing_chapters: - outcsv.write(''.join([chapter[0], ',', chapter[1], '\n'])) - - # Create the missing csv data files for each chapter. - for chapter in missing_chapters: - # Get the list for the images of each chapter. - chapter_name_ext = ''.join([chapter[1], '.csv']) - if chapter_name_ext not in data_list_dir: - chapter_images_list_to_csv(chapter) - else: - print(''.join([chapter_name_ext, ' already exists.'])) diff --git a/tirante/version.py b/tirante/version.py deleted file mode 100644 index fab5843..0000000 --- a/tirante/version.py +++ /dev/null @@ -1,23 +0,0 @@ -"""MIT License - -Copyright (c) 2019 David Luevano Alvarado - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -""" -__version__ = '0.0.1' -- cgit v1.2.3