Skip to content

Commit

Permalink
update subcmd of ebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jachinlin committed Nov 27, 2018
1 parent 66b9704 commit 3f54942
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ docker run -v `pwd`:/output -it --rm geektime mp3batch --all
- [X] MP3 and MP4
- [X] comments
- [X] batch download
- [X] docker
- [ ] support mathjax
- [ ] support windows
- [ ] ...
Expand Down
30 changes: 18 additions & 12 deletions geektime_dl/cli/ebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ class EBook(Command):
"""

@staticmethod
def render_column_source_files(course_intro, course_content, out_dir, force=False):
def _title(c):
if not c['had_sub']:
t = c['column_title'] + '[免费试读]'
elif c['update_frequency'] == '全集':
t = c['column_title'] + '[更新完毕]'
else:
t = c['column_title'] + '[未完待续]'
return t

def render_column_source_files(self, course_intro, course_content, out_dir, force=False):

# TODO refactor here
# cover and introduction
Expand All @@ -47,16 +56,7 @@ def render_column_source_files(course_intro, course_content, out_dir, force=Fals
maker.generate_cover_img(course_intro['column_cover'], output_dir)
print('下载' + column_title + '封面' + ' done')

def _title(c):
if not c['had_sub']:
t = c['column_title'] + '[免费试读]'
elif c['update_frequency'] == '全集':
t = c['column_title'] + '[更新完毕]'
else:
t = c['column_title'] + '[未完待续]'
return t

ebook_name = _title(course_intro)
ebook_name = self._title(course_intro)
maker.render_toc_md(
ebook_name + '\n',
['# 简介\n'] + ['# ' + maker.format_file_name(t['article_title']) + '\n' for t in articles],
Expand Down Expand Up @@ -117,7 +117,10 @@ def run(self, args):

# ebook
if not source_only:
make_mobi(source_dir=os.path.join(out_dir, course_data['column_title']), output_dir=out_dir)
if course_data['update_frequency'] == '全集' and os.path.isfile(os.path.join(out_dir, self._title(course_data)) + '.mobi'):
print("{} exists ".format(self._title(course_data)))
else:
make_mobi(source_dir=os.path.join(out_dir, course_data['column_title']), output_dir=out_dir)

def _timestamp2str(self, timestamp):
if not timestamp:
Expand Down Expand Up @@ -185,15 +188,18 @@ def run(self, args):
continue
if c['update_frequency'] == '全集':
super(EbookBatch, self).run([str(c['id'])] + args)
print('\n')
else:
super(EbookBatch, self).run([str(c['id']), '--source-only'] + args)
print('\n')

else:
course_ids = args[0]
cid_list = course_ids.split(',')

for cid in cid_list:
super(EbookBatch, self).run([cid.strip()] + args)
print('\n')



0 comments on commit 3f54942

Please sign in to comment.