예제 #1
0
파일: music.py 프로젝트: OGNova/airplane
 def on_play(self, event, url):
     g = Guild.select(Guild).where((Guild.guild_id == event.guild.id)).get()
     
     if g.premium == False:
       raise CommandFail('This guild does not have premium enabled, please contact an Airplane global administrator.')
     
     # item = YoutubeDLInput(url, command='ffmpeg').pipe(BufferedOpusEncoderPlayable)
     # self.get_player(event.guild.id).queue.append(item)
     item = YoutubeDLInput(url)
     song = item.info
     if song['extractor'] is 'youtube':
         if song['is_live']:
             raise CommandFail('Sorry, live streams are not supported.')
     if song['duration'] > 7200:
         raise CommandFail('Sorry you are not allowed to play songs over 2 hours.')
     if song['duration'] > event.config.max_song_length:
         raise CommandFail('Sorry, you may not go over the server time limit.')
     item2 = item.pipe(BufferedOpusEncoderPlayable)
     self.get_player(event.guild.id).queue.append(item2)
     song = item.info
     if song['extractor'] is 'youtube':
         if song['artist']:
             return event.msg.reply('Now playing **{songname}** by **{author}**. Song length is `{duration}`'.format(songname=song['alt_title'], author=song['artist'], duration=timedelta(seconds=song['duration'])))
         else:
             return event.msg.reply('Now playing **{songname}** uploaded by **{author}**. Song length is `{duration}`'.format(songname=song['title'], author=song['uploader'], duration=timedelta(seconds=song['duration'])))
     else:
         return CommandSuccess('You\'re playing a song :D')
예제 #2
0
 def on_playlist_command(self, event, to_shuffle, url=""):
     """
     Voice Used to load the music from a youtube playlist link.
     If the first argument is in the list:
     "shuffle" or "Shuffle",
     then the playlist will be shuffled before it's loaded.
     Only accepts links that match youtube's link formats.
     and will load the items of the playlist into the player queue.
     """
     self.pre_check(event)
     if to_shuffle != "shuffle" and to_shuffle != "Shuffle":
         url = "{} {}".format(to_shuffle, url)
         to_shuffle = "no"
     url_not_found = False
     for url_format in ("https://www.youtube.com/playlist?list=",
                        "https://youtube.com/playlist?list=",
                        "https://youtu.be"):
         if url_format in url:
             url_not_found = True
     if not url_not_found:
         return api_loop(
             event.channel.send_message,
             "Invalid youtube playlist link.",
         )
     if event.guild.get_member(event.author).get_voice_state():
         self.on_join(event)
     self.same_channel_check(event)
     if (event.author.id not in self.cool_down["general"]
             or time() - self.cool_down["general"][event.author.id] >= 1):
         if (event.guild.id not in self.cool_down["playlist"]
                 or not self.cool_down["playlist"][event.guild.id]):
             self.cool_down["playlist"][event.guild.id] = True
             self.cool_down["general"][event.author.id] = time()
             videos_added = 0
             many_object = YoutubeDLInput.many(url, command="ffmpeg")
             try:
                 many_object = list(many_object)
             except Exception as e:
                 return api_loop(
                     event.channel.send_message,
                     "Playlist not found: {}".format(e),
                 )
             if to_shuffle == "shuffle" or to_shuffle == "Shuffle":
                 shuffle(many_object)
             message = api_loop(
                 event.channel.send_message,
                 "Adding music from playlist.",
             )
             for youtubedl_object in many_object:
                 try:
                     yt_data = self.get_ytdl_values(youtubedl_object.info)
                 except DownloadError as e:
                     continue
                 if yt_data["is_live"]:
                     continue
                 elif yt_data is None or yt_data["duration"] > 3620:
                     continue
                 try:
                     self.get_player(
                         event.guild.id).append(youtubedl_object)
                 except CommandError as e:
                     self.cool_down["playlist"][event.guild.id] = False
                     raise e
                 videos_added += 1
             message.edit(
                 "Successfully added {} videos to queue from playlist and dropped {} videos."
                 .format(
                     videos_added,
                     len(many_object) - videos_added,
                 ), )
             self.cool_down["playlist"][event.guild.id] = False
         else:
             api_loop(
                 event.channel.send_message,
                 "Still adding previous playlist, please wait.",
             )
     else:
         cool = round(
             Decimal(
                 1 -
                 (time() - self.cool_down["general"][event.author.id]), ), )
         api_loop(
             event.channel.send_message,
             "Cool down: {} seconds left.".format(cool),
         )
