Ejemplo n.º 1
0
 async def info(self, ctx, video: str):
     if findvideo(video):
         video = findvideo(video)
     videoinfo = await self.loop.run_in_executor(None,
                                                 func=functools.partial(
                                                     self.video_info,
                                                     video))
     try:
         videoinfo = videoinfo['items'][0]
     except (KeyError, IndexError):
         return await ctx.error(
             f'Couldn\'t find a video. Please provide a valid YouTube video URL'
         )
     title = videoinfo['snippet']['title']
     vid = videoinfo['id']
     author = videoinfo['snippet']['channelTitle']
     authorid = videoinfo['snippet']['channelId']
     published = videoinfo['snippet']['publishedAt'].replace(
         'T', ' ').split('.')[0]
     duration = videoinfo['contentDetails']['duration'].replace(
         'PT', '').replace('H',
                           ' Hrs ').replace('M',
                                            ' Mins ').replace('S', 'Secs')
     description = videoinfo['snippet']['description']
     paginator = WrappedPaginator(
         prefix='```\nDescription (Use controls to change page)\n',
         suffix='```',
         max_size=1895)
     for line in description.split('\n'):
         paginator.add_line(line)
     views = format(
         int(videoinfo.get('statistics', {}).get('viewCount', 0)), ',d')
     likes = format(
         int(videoinfo.get('statistics', {}).get('likeCount', 0)), ',d')
     dislikes = format(
         int(videoinfo.get('statistics', {}).get('dislikeCount', 0)), ',d')
     comments = format(
         int(videoinfo.get('statistics', {}).get('commentCount', 0)), ',d')
     embed = discord.Embed(title=f"Video info for {video}",
                           color=ctx.author.color,
                           timestamp=datetime.datetime.utcnow())
     embed.add_field(
         name=videoinfo["snippet"]["title"],
         value=
         f"» Link: [{title}](https://youtu.be/{vid} 'Click here to watch the video')\n» Author: [{author}](https://youtube.com/channel/{authorid} 'Click here to checkout {author} channel')\n» Published: {published}\n» Views: {views}\n» Likes: {likes}\n» Dislikes: {dislikes}\n» Comments: {comments}",
         inline=False)
     interface = PaginatorEmbedInterface(ctx.bot,
                                         paginator,
                                         owner=ctx.author,
                                         _embed=embed)
     return await interface.send_to(ctx)
Ejemplo n.º 2
0
 async def handle_youtube(self, message, extra):
     ytcog = self.bot.get_cog('YouTube API')
     tosearch = str(message.system_content) + \
         str([e.to_dict() for e in message.embeds]) if not extra else extra
     video = findvideo(tosearch)
     channel = findchannel(tosearch)
     invalidvid = False
     invalidchannel = False
     if video:
         if not message.author.permissions_in(
                 message.channel).manage_messages:
             try:
                 await message.delete()
             except Exception:
                 pass
             vinfo = await ytcog.avideo_info(video)
             if vinfo:
                 info = vinfo[0]
                 logch = self.bot.get_config(
                     message.guild).get('log.action')
                 if logch:
                     description = f'**YouTube video sent in** {message.channel.mention}'
                     if video in extra:
                         if video in str(message.system_content) + str(
                             [e.to_dict() for e in message.embeds]):
                             return
                         description = f'**YouTube video found in external content**'
                     embed = discord.Embed(color=message.author.color,
                                           timestamp=message.created_at,
                                           description=description)
                     embed.set_author(name=message.author,
                                      icon_url=str(
                                          message.author.avatar_url_as(
                                              static_format='png',
                                              size=2048)))
                     embed.add_field(name='Video ID',
                                     value=video,
                                     inline=False)
                     if not invalidvid:
                         embed.add_field(
                             name='Title',
                             value=
                             f'[{info.get("snippet", {}).get("title", "Unknown")}](https://youtu.be/{video})',
                             inline=False)
                         embed.add_field(
                             name='Channel',
                             value=
                             f'[{info.get("snippet", {}).get("channelTitle", "Unknown")}](https://youtube.com/channel/{info.get("snippet", {}).get("channelId", "Unknown")})',
                             inline=False)
                         views = format(
                             int(info['statistics'].get('viewCount', 0)),
                             ',d')
                         likes = format(
                             int(info['statistics'].get('likeCount', 0)),
                             ',d')
                         dislikes = format(
                             int(info['statistics'].get('dislikeCount', 0)),
                             ',d')
                         comments = format(
                             int(info['statistics'].get('commentCount', 0)),
                             ',d')
                         embed.add_field(
                             name='Stats',
                             value=
                             f'{views} views, {likes} likes, {dislikes} dislikes, {comments} comments',
                             inline=False)
                     embed.set_footer(
                         text=f"Author ID: {message.author.id}")
                     try:
                         await logch.send(embed=embed)
                     except Exception:
                         pass
     if channel:
         if not message.author.permissions_in(
                 message.channel).manage_messages:
             try:
                 await message.delete()
             except Exception:
                 pass
             cinfo = await ytcog.achannel_info(channel)
             if cinfo:
                 info = cinfo[0]
                 logch = self.bot.get_config(
                     message.guild).get('log.action')
                 if logch:
                     description = f'**YouTube channel sent in** {message.channel.mention}'
                     if channel in extra:
                         if channel in str(message.system_content) + str(
                             [e.to_dict() for e in message.embeds]):
                             return
                         description = f'**YouTube channel found in external content**'
                     embed = discord.Embed(color=message.author.color,
                                           timestamp=message.created_at,
                                           description=description)
                     embed.set_author(name=message.author,
                                      icon_url=str(
                                          message.author.avatar_url_as(
                                              static_format='png',
                                              size=2048)))
                     if not invalidchannel:
                         embed.add_field(
                             name='Name',
                             value=
                             f'{info.get("snippet", {}).get("title", "Unknown")}',
                             inline=False)
                         embed.add_field(
                             name='Channel',
                             value=f'https://youtube.com/channel/{channel}')
                         embed.add_field(
                             name='Custom URL',
                             value=
                             f'https://youtube.com/{info.get("snippet", {}).get("customUrl", "N/A")}',
                             inline=False)
                         subs = format(
                             int(info['statistics'].get(
                                 'subscriberCount', 0)),
                             ',d') if not info['statistics'].get(
                                 'hiddenSubscriberCount',
                                 False) else 'Hidden'
                         views = format(
                             int(info['statistics'].get('viewCount', 0)),
                             ',d')
                         videos = format(
                             int(info['statistics'].get('videoCount', 0)),
                             ',d')
                         embed.add_field(
                             name='Stats',
                             value=
                             f'{subs} subscribers, {views} total views, {videos} videos',
                             inline=False)
                     embed.set_footer(
                         text=f"Author ID: {message.author.id}")
                     try:
                         await logch.send(embed=embed)
                     except Exception:
                         pass
