diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 679400a8..c96658ec 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -343,9 +343,16 @@ class Extractor(): return if reason: - t = dt.datetime.fromtimestamp(until).time() - isotime = f"{t.hour:02}:{t.minute:02}:{t.second:02}" - self.log.info("Waiting until %s (%s)", isotime, reason) + if seconds >= 3600.0: + h, m = divmod(seconds, 3600.0) + dur = f"{int(h)}h {int(m/60.0)}min" + elif seconds >= 60.0: + dur = str(int(seconds/60.0)) + " minutes" + else: + dur = str(int(seconds)) + " seconds" + t = time.localtime(until) + iso = f"{t.tm_hour:02}:{t.tm_min:02}:{t.tm_sec:02}" + self.log.info("Waiting for %s until %s (%s)", dur, iso, reason) time.sleep(seconds) def sleep(self, seconds, reason): diff --git a/test/test_extractor.py b/test/test_extractor.py index 4ade9b71..94c3d867 100644 --- a/test/test_extractor.py +++ b/test/test_extractor.py @@ -217,7 +217,23 @@ class TestExtractorWait(unittest.TestCase): calls = log.info.mock_calls self.assertEqual(len(calls), 1) - self._assert_isotime(calls[0][1][1], until) + self.assertEqual(calls[0][1][1], "6 seconds") + self._assert_isotime(calls[0][1][2], until) + + def test_wait_seconds_long(self): + extr = extractor.find("generic:https://example.org/") + seconds = 5000 + until = time.time() + seconds + + with patch("time.sleep") as sleep, patch.object(extr, "log") as log: + extr.wait(seconds=seconds) + + sleep.assert_called_once_with(5001.0) + + calls = log.info.mock_calls + self.assertEqual(len(calls), 1) + self.assertEqual(calls[0][1][1], "1h 23min") + self._assert_isotime(calls[0][1][2], until) def test_wait_until(self): extr = extractor.find("generic:https://example.org/") @@ -232,7 +248,8 @@ class TestExtractorWait(unittest.TestCase): calls = log.info.mock_calls self.assertEqual(len(calls), 1) - self._assert_isotime(calls[0][1][1], until) + self.assertEqual(calls[0][1][1], "5 seconds") + self._assert_isotime(calls[0][1][2], until) def test_wait_until_datetime(self): extr = extractor.find("generic:https://example.org/") @@ -251,7 +268,8 @@ class TestExtractorWait(unittest.TestCase): calls = log.info.mock_calls self.assertEqual(len(calls), 1) - self._assert_isotime(calls[0][1][1], until_local) + self.assertEqual(calls[0][1][1], "5 seconds") + self._assert_isotime(calls[0][1][2], until_local) def _assert_isotime(self, output, until): if not isinstance(until, dt.datetime):