예제 #3
0
 def on_play(self, event, url):
     item = YoutubeDLInput(url).pipe(BufferedOpusEncoderPlayable)
     self.get_player(event.guild.id).queue.append(item)
예제 #4
0
 def on_play(self, event, type="yt", content=None):
     """
     Voice Make me play the audio stream from youtube or soundcloud in a voice chat.
     With the optional client argument being required when trying to search a client rather than inputting a link.
     If the first argument is in the list:
     "yt" or "youtube", "sc" or "soundcloud",
     then 2nd argument will be searched for on the relevant site before being piped into the player queue.
     If a url fitting either the youtube or soundcloud formats.
     is passed as the first argument then it will be piped into the player queue.
     Otherwise, this will search youtube and then pipe the result into the player queue.
     """
     urls = {
         "https://www.youtube.com/watch?v=": "yt",
         "https://youtube.com/watch?v=": "yt",
         "https://youtu.be": "yt",
         "https://soundcloud.com": "sc",
     }  # /watch?v= /watch?v=
     search_prefixs = {
         "youtube": "ytsearch:{}",
         "yt": "ytsearch:{}",
         "soundcloud": "scsearch:{}",
         "sc": "scsearch:{}",
     }
     self.pre_check(event)
     if event.guild.id not in self.cool_down:
         self.cool_down[event.guild.id] = {}
     if (event.author.id not in self.cool_down["general"]
             or time() - self.cool_down["general"][event.author.id] >= 1):
         if (event.guild.id not in self.cool_down["playlist"]
                 or not self.cool_down["playlist"][event.guild.id]):
             self.cool_down["general"][event.author.id] = time()
             if event.guild.get_member(event.author).get_voice_state():
                 self.on_join(event)
             self.same_channel_check(event)
             if type not in search_prefixs.keys():
                 if type == "override":
                     if event.author.id not in self.owners:
                         return api_loop(
                             event.channel.send_message,
                             "You don't own me",
                         )
                     video_url = content
                     url_found = True
                     pass
                 elif content is not None:
                     content = "{} {}".format(type, content)
                     type = "yt"
                 else:
                     content = type
                     type = "yt"
             elif type in search_prefixs.keys() and content is None:
                 return api_loop(
                     event.channel.send_message,
                     "Search (content) argument missing.",
                 )
             if "url_found" not in locals():
                 url_found = False
             for url, index in urls.items():
                 if url in content:
                     url_found = True
                     video_url = content
                     type = index
             if not url_found:
                 if type in search_prefixs:
                     video_url = search_prefixs[type].format(content)
                 else:
                     video_url = search_prefixs["yt"].format(content)
             youtubedl_object = YoutubeDLInput(video_url, command="ffmpeg")
             try:
                 yt_data = self.get_ytdl_values(youtubedl_object.info)
             except DownloadError as e:
                 return api_loop(
                     event.channel.send_message,
                     "Video not avaliable: {}".format(e),
                 )
             if yt_data["is_live"]:
                 return api_loop(
                     event.channel.send_message,
                     "Livestreams aren't supported",
                 )
             elif yt_data["duration"] > 3620:
                 return api_loop(
                     event.channel.send_message,
                     "The maximum supported length is 1 hour.",
                 )
             self.get_player(event.guild.id).append(youtubedl_object)
             api_loop(
                 event.channel.send_message,
                 "Added ``{}`` by ``{}`` using ``{}``.".format(
                     yt_data["title"],
                     yt_data["uploader"],
                     yt_data["source"],
                 ),
             )
         else:
             api_loop(
                 event.channel.send_message,
                 "Currently adding playlist, please wait.",
             )
     else:
         cool = round(
             Decimal(
                 1 -
                 (time() - self.cool_down["general"][event.author.id]), ), )
         api_loop(
             event.channel.send_message,
             "Cool down: {} seconds left.".format(cool),
         )