Ejemplo n.º 3
0
 async def handle_youtube(self, message):
     ytcog = self.bot.get_cog('YouTube API')
     video = findvideo(message.system_content)
     channel = findchannel(message.system_content)
     invalidvid = False
     invalidchannel = False
     if video:
         if not message.author.permissions_in(message.channel).manage_messages:
             if 'youtube' in self.bot.configs[message.guild.id].get('mod.linkfilter'):
                 try:
                     await message.delete()
                 except Exception:
                     pass
                 videoinfo = await self.bot.loop.run_in_executor(None, func=functools.partial(ytcog.video_info, video))
                 videoinfo = videoinfo.get('items', [])
                 if len(videoinfo) >= 1:
                     videoinfo = videoinfo[0]
                     logch = self.bot.configs[message.guild.id].get('log.action')
                     if logch:
                         embed = discord.Embed(color=message.author.color, timestamp=message.created_at, description=f'**YouTube video sent in** {message.channel.mention}')
                         embed.set_author(name=message.author, icon_url=str(message.author.avatar_url_as(static_format='png', size=2048)))
                         embed.add_field(name='Video ID', value=video, inline=False)
                         if not invalidvid:
                             embed.add_field(name='Title', value=f'[{videoinfo.get("snippet", {}).get("title", "Unknown")}](https://youtu.be/{video})', inline=False)
                             embed.add_field(name='Channel', value=f'[{videoinfo.get("snippet", {}).get("channelTitle", "Unknown")}](https://youtube.com/channel/{videoinfo.get("snippet", {}).get("channelId", "Unknown")})', inline=False)
                             views = format(int(videoinfo['statistics'].get('viewCount', 0)), ',d')
                             likes = format(int(videoinfo['statistics'].get('likeCount', 0)), ',d')
                             dislikes = format(int(videoinfo['statistics'].get('dislikeCount', 0)), ',d')
                             comments = format(int(videoinfo['statistics'].get('commentCount', 0)), ',d')
                             embed.add_field(name='Stats', value=f'{views} views, {likes} likes, {dislikes} dislikes, {comments} comments', inline=False)
                         embed.set_footer(text=f"Author ID: {message.author.id}")
                         try:
                             await logch.send(embed=embed)
                         except Exception:
                             pass
     if channel:
         if not message.author.permissions_in(message.channel).manage_messages:
             if 'youtube' in self.bot.configs[message.guild.id].get('mod.linkfilter'):
                 try:
                     await message.delete()
                 except Exception:
                     pass
                 channelinfo = await self.bot.loop.run_in_executor(None, func=functools.partial(ytcog.channel_info, channel))
                 channelinfo = channelinfo.get('items', [])
                 if len(channelinfo) >= 1:
                     channelinfo = channelinfo[0]
                     logch = self.bot.configs[message.guild.id].get('log.action')
                     if logch:
                         embed = discord.Embed(color=message.author.color, timestamp=message.created_at, description=f'**YouTube channel sent in** {message.channel.mention}')
                         embed.set_author(name=message.author, icon_url=str(message.author.avatar_url_as(static_format='png', size=2048)))
                         if not invalidchannel:
                             embed.add_field(name='Name', value=f'{channelinfo.get("snippet", {}).get("title", "Unknown")}', inline=False)
                             embed.add_field(name='Channel', value=f'https://youtube.com/channel/{channel}')
                             embed.add_field(name='Custom URL', value=f'https://youtube.com/{channelinfo.get("snippet", {}).get("customUrl", "N/A")}', inline=False)
                             subs = format(int(channelinfo['statistics'].get('subscriberCount', 0)), ',d') if not channelinfo['statistics'].get('hiddenSubscriberCount', False) else 'Hidden'
                             views = format(int(channelinfo['statistics'].get('viewCount', 0)), ',d')
                             videos = format(int(channelinfo['statistics'].get('videoCount', 0)), ',d')
                             embed.add_field(name='Stats', value=f'{subs} subscribers, {views} total views, {videos} videos', inline=False)
                         embed.set_footer(text=f"Author ID: {message.author.id}")
                         try:
                             await logch.send(embed=embed)
                         except Exception:
                             pass