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

Download books and extras into separate directories #27

niqdev merged 4 commits into niqdev:master from lszeremeta:master
Dec 7, 2016

Conversation

@lszeremeta
Copy link
Contributor

@lszeremeta lszeremeta commented Dec 6, 2016
edited
Loading

Short description

If path.separate is set to true in the configuration file, downloads books and extras into separate directories.

Examples

If path.separate is set to true, path.ebooks=ebooks and path.extras=extras, ebooks and extras are downloaded to the following locations:
ebooks/TITLE - AUTHOR/TITLE.pdf
ebooks/TITLE - AUTHOR/extras/TITLE.png

Note that if you use separate directories, path.extras behaves differently:

If path.separate is set to false, path.ebooks=ebooks and path.extras=ebooks/extras, ebooks and extras are downloaded to the following locations:
ebooks/TITLE.pdf
ebooks/extras/TITLE.png

Disclaimer

The code is only a suggestion (preview) of new functionality, but works properly with local downloads. 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.

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.
Copy link
Owner

niqdev commented Dec 6, 2016

Hi! I like the idea, I will add few hints in the code directly, let me know what do you think!

config/dev.cfg Outdated
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.

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

Copy link
Contributor Author

Ok, I will try to do this in my free time, but I can not promise when exactly.

Copy link
Owner

niqdev commented Dec 6, 2016

No problem. Let me know if you have any other idea or suggestion.
Thanks

lszeremeta reacted with thumbs up emoji

path.separate=true
path.extras=ebooks/extras
#path.separate.ebooks=MY/EBOOKS/FOLDER
#path.separate.extras=MY/EXTRAS/FOLDER
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.

Perfect, I like it in this way with the has_option

lszeremeta reacted with thumbs up emoji
ifself.__config.get('path', 'path.separate') =="true":
directory = directory+'/'+self.info['title'] +' - '+self.info['author']
ifself.__config.has_option('path', 'path.separate.extras'):
directory=self.__config.get('path', 'path.separate.ebooks') +'/'+self.info['title'] +' - '+self.info['author']
Copy link
Owner

Choose a reason for hiding this comment

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

I'll wait to merge the request when you will add the sanity (regexp) check and the path.separate.space.
Maybe something like this should be already enough

.encode('ascii', 'ignore').replace(' ', '_')

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.

I just did it 😄
path.separate.space=? is for space.

@niqdev niqdev merged commit 852da5b into niqdev:master Dec 7, 2016
Copy link
Owner

niqdev commented Dec 7, 2016

Thanks for your contribution!

lszeremeta reacted with thumbs up emoji

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@niqdev niqdev niqdev left review comments

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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