Skip to content

Commit

Permalink
add "time" column which shows uploaded time in UTC
Browse files Browse the repository at this point in the history
  • Loading branch information
akaWolf committed Jan 25, 2017
1 parent 62d9cf7 commit 504534a
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion mps_youtube/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def fetch_comments(item):
for n, com in enumerate(coms, 1):
snippet = com.get('snippet', {})
poster = snippet.get('authorDisplayName')
_, shortdate = util.yt_datetime(snippet.get('publishedAt', ''))
shortdate = util.yt_datetime(snippet.get('publishedAt', ''))[1]
text = snippet.get('textDisplay', '')
cid = ("%s/%s" % (n, len(coms)))
commentstext += ("%s %-35s %s\n" % (cid, c.c("g", poster), shortdate))
Expand Down
4 changes: 3 additions & 1 deletion mps_youtube/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ def get_tracks_from_json(jsons):
#XXX this is a very poor attempt to calculate a rating value
rating = 5.*likes/(likes+dislikes) if (likes+dislikes) > 0 else 0
category = snippet.get('categoryId')
publisheddatetime = util.yt_datetime(snippet.get('publishedAt', ''))

# cache video information in custom global variable store
g.meta[ytid] = dict(
Expand All @@ -420,7 +421,8 @@ def get_tracks_from_json(jsons):
uploaderName=snippet.get('channelTitle'),
category=category,
aspect="custom", #XXX
uploaded=util.yt_datetime(snippet.get('publishedAt', ''))[1],
uploaded=publisheddatetime[1],
uploadedTime=publisheddatetime[2],
likes=str(num_repr(likes)),
dislikes=str(num_repr(dislikes)),
commentCount=str(num_repr(int(stats.get('commentCount', 0)))),
Expand Down
5 changes: 3 additions & 2 deletions mps_youtube/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def generate_songlist_display(song=False, zeromsg=None):
user_columns = _get_user_columns() if have_meta else []
maxlength = max(x.length for x in g.model)
lengthsize = 8 if maxlength > 35999 else 7
lengthsize = 5 if maxlength < 6000 else lengthsize
lengthsize = 6 if maxlength < 6000 else lengthsize
reserved = 9 + lengthsize + len(user_columns)
cw = getxy().width
cw -= 1
title_size = cw - sum(1 + x['size'] for x in user_columns) - reserved
before = [{"name": "idx", "size": 3, "heading": "Num"},
{"name": "title", "size": title_size, "heading": "Title"}]
after = [{"name": "length", "size": lengthsize, "heading": "Time"}]
after = [{"name": "length", "size": lengthsize, "heading": "Length"}]
columns = before + user_columns + after

for n, column in enumerate(columns):
Expand Down Expand Up @@ -167,6 +167,7 @@ def _get_user_columns():
"rating": dict(name="rating", size=4, heading="Rtng"),
"comments": dict(name="commentCount", size=4, heading="Comm"),
"date": dict(name="uploaded", size=8, heading="Date"),
"time": dict(name="uploadedTime", size=11, heading="Time"),
"user": dict(name="uploaderName", size=10, heading="User"),
"likes": dict(name="likes", size=4, heading="Like"),
"dislikes": dict(name="dislikes", size=4, heading="Dslk"),
Expand Down
2 changes: 1 addition & 1 deletion mps_youtube/helptext.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def helptext():
{2}set all default{1} - restore default settings
{2}set checkupdate true|false{1} - check for updates on exit
{2}set columns <columns>{1} - select extra displayed fields in search results:
(valid: views comments rating date user likes dislikes category)
(valid: views comments rating date time user likes dislikes category)
{2}set ddir <download direcory>{1} - set where downloads are saved
{2}set download_command <command>{1} - type {2}help dl-command{1} for info
{2}set encoder <number>{1} - set encoding preset for downloaded files
Expand Down
5 changes: 3 additions & 2 deletions mps_youtube/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,13 @@ def real_len(u, alt=False):


def yt_datetime(yt_date_time):
""" Return a time object and locale formated date string. """
""" Return a time object, locale formated date string and locale formatted time string. """
time_obj = time.strptime(yt_date_time, "%Y-%m-%dT%H:%M:%S.%fZ")
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
return time_obj, short_date, locale_time


def parse_multi(choice, end=None):
Expand Down

0 comments on commit 504534a

Please sign in to comment.