implemented comic download cli
This commit is contained in:
13
yoink/cli.py
13
yoink/cli.py
@@ -1,6 +1,9 @@
|
|||||||
|
from pydoc import cli
|
||||||
import click
|
import click
|
||||||
|
|
||||||
from yoink.common import qb_client, app_root, library_path, config_path
|
from yoink.common import qb_client, app_root, library_path, config_path
|
||||||
|
from yoink.comic import Comic, ComicArchiver
|
||||||
|
from yoink.torrent import Torrent, TorrentDownloader
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +20,15 @@ def download(url):
|
|||||||
click.echo('url cannot be blank')
|
click.echo('url cannot be blank')
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
click.echo('Downloading')
|
comic = Comic(url)
|
||||||
|
archiver = ComicArchiver(comic)
|
||||||
|
click.echo(f'Downloading {comic.title}')
|
||||||
|
archiver.download()
|
||||||
|
click.echo('Building comic archive')
|
||||||
|
archiver.generate_archive()
|
||||||
|
click.echo('Cleaning up')
|
||||||
|
archiver.cleanup_worktree()
|
||||||
|
click.echo('Success')
|
||||||
|
|
||||||
if __name__=='__main__':
|
if __name__=='__main__':
|
||||||
yoink()
|
yoink()
|
||||||
@@ -62,11 +62,12 @@ class ComicArchiver:
|
|||||||
if not os.path.exists(self.worktree):
|
if not os.path.exists(self.worktree):
|
||||||
os.makedirs(self.worktree, mode=0o777)
|
os.makedirs(self.worktree, mode=0o777)
|
||||||
|
|
||||||
for index,url in enumerate(self.comic.filelist):
|
|
||||||
opener = urllib.request.build_opener()
|
opener = urllib.request.build_opener()
|
||||||
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
|
opener.addheaders = [('User-Agent', 'Mozilla/5.0')]
|
||||||
urllib.request.install_opener(opener)
|
urllib.request.install_opener(opener)
|
||||||
|
|
||||||
|
for index,url in enumerate(self.comic.filelist):
|
||||||
|
|
||||||
if not url.endswith('.jpg'):
|
if not url.endswith('.jpg'):
|
||||||
formatted_file = os.path.join(self.worktree, f'{self.comic.title} ' + ''.join([str(index).zfill(3), '.jpg']))
|
formatted_file = os.path.join(self.worktree, f'{self.comic.title} ' + ''.join([str(index).zfill(3), '.jpg']))
|
||||||
print(formatted_file, end='\r')
|
print(formatted_file, end='\r')
|
||||||
@@ -75,6 +76,7 @@ class ComicArchiver:
|
|||||||
page_number = url.split('/')[-1].split('.')[0].zfill(3)
|
page_number = url.split('/')[-1].split('.')[0].zfill(3)
|
||||||
file_extension = url.split('/')[-1].split('.')[1]
|
file_extension = url.split('/')[-1].split('.')[1]
|
||||||
urllib.request.urlretrieve(url, filename=os.path.join(self.worktree, f'{self.comic.title}{page_number}.{file_extension}'))
|
urllib.request.urlretrieve(url, filename=os.path.join(self.worktree, f'{self.comic.title}{page_number}.{file_extension}'))
|
||||||
|
print()
|
||||||
|
|
||||||
def generate_archive(self, archive_format='.cbr'):
|
def generate_archive(self, archive_format='.cbr'):
|
||||||
if os.path.exists(os.path.join(self.worktree, f'{self.comic.title}{archive_format}')):
|
if os.path.exists(os.path.join(self.worktree, f'{self.comic.title}{archive_format}')):
|
||||||
|
|||||||
Reference in New Issue
Block a user