mps-youtube / yewtube

yewtube, forked from mps-youtube , is a Terminal based YouTube player and downloader. No Youtube API key required.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Crashing when perfomrming a playlist search

bvvt opened this issue · comments

commented

Issue / Suggestion

The following message apears when I perform a playlist search:

Searching playlists for swag                                                                                                                             
Traceback (most recent call last):
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/main.py", line 65, in matchfunction
    func(*matches)
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/commands/search.py", line 386, in pl_search
    g.content = content.generate_playlist_display()
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/content.py", line 155, in generate_playlist_display
    updated = yt_datetime(x.get('updated'))[1]
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/util.py", line 315, in yt_datetime
    time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%S.%fZ")
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 562, in _strptime_time
    tt = _strptime(data_string, format)[0]
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2020-08-31T15:32:25Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/bin/mpsyt", line 33, in <module>
    sys.exit(load_entry_point('mps-youtube==0.2.8', 'console_scripts', 'mpsyt')())
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/main.py", line 148, in main
    if matchfunction(i.function, i.regex, userinput):
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/main.py", line 80, in matchfunction
    content.generate_songlist_display(zeromsg=g.message)
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/content.py", line 74, in generate_songlist_display
    return generate_playlist_display()
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/content.py", line 155, in generate_playlist_display
    updated = yt_datetime(x.get('updated'))[1]
  File "/usr/local/Cellar/mps-youtube/0.2.8_11/libexec/lib/python3.9/site-packages/mps_youtube/util.py", line 315, in yt_datetime
    time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%S.%fZ")
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 562, in _strptime_time
    tt = _strptime(data_string, format)[0]
  File "/usr/local/Cellar/python@3.9/3.9.7/Frameworks/Python.framework/Versions/3.9/lib/python3.9/_strptime.py", line 349, in _strptime
    raise ValueError("time data %r does not match format %r" %
ValueError: time data '2020-08-31T15:32:25Z' does not match format '%Y-%m-%dT%H:%M:%S.%fZ'

Your Environment

mpsyt --version info:

mpsyt version      : 0.2.8
   notes           : released 17 February 2018
pafy version       : 0.5.5 (youtube-dl backend)
youtube-dl version : 2020.05.03
Python version     : 3.9.7 (default, Sep  3 2021, 12:37:55) 
[Clang 12.0.5 (clang-1205.0.22.9)]
Processor          : i386
Machine type       : x86_64
Architecture       : 64bit, 
Platform           : macOS-11.5.2-x86_64-i386-64bit
sys.stdout.enc     : utf-8
default enc        : utf-8
Config dir         : ~/.config/mps-youtube
env:TERM           : xterm-256color
env:SHELL          : /bin/bash
env:LANG           : fr_CH.UTF-8

Running Mac OS Big Sur 11.5.2

Using mplayer 1.4

This is apparently because there's a difference in time results from out of the current queries.

For a workaround/fix for this, you can edit util.py in the source/install to reflect this...

def yt_datetime(yt_date_time):
""" Return a time object, locale formated date string and locale formatted time string. """
try:
time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%S.%fZ")

except:        
    time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%SZ")
    
locale_date = time.strftime("%x", time_obj)
locale_time = time.strftime("%X", time_obj)
# strip first two digits of four digit year
short_date = re.sub(r"(\d\d\D\d\d\D)20(\d\d)$", r"\1\2", locale_date)
return time_obj, short_date, locale_time

def yt_datetime_local(yt_date_time):
""" Return a datetime object, locale converted and formated date string and locale converted and formatted time string. """
try:
time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%S.%fZ")

except:        
    time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%SZ")
    
datetime_obj = utc2local(datetime_obj)
locale_date = datetime_obj.strftime("%x")
locale_time = datetime_obj.strftime("%X")
# strip first two digits of four digit year
short_date = re.sub(r"(\d\d\D\d\d\D)20(\d\d)$", r"\1\2", locale_date)
return datetime_obj, short_date, locale_time

Where there's a try/except block such that if the first and preferred fails, the apparent alternate is ran instead. The drawback to this is that there might be "more" of those and you may still run into problems. This, however, fixed the playlist search