mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.
GNU General Public License v3.0
8.07k stars 645 forks source link

Problem playing last item: unconverted data remains: Z #1101

Closed louisabraham closed 1 year ago

louisabraham commented 4 years ago

Issue

When trying to display information about a search result with i 1, I get the following error:

Problem playing last item: unconverted data remains: Z

Your Environment

I installed mpsyt from the github repository.

mpsyt version      : 0.2.8
   notes           : released 17 February 2018
pafy version       : 0.5.5 (youtube-dl backend)
youtube-dl version : 2020.06.16.1
Python version     : 3.8.3 (default, May 19 2020, 23:51:58) 
[GCC 9.3.0]
Processor          : 
Machine type       : aarch64
Architecture       : 64bit, ELF
Platform           : Linux-5.7.0-2-MANJARO-ARM-aarch64-with-glibc2.17
sys.stdout.enc     : utf-8
default enc        : utf-8
Config dir         : /home/louisabraham/.config/mps-youtube
env:TERM           : xterm-256color
env:SHELL          : /bin/bash
env:LANG           : en_US.utf8
poyenc commented 4 years ago

The root cause is that when mpsyt trying to parse video published date string, the employed function datetime.datetime.strptime() did not recognize the ending Z, which is time zone designator, in date string. (defined by ISO 8601 according to YouTube Data API v3)

In function commands.misc.video_info() (or commands.misc.info() in older version), we can simply add Z in the format string to avoid this error, but I think we need more graceful way to handle this issue.

    elif g.browse_mode == "normal":
        g.content = logo(c.b)
        screen.update()
        screen.writestatus("Fetching video metadata..")
        item = (g.model[int(num) - 1])
        streams.get(item)
        p = util.get_pafy(item)
-       pub = datetime.strptime(str(p.published), "%Y-%m-%d %H:%M:%S")
+       pub = datetime.strptime(str(p.published), "%Y-%m-%d %H:%M:%SZ")
        pub = util.utc2local(pub)
        screen.writestatus("Fetched")
        out = c.ul + "Video Info" + c.w + "\n\n"
louisabraham commented 4 years ago

I think it's ok to put a condition to test if the last character is Z (in case the API drops it). What do you imagine could be more graceful?

poyenc commented 4 years ago

For this issue, I think we can assume there will always be an ending Z in date string, like the usages in util.py.

For long-term development, it is better to wrap all the date string manipulation logic into a single library. And handle them conditionally if necessary.