further pepping, spelling and other such things
This commit is contained in:
parent
6cc7554cd8
commit
cd5ae1d32b
12 changed files with 52 additions and 56 deletions
|
@ -14,10 +14,7 @@ video_url = "http://youtu.be/%s"
|
|||
|
||||
|
||||
def plural(num=0, text=''):
|
||||
return "{:,} {}{}".format(num, text, "s"[num==1:])
|
||||
|
||||
|
||||
|
||||
return "{:,} {}{}".format(num, text, "s"[num == 1:])
|
||||
|
||||
|
||||
def get_video_description(video_id):
|
||||
|
@ -41,22 +38,23 @@ def get_video_description(video_id):
|
|||
likes = plural(int(data['likeCount']), "like")
|
||||
dislikes = plural(data['ratingCount'] - int(data['likeCount']), "dislike")
|
||||
|
||||
percent = 100 * float(data['likeCount'])/float(data['ratingCount'])
|
||||
percent = 100 * float(data['likeCount']) / float(data['ratingCount'])
|
||||
out += u' - {}, {} (\x02{:.1f}\x02%)'.format(likes,
|
||||
dislikes, percent)
|
||||
dislikes, percent)
|
||||
|
||||
if 'viewCount' in data:
|
||||
views = data['viewCount']
|
||||
out += u' - \x02{:,}\x02 view{}'.format(views, "s"[views==1:])
|
||||
out += u' - \x02{:,}\x02 view{}'.format(views, "s"[views == 1:])
|
||||
|
||||
try:
|
||||
uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"]["$t"]
|
||||
uploader = http.get_json(base_url + "users/{}?alt=json".format(data["uploader"]))["entry"]["author"][0]["name"][
|
||||
"$t"]
|
||||
except:
|
||||
uploader = data["uploader"]
|
||||
|
||||
|
||||
upload_time = time.strptime(data['uploaded'], "%Y-%m-%dT%H:%M:%S.000Z")
|
||||
out += u' - \x02{}\x02 on \x02{}\x02'.format(uploader,
|
||||
time.strftime("%Y.%m.%d", upload_time))
|
||||
time.strftime("%Y.%m.%d", upload_time))
|
||||
|
||||
if 'contentRating' in data:
|
||||
out += u' - \x034NSFW\x02'
|
||||
|
@ -88,7 +86,6 @@ def youtube(inp):
|
|||
return get_video_description(video_id) + u" - " + video_url % video_id
|
||||
|
||||
|
||||
|
||||
@hook.command('ytime')
|
||||
@hook.command
|
||||
def youtime(inp):
|
||||
|
@ -119,8 +116,8 @@ def youtime(inp):
|
|||
total_text = timeformat.format_time(total, accuracy=8)
|
||||
|
||||
return u'The video \x02{}\x02 has a length of {} and has been viewed {:,} times for ' \
|
||||
'a total run time of {}!'.format(data['title'], length_text, views, \
|
||||
total_text)
|
||||
u'a total run time of {}!'.format(data['title'], length_text, views,
|
||||
total_text)
|
||||
|
||||
|
||||
ytpl_re = (r'(.*:)//(www.youtube.com/playlist|youtube.com/playlist)(:[0-9]+)?(.*)', re.I)
|
||||
|
@ -135,6 +132,6 @@ def ytplaylist_url(match):
|
|||
return "\x034\x02Invalid response."
|
||||
title = soup.find('title').text.split('-')[0].strip()
|
||||
author = soup.find('img', {'class': 'channel-header-profile-image'})['title']
|
||||
numvideos = soup.find('ul', {'class': 'header-stats'}).findAll('li')[0].text.split(' ')[0]
|
||||
num_videos = soup.find('ul', {'class': 'header-stats'}).findAll('li')[0].text.split(' ')[0]
|
||||
views = soup.find('ul', {'class': 'header-stats'}).findAll('li')[1].text.split(' ')[0]
|
||||
return u"\x02%s\x02 - \x02%s\x02 views - \x02%s\x02 videos - \x02%s\x02" % (title, views, numvideos, author)
|
||||
return u"\x02%s\x02 - \x02%s\x02 views - \x02%s\x02 videos - \x02%s\x02" % (title, views, num_videos, author)
|
||||
|
|
Reference in a new issue