AlphaSlayer1964 / kemono-dl

A simple kemono.party downloader using python.
506 stars 82 forks source link

Error with date while updating #45

Closed MagicalKyaru closed 2 years ago

MagicalKyaru commented 2 years ago

Version

Version: 2021.12.30.01

Site, Service, User ID, Post ID

Your Command


python3 /kemono-dl-2021.12.30.01/kemono-dl.py --cookies "/kemono-dl-2021.12.30.01/cookie.txt" -o /kemono-dl-2021.12.30.01/Downloads/ --kemono-favorite-users --update-posts --skip-content --skip-comments

Description of bug

Error with date when running with --update-posts on a post already downloaded.

How To Reproduce

  1. Download post linked.
  2. Run again with --update-posts.

Error messages and tracebacks

INFO: Post: アーケードダヴィンチちゃんバックハメ-高画質版
Traceback (most recent call last):
  File "/home/freebox/kemono-dl-2021.12.30.01/kemono-dl.py", line 4, in <module>
    main()
  File "/home/freebox/kemono-dl-2021.12.30.01/src/main.py", line 610, in main
    D.download_posts()
  File "/home/freebox/kemono-dl-2021.12.30.01/src/main.py", line 159, in download_posts
    if self._should_download():
  File "/home/freebox/kemono-dl-2021.12.30.01/src/main.py", line 207, in _should_download
    current_post_date = datetime.datetime.strptime(self.current_post['edited'], r'%a, %d %b %Y %H:%M:%S %Z')
TypeError: strptime() argument 1 must be str, not None

Additional comments

Happens with the posts that return "null" in the edited field of the json.

Quick fix

Not a good looking fix but it works for those who want to fix it asap.

In main.py l.205

                with open(json_path, 'r') as f:
                    data = json.loads(f.read())
                # Check if remote edit is null. If it is, logs that we cannot verify the date.
                if data['edited'] is None:
                    logger.info("Cannot verify if post has been updated.")
                    return False
               # Check if local edit is null while the remote isn't. It just skips the next part checking the dates.
                elif self.current_post['edited'] is None:
                    logger.info("Updating post.")
                else:
                    current_post_date = datetime.datetime.strptime(self.current_post['edited'], r'%a, %d %b %Y %H:%M:%S %Z')
                    old_post_date = datetime.datetime.strptime(data['edited'], r'%a, %d %b %Y %H:%M:%S %Z')
                    if old_post_date > current_post_date:
                        logger.info("Skipping Post: Post is up to date")
                        return False
AlphaSlayer1964 commented 2 years ago

Will add a fix by tonight didn't know the edited value could store null.

AlphaSlayer1964 commented 2 years ago

Release 2021.12.31 has fixed this issue