Compare commits
3 Commits
c1439ca4c5
...
9c8203d433
Author | SHA1 | Date | |
---|---|---|---|
9c8203d433 | |||
9ba23e9a29 | |||
5fe240db8b |
@ -49,8 +49,8 @@ class McManiac(DatabasePlugin):
|
||||
if result:
|
||||
return '[{rank}/{total}] {item}'.format(**result)
|
||||
|
||||
@irc3.event(r'^:(?P<mask>\S+) PRIVMSG \S+ :.*?\b(?P<item>Mc\S+iaC)\b.*')
|
||||
def save(self, mask: str, item: str):
|
||||
@irc3.event(r'^:(?P<mask>\S+) PRIVMSG (?P<channel>#\S+) :.*?\b(?P<item>Mc\S+iaC)\b.*')
|
||||
def save(self, mask: str, channel: str, item: str):
|
||||
if IrcString(mask).nick != self.bot.nick:
|
||||
with self.con.cursor() as cur:
|
||||
cur.execute('''
|
||||
@ -59,5 +59,11 @@ class McManiac(DatabasePlugin):
|
||||
VALUES
|
||||
(%s)
|
||||
ON CONFLICT DO NOTHING
|
||||
RETURNING
|
||||
(SELECT (count(*) + 1) AS total FROM mcmaniacs)
|
||||
''', [item])
|
||||
self.con.commit()
|
||||
result = cur.fetchone()
|
||||
if result is None:
|
||||
return
|
||||
self.bot.privmsg(channel, f"{result['total']}. mcmanic added: {item}")
|
||||
|
@ -16,6 +16,7 @@ class YouTube(Plugin):
|
||||
URL = 'https://www.googleapis.com/youtube/v3'
|
||||
API = '{}/videos?part=snippet,statistics,contentDetails'.format(URL)
|
||||
SEARCH = '{}/search?part=id'.format(URL)
|
||||
RETURN_YOUTUBE_DISLIKE_API = 'https://returnyoutubedislikeapi.com/votes'
|
||||
|
||||
def get_video_data(self, video_id: str):
|
||||
"""Requests the infos for a video id and formats them."""
|
||||
@ -24,13 +25,15 @@ class YouTube(Plugin):
|
||||
if not data.get('items'):
|
||||
return
|
||||
|
||||
return_youtube_dislike_response = requests.get(self.RETURN_YOUTUBE_DISLIKE_API, params={'videoId': video_id}).json()
|
||||
|
||||
item = data['items'][0]
|
||||
date = date_from_iso(item['snippet']['publishedAt'])
|
||||
length = re.findall('(\d+[DHMS])', item['contentDetails']['duration'])
|
||||
|
||||
views = int(item['statistics'].get('viewCount', 0))
|
||||
likes = int(item['statistics'].get('likeCount', 0))
|
||||
dislikes = int(item['statistics'].get('dislikeCount', 0))
|
||||
dislikes = int(return_youtube_dislike_response.get('dislikes', 0))
|
||||
|
||||
try:
|
||||
score = 100 * float(likes) / (likes + dislikes)
|
||||
|
Loading…
Reference in New Issue
Block a user