def random(self): while True: id = random.randint(10000, 1000000) url = functions.get_real_url_from_id(id) if not url: continue return self.play_by_id(id)
def play_by_key(self, key): song_list = functions.search_songs(key) if song_list: for song in song_list: url = functions.get_real_url_from_id(song['id']) if not url: continue return self.play_by_id(song['id'], song['name'], song['artist']) return 'Not found'
def play_by_id(self, id, name=None, artist=None): url = functions.get_real_url_from_id(id) if not url: return 'Incorrect id or song has been removed' if not name or not artist: name, artist = functions.get_detail_from_id(id) self.set_player(url) self.player.play() self.current_name = name self.current_artist = artist return f':musical_note: {name}-{artist}'
def add_by_id(self, id, name=None, artist=None): url = functions.get_real_url_from_id(id) if not url: return 'Incorrect id or song has been removed' if not name or not artist: name, artist = functions.get_detail_from_id(id) self.songlist.append({ 'id': id, 'name': name, 'artist': artist, }) if len(self.songlist) == 1: return self.play_by_id(id, name, artist) return f'add success {name}-{artist}'
def add_by_key(self, key): song_list = functions.search_songs(key) if song_list: for song in song_list: url = functions.get_real_url_from_id(song['id']) if not url: continue self.songlist.append({ 'id': song['id'], 'name': song['name'], 'artist': song['artist'], }) if len(self.songlist) == 1: return self.play_by_id(song['id'], song['name'], song['artist']) return f'add success {song["name"]}-{song["artist"]}' return f'Not found for {key}'