diff --git a/e621dl.py b/e621dl.py index d39b802..175fa46 100755 --- a/e621dl.py +++ b/e621dl.py @@ -15,7 +15,7 @@ if __name__ == '__main__': # Create the requests session that will be used throughout the run. with remote.requests_retry_session() as session: - # Set the user-agent. Requirements are specified at https://e621.net/help/show/api#basics. + # Set the user-agent. Requirements are specified at https://e621.net/wiki_pages/2425#Basics. session.headers['User-Agent'] = f"e621dl.py/{constants.VERSION} (by Wulfre)" # Check if a new version is released on github. If so, notify the user. @@ -23,10 +23,6 @@ print('A NEW VERSION OF e621dl IS AVAILABLE ON GITHUB AT https://github.com/Wulfre/e621dl/releases/latest.') print(f"[i] Running e621dl version {constants.VERSION}.") - print('') - print("[i] Checking for partial downloads...") - - remote.finish_partial_downloads(session) print('') print("[i] Parsing config...") @@ -36,9 +32,18 @@ # Initialize the lists that will be used to filter posts. searches = [] - # Initialize last_id + # Initialize last_id. last_id = None + # Initialize login information. + login = { + 'username': config['login'].get('username'), + 'api_key': config['login'].get('api_key') + } + + if login['username'] or login['api_key'] == None: + print('[i] No login detected. Some posts may be hidden and unable to be downloaded.') + # Initialize user configured options in case any are missing. default_days = config['default_search'].get('days', 1) default_score = config['default_search'].get('min_score', -0x7F_FF_FF_FF) @@ -70,6 +75,10 @@ 'earliest_date': section_date }) + print('') + print("[i] Checking for partial downloads...") + remote.finish_partial_downloads(session) + for search in searches: print('') @@ -83,7 +92,7 @@ # Sets up a loop that will continue indefinitely until the last post of a search has been found. while True: print("[i] Getting posts...") - results = remote.get_posts(search_string, search['earliest_date'], last_id, session)['posts'] + results = remote.get_posts(search_string, search['earliest_date'], last_id, login, session)['posts'] # Gets the id of the last post found in the search so that the search can continue. try: diff --git a/e621dl/constants.py b/e621dl/constants.py index b2fb412..88e866a 100644 --- a/e621dl/constants.py +++ b/e621dl/constants.py @@ -4,7 +4,11 @@ MAX_TAGS = 38 PARTIAL_DOWNLOAD_EXT = 'request' -DEFAULT_CONFIG_TEXT = '''default_search: +DEFAULT_CONFIG_TEXT = '''login: + username: + api_key: + +default_search: days: 1 min_score: 0 min_favs: 0 diff --git a/e621dl/remote.py b/e621dl/remote.py index c282ceb..edcb332 100644 --- a/e621dl/remote.py +++ b/e621dl/remote.py @@ -55,11 +55,13 @@ def get_github_release(session): return response.json()['tag_name'].strip('v') -def get_posts(search_string, earliest_date, last_id, session): +def get_posts(search_string, earliest_date, last_id, login, session): url = 'https://e621.net/posts.json' payload = { 'limit': constants.MAX_RESULTS, - 'tags': f"date:>={earliest_date} {search_string}" + 'tags': f"date:>={earliest_date} {search_string}", + 'login': login['username'], + 'api_key': login['api_key'] } if last_id: