def recommend_more(): try: pageToken = request.args.get('pageToken', '') playlistId = request.args.get('playlistId', '') topicId = request.args.get('topicId', '') response, page = [], 'ajax/recommended/more' if len(playlistId.strip()) > 0: playlist_tracks = YouTube.getPlaylistInfo(playlistId, 8, pageToken) if playlist_tracks['status'] == True: if playlist_tracks.get('videos') is not None: response.append(playlist_tracks) elif len(topicId.strip()) > 0: options = { 'part': 'snippet', 'maxResults': 8, 'key': 'AIzaSyDkNYRbreB8JHOggvjSznMIuw6TlvkHjGQ', 'regionCode': Repo.getRegion()['countryCode'], 'topicId': topicId, 'pageToken': pageToken } playlist_topics = YouTube.search(options) if playlist_topics['status'] is True: if len(playlist_topics.get('videos', [])) > 0: response.append(playlist_topics) return render('recommended', response=response, page=page) except Exception as e: return render('error', code=500, message=str(e))
def stream(): try: v = request.args.get('v') plist = request.args.get('list') playlist = request.args.get('playlist') if v is not None: video = YouTube.getVideoInfo(v) return render( 'stream', type='video', core=video, json_core=json.dumps(video), relatedToVideoId=v) if video.get('status') == True else render( 'error', code=404, message=video['message']) elif plist is not None: playlist = YouTube.getPlaylistInfo(plist) return render( 'stream', type='playlist', core=playlist, json_core=json.dumps(playlist), relatedToVideoId=playlist['videos'][0]['id']) if playlist.get( 'status', False) == True else render( 'error', code=404, message=playlist['message']) else: return render( 'error', code=900, message= 'Please provide the Video Id for the song to stream, or search any other song.' ) except Exception as e: return render('error', code=500, message=str(e))
def recommended(): try: limit, response, page = int(request.args.get( 'limit', '0')), [], 'ajax/recommended/more' playlists, countryCode, nextPageToken = [ 'PLMC9KNkIncKvYin_USF1qoJQnIyMAfRxl', 'PLNCA1T91UH31_SnlMecke_9wsbc-5mamS', 'PLYVjGTi85afoMw4yMGHLTB99T8ZTTP0ZP' ], Repo.getRegion()['countryCode'], '' options = { 'part': 'id', 'maxResults': 50, 'order': 'relevance', 'key': 'AIzaSyDkNYRbreB8JHOggvjSznMIuw6TlvkHjGQ', 'channelId': 'UCk8vhgJslhfcLcwS5Q2KADw', 'type': 'playlist' } channel_playlists = YouTube.search(options) if channel_playlists.get('items') is not None: for item in channel_playlists.get('items'): playlistId = item['id'].get('playlistId') if playlistId is not None: playlists.append(playlistId) for playlist in playlists: playlist_tracks = YouTube.getPlaylistInfo(playlist, 8) if playlist_tracks['status'] == True: video = playlist_tracks.get('videos') if video is not None: response.append(playlist_tracks) topics = [{ 'topicId': '/m/04rlf', 'title': 'Music' }, { 'topicId': '/m/02lkt', 'title': 'EDM' }, { 'topicId': '/m/06by7', 'title': 'Rock' }] for topic in topics: options_topic = { 'part': 'snippet', 'maxResults': 8, 'key': 'AIzaSyDkNYRbreB8JHOggvjSznMIuw6TlvkHjGQ', 'regionCode': Repo.getRegion()['countryCode'], 'topicId': topic['topicId'] } playlist_topics = YouTube.search(options_topic) if playlist_topics['status'] == True: playlist_topics.update({'title': topic['title']}) response.append(playlist_topics) return render('recommended', response=response, page=page) except Exception as e: return render('error', code=500, message=str(e))