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

feat: add option for naming folders with chapter name #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
26 changes: 25 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,30 @@ For example, downloading Tower of God, Chapter 150 would result in the following
│...
```

* In order to use chapter names instead of chapter numbers for separate folders, pass the ```--chapter-name``` argument along with ```--separate```.
```ps
$ python webtoon_downloader.py [url] --separate --chapter-name
```
For example, downloading Tower of God, Chapter 150 to 152 with this option would result in the following:
```ps
Tower_of_God
│[Season 2] Ep. 70
│--150_001.jpg
│--150_002.jpg
│--150_003.jpg
│...
│[Season 2] Ep. 71
│--151_001.jpg
│--151_002.jpg
│--151_003.jpg
│...
│[Season 2] Ep. 72
│--152_001.jpg
│--152_002.jpg
│--152_003.jpg
│...
```

For more details on positional arguments, please use the ```-h ``` or ```--help``` argument:
```console
py webtoon_downloader.py --help
Expand Down Expand Up @@ -188,4 +212,4 @@ Project Link: [https://github.com/Zehina/Webtoon-Downloader](https://github.com/
[license-shield]: https://img.shields.io/github/license/Zehina/repo.svg?style=for-the-badge
[license-url]: https://github.com/Zehina/Webtoon-Downloader/blob/master/LICENSE.txt
[linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555
[linkedin-url]: https://linkedin.com/in/Zehina
[linkedin-url]: https://linkedin.com/in/Zehina
3 changes: 3 additions & 0 deletions src/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def initialize(self):
self.parser.add_argument('--separate', required=False,
help='download each chapter in seperate folders',
action='store_true', default=False)
self.parser.add_argument('--chapter-name', required=False,
help='use the chapter title for the separate folder names',
action='store_true', default=False)
self.parser.add_argument('--readme', '-r', help=('displays readme file content for '
'more help details'), required=False, action='store_true')
self.parser._positionals.title = "commands"
Expand Down
12 changes: 8 additions & 4 deletions src/webtoon_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def download_chapter(chapter_download_task_id: int, session: requests.Session, v
log.info(f'Chapter {chapter_info.chapter_number} download complete with a total of {len(img_urls)} pages [green]✓')
progress.remove_task(chapter_download_task_id)

def download_webtoon(series_url: str, start_chapter: int, end_chapter: int, dest: str, images_format: str='jpg', download_latest_chapter=False, separate_chapters=False):
def download_webtoon(series_url: str, start_chapter: int, end_chapter: int, dest: str, images_format: str='jpg', download_latest_chapter=False, separate_chapters=False, use_chapter_name=False):
"""
downloads all chapters starting from start_chapter until end_chapter, inclusive.
stores the downloaded chapter into the dest path.
Expand All @@ -357,6 +357,10 @@ def download_webtoon(series_url: str, start_chapter: int, end_chapter: int, dest
separate_chapters: bool
separate downloaded chapters in their own folder under the dest path if true,
else stores all images in the dest folder.

use_chapter_name: bool
when downloading chapters in their own folders, use the chapter name instead
of the chapter number
"""
session = requests.session()
session.cookies.set("needGDPR", "FALSE", domain=".webtoons.com")
Expand Down Expand Up @@ -398,7 +402,7 @@ def download_webtoon(series_url: str, start_chapter: int, end_chapter: int, dest
with ThreadPoolExecutor(max_workers=4) as pool:
chapter_download_futures = set()
for chapter_info in itertools.islice(chapters_to_download, n_concurrent_chapters_download):
chapter_dest = os.path.join(dest, f"{chapter_info.chapter_number:0{zeros}d}") if separate_chapters else dest
chapter_dest = os.path.join(dest, f"{chapter_info.title}" if use_chapter_name else f"{chapter_info.chapter_number:0{zeros}d}") if separate_chapters else dest
chapter_download_task = progress.add_task(f"[plum2]Chapter {chapter_info.chapter_number}.", type='Pages', type_color='grey85', number_format='>02d', start=False, rendered_total='??')
chapter_download_futures.add(
pool.submit(download_chapter, chapter_download_task, session, viewer_url, chapter_info, chapter_dest, zeros, images_format)
Expand All @@ -417,7 +421,7 @@ def download_webtoon(series_url: str, start_chapter: int, end_chapter: int, dest

# Scheduling the next set of futures.
for chapter_info in itertools.islice(chapters_to_download, len(done)):
chapter_dest = os.path.join(dest, f"{chapter_info.chapter_number:0{zeros}d}") if separate_chapters else dest
chapter_dest = os.path.join(dest, f"{chapter_info.title}" if use_chapter_name else f"{chapter_info.chapter_number:0{zeros}d}") if separate_chapters else dest
chapter_download_task = progress.add_task(f"[plum2]Chapter {chapter_info.chapter_number}.", type='Pages', type_color='grey85', number_format='>02d', start=False, rendered_total='??')
chapter_download_futures.add(
pool.submit(download_chapter, chapter_download_task, session, viewer_url, chapter_info, chapter_dest, zeros, images_format)
Expand All @@ -442,7 +446,7 @@ def main():
return
series_url = args.url
separate = args.seperate or args.separate
download_webtoon(series_url, args.start, args.end, args.dest, args.images_format, args.latest, separate)
download_webtoon(series_url, args.start, args.end, args.dest, args.images_format, args.latest, separate, args.chapter_name)

if(__name__ == '__main__'):
main()