HoloArchivists / twspace-dl

A python module to download twitter spaces.
GNU General Public License v2.0
473 stars 78 forks source link

strftime didn't have %s and log file problem #49

Closed JC-Chung closed 2 years ago

JC-Chung commented 2 years ago

strftime() Format Codes didn't have %s and maybe means %f Microsecond as a decimal number, zero-padded to 6 digits. ? https://github.com/Ryu1845/twspace-dl/blob/daa6ab1d1fdf5f56f4b6d95717a5c0295d8b50cc/twspace_dl/__main__.py#L35 And this is the error that use %s

Traceback (most recent call last):
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\users\test01\appdata\local\programs\python\python39\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\test01\AppData\Local\Programs\Python\Python39\Scripts\twspace_dl.exe\__main__.py", line 7, in <module>
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 199, in main
    args.func(args)
  File "c:\users\test01\appdata\local\programs\python\python39\lib\site-packages\twspace_dl\__main__.py", line 34, in space
    log_filename = datetime.datetime.now().strftime(
ValueError: Invalid format string

Btw, the log file only write the last message like

2022-03-14 01:15:13,245 [INFO] Finished downloading

or

2022-03-14 01:17:14,383 [ERROR] Can't Download. Space has ended, can't retrieve master url. You can provide it with -f URL if you have it.

but in cmd screen even have like

2022-03-14 01:34:35,215 [INFO] ./[2022-03-12]creator_screen_name-id.m3u8 written to disk
2022-03-14 01:34:35,955 [INFO] .\tmppnmz5g9v\[2022-03-12]creator_screen_name-id.m3u8 written to disk

doesn't the two lines need write in log file, too?

Ryu1845 commented 2 years ago

Ah it comes from @eggplants, I should have checked more carefully. Thank you for the fix.

eggplants commented 2 years ago

@JC-Chung Thanks, and sorry @Ryu1845 ...

JC-Chung commented 2 years ago

And now the log file no matter [INFO] or [ERROR] both didn't show any info about the space, only know this time download is success or fail. But I don't know how to fix it...

Ryu1845 commented 2 years ago

And now the log file no matter [INFO] or [ERROR] both didn't show any info about the space, only know this time download is success or fail. But I don't know how to fix it...

That's on me, I need to log more.

eggplants commented 2 years ago

%s in strftime is not portable. In my environment it works. But there is possibility to raise ValueError in other environment, especially Windows.

Ref: https://stackoverflow.com/a/11743262

Python doesn't actually support %s as an argument to strftime (if you check at http://docs.python.org/library/datetime.html#strftime-and-strptime-behavior it's not in the list), the only reason it's working is because Python is passing the information to your system's strftime, which uses your local timezone.

%f is better.

JC-Chung commented 2 years ago

@Ryu1845 Sorry tags again, but --write-url URL_OUTPUT seems have small bug? It adds url like

https://.../master_playlist.m3u8https://.../master_playlist.m3u8https://.../master_playlist.m3u8...

instead of

https://.../master_playlist.m3u8
https://.../master_playlist.m3u8
https://.../master_playlist.m3u8
...
Ryu1845 commented 2 years ago

@Ryu1845 Sorry tags again, but --write-url URL_OUTPUT seems have small bug? It adds url like

https://.../master_playlist.m3u8https://.../master_playlist.m3u8https://.../master_playlist.m3u8...

instead of

https://.../master_playlist.m3u8
https://.../master_playlist.m3u8
https://.../master_playlist.m3u8
...

I guess I have to add a \n there https://github.com/Ryu1845/twspace-dl/blob/main/twspace_dl/__main__.py#L86

sonarcloud[bot] commented 2 years ago

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication