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

Added the ability to choose the id to name the downloaded files #32

Closed
wants to merge 2 commits into from
Closed
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
12 changes: 7 additions & 5 deletions docs/config_readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ In general, try to match the format of the default `config.txt`, i.e.:
"cache_size": 65536,
"create_subdirectories": false,
"download_directory": "downloads/",
"part_used_as_name": "md5"
"last_run": "2014-06-21",
"parallel_downloads": 6,
"tag_file": "tags.txt"
Expand All @@ -28,11 +29,12 @@ Note that for the `cache_size`, `create_subdirectories`, and `parallel_downloads

### Common Settings

| Option Name | Quotes? | Acceptable Range | Description |
| --------------------- | ------- | --------------------------- |----------------------------------------------------------- |
| download_directory | Yes | anything | path where **e621dl** puts downloads (must end with `/`) |
| create_subdirectories | No | `true` or `false` | create a subfolder for each line in tag file if true |
| last_run | Yes | date (format: `YYYY-MM-DD`) | the last day **e621dl** was last run |
| Option Name | Quotes? | Acceptable Range | Description |
| --------------------- | ------- | --------------------------- |-------------------------------------------------------------------- |
| download_directory | Yes | anything | path where **e621dl** puts downloads (must end with `/`) |
| part_used_as_name | Yes | `md5` or `id` | what to put in the name of the downloaded, the hash, or the post id |
| create_subdirectories | No | `true` or `false` | create a subfolder for each line in tag file if true |
| last_run | Yes | date (format: `YYYY-MM-DD`) | the last day **e621dl** was last run |


### Advanced Settings
Expand Down
1 change: 1 addition & 0 deletions lib/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'cache_name': ".cache",
'cache_size': 65536,
'download_directory': "downloads/",
'part_used_as_name': "md5"
'last_run': datetime.now().strftime(DATETIME_FMT),
'tag_file': "tags.txt",
'parallel_downloads': 8,
Expand Down
4 changes: 2 additions & 2 deletions lib/e621_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from collections import namedtuple
import logging

UPLOAD = namedtuple('Upload', 'url md5 ext')
UPLOAD = namedtuple('Upload', 'id url md5 ext')
SPOOF = SpoofOpen()

LIST_BASE = 'https://e621.net/post/index.json?'
Expand All @@ -27,7 +27,7 @@ def get_posts(search_term, uploaded_after, page_num, max_results):

uploads = []
for post in results:
uploads.append(UPLOAD(post['file_url'], post['md5'], post['file_ext']))
uploads.append(UPLOAD(post['id'], post['file_url'], post['md5'], post['file_ext']))
return uploads

def download(url, filename):
Expand Down
11 changes: 9 additions & 2 deletions lib/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ def safe_filename(tag_line, item, config_dict):
if config_dict['create_subdirectories'] == True:
if not os.path.isdir(config_dict['download_directory'] + safe_tagline.decode('utf-8')):
os.makedirs(config_dict['download_directory'] + safe_tagline)
safe_filename = safe_tagline + '/' + item.md5 + '.' + item.ext

name_format = str(getattr(item, config_dict['part_used_as_name']))
safe_filename = safe_tagline + '/' + str(name_format) + '.' + item.ext

else:
safe_filename = safe_tagline.decode('utf-8') + '_' + item.md5.decode('utf-8') + '.' + item.ext.decode('utf-8')
name_format = str(getattr(item, config_dict['part_used_as_name']).decode('utf-8'))
safe_filename = safe_tagline.decode('utf-8') + '_' + str(item.id.decode('utf-8')) + '.' + item.ext.decode('utf-8')

return safe_filename

Expand All @@ -136,6 +139,10 @@ def validate_config(c):
assert bool(re.match(r'\d{4}-\d{2}-\d{2}', c['last_run'])) == True, \
"'last_run' format must be: \"YYYY-MM-DD\" (quotes required"

assert c['part_used_as_name'] == "id" or \
c['part_used_as_name'] == "md5", \
"'part_used_as_name' must be 'id' or 'md5'"

if not os.path.exists(c['download_directory']):
log.info('empty download directory created')
os.makedirs(c['download_directory'])
Expand Down