Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Download books and extras into separate directories #27

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

Merged
niqdev merged 4 commits into niqdev:master from lszeremeta:master
Dec 7, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Download ebooks into separate directories
If path.separate is set to true in the configuration file, downloads books and extras into separate directory.
Examples:
ebooks/TITLE - AUTHOR/TITLE.pdf
...
ebooks/TITLE - AUTHOR/extras/TITLE.png
Note that if you use separate directories path.extras behaves differently.
The code is only a suggestion (preview) of new functionality, but works properly with local download. Other features to check (possible complications with Google Drive upload). Instead of setting this in the configuration file, separate or not directory can be changed by additional option from the command line.
  • Loading branch information
lszeremeta committed Dec 6, 2016
commit 688328e92d62085ce5110ca8a08d112f15cb35b2
3 changes: 2 additions & 1 deletion config/dev.cfg
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ credential.password=testPwd

[path]
path.ebooks=ebooks
path.extras=ebooks/extras
path.extras=extras
path.separate=true
Copy link
Owner

@niqdev niqdev Dec 6, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to avoid any regression, I suggest to

# leave the old path: unfortunately I have written no tests... my fault
path.extras=ebooks/extras
# add something like the following, default must be FALSE
path.separate=false
path.separate.ebooks=MY/EBOOKS/FOLDER
path.separate.extras=MY/EXTRAS/FOLDER

Updated Maybe instead of having path.separate=false just check if path.separate.extras is not empty ?

Copy link
Contributor Author

@lszeremeta lszeremeta Dec 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea. I also thought if true/false is actually needed. This can be changed. path.separate.ebooks and path.separate.extras is also a good idea. I will try to change this in the near future.

niqdev reacted with thumbs up emoji
Copy link
Contributor Author

@lszeremeta lszeremeta Dec 6, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first package of improvements: 5015a87
Config now do not even have to contain path.ebooks and path.extras. There can be only path.separate.ebooks and path.separate.extras.


[drive]
drive.oauth2_scope=https://www.googleapis.com/auth/drive
Expand Down
3 changes: 2 additions & 1 deletion config/prod_example.cfg
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ credential.password=PACKTPUB_PASSWORD

[path]
path.ebooks=ebooks
path.extras=ebooks/extras
path.extras=extras
path.separate=true

[drive]
drive.oauth2_scope=https://www.googleapis.com/auth/drive
Expand Down
7 changes: 7 additions & 0 deletions script/packtpub.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ def download_ebooks(self, types):
for type in types]

directory = self.__config.get('path', 'path.ebooks')

if self.__config.get('path', 'path.separate') == "true":
directory = directory + '/' + self.info['title'] + ' - ' + self.info['author']
Copy link
Owner

@niqdev niqdev Dec 6, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • use regexp on title and author to remove any extraneous character: restrict to [a-zA-Z] for example
  • try to avoid any space, I suggest to use _ as separator
  • maybe verify that if the folder is nested for some reason, the script doesn't throw any error (equivalent of unix mkdir -p /my/path/to/new/folder
  • I'm not a python ninja, so don't know if XXX == "true" is the best way for comparison or you prefer to check simply if path.separate.extras is not an empty string

Copy link
Contributor Author

@lszeremeta lszeremeta Dec 6, 2016
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're definitely right - checking variables is always desirable. Even though here should not appear anything wrong. I will try to add a regex for this. Probably [a-zA-Z] with single space, hyphen and comma.

Regarding to _ instead of spaces: I'm not entirely convinced. This is great for file names but for directory names less.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On unix system usually is desiderable to avoid empty space, if you prefer you can have also

path.separate.space=_

as default, so is configurable

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moreover to concatenate the string you could use .format() or any equivalent to make it more readable


for download in downloads_info:
self.info['paths'].append(
download_file(self.__session, download['url'], directory, download['filename'], self.__headers))
Expand All @@ -134,6 +138,9 @@ def download_extras(self):

directory = self.__config.get('path', 'path.extras')

if self.__config.get('path', 'path.separate') == "true":
directory = self.__config.get('path', 'path.ebooks') + '/' + self.info['title'] + ' - ' + self.info['author'] + '/' + directory

url_image = self.info['url_image']
filename = self.info['filename'] + '_' + split(url_image)[1]
self.info['paths'].append(download_file(self.__session, url_image, directory, filename, self.__headers))
Expand Down

AltStyle によって変換されたページ (->オリジナル) /