def get_youtube_data(keyword): '''Make a request to the Web API using the baseurl and params Parameters ---------- keyword: string A keyword to search on YouTube Returns ------- list the data returned from making the request in the form of a list ''' cache_list = [] youtube = build('youtube', 'v3', developerKey=API_YOUTUBE_KEY) output = youtube.search().list(part='snippet', q=keyword, order='viewCount', type='video', maxResults=10).execute() for result in output['items']: video = Video(result) video.get_statistics() cache_list.append(video.to_json()) return cache_list
def process_resolution(self): resolution = self.args.resolution for n in self.videos: if self.PlayList: print(f'Downloading: {n}') streams = Video(n).streams name = streams.ffresolution(resolution).download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded")
def process_itag(self): itag = self.args.itag for n in self.videos: if self.PlayList: print(f'Downloading: {n}') name = Video(n).streams.get_itag(itag).download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded")
def process_video(self): quality = self.parse_quality(self.args.video) for n in self.videos: if self.PlayList: print(f'Downloading: {n}') if quality == 0: name = Video(n).streams.get_both.high().download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded") elif quality == 1: name = Video(n).streams.get_both.mid().download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded") else: name = Video(n).streams.get_both.low().download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded")
def process_ffmpeg(self): quality = self.parse_quality(self.args.ffmpeg) for n in self.videos: if self.PlayList: print(f'Downloading: {n}') if quality == 0: name = Video(n).streams.ffhigh.download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded") elif quality == 1: name = Video(n).streams.ffmid.download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded") else: name = Video(n).streams.fflow.download(dire=self.output, status=True, connection=self.conn) if name: print(f"{name} Downloaded")
class EventHandler(): """Class to work with events ganerated by user""" def __init__(self, master): self.master = master self.video = Video() def format_selector_handler(self, url): self.video.url = url return self.video.enable_formats() def folder_select_handler(self, path): """Valid the selected destiny path Args: path: str Returns: path: str """ if path != '' and path != (): self.video.path = path return self.video.path def download_button_event_handler(self, url=None, format=None): """Get the typed URL selected format when the user click in download Args: url: str format: str (optional) """ format = format if not None else '' url = url if not None else '' self.video.url = url self.output_format = format self.video.download()
def __init__(self, master): self.master = master self.video = Video()
def extract(yid): from youtube import Video return Video(yid).get_music_data()
def print_streams(self): if self.args.streams: for n in self.videos: print(f'Video url: {n}') for m in Video(n).streams: print(m)
def aggregate(): if request.method == 'GET': stats = { 'list_queries': [], } result = requests.get(app.config['REST_URL'] + session['profil']['id'] + '/queries/') result = result.json() for doc in result: # add count # and for db compatibilty need to if 'count_videos' in doc: doc['countVideos'] = doc['count_videos'] else: doc['countVideos'] = 'NA' stats['list_queries'].append(doc) if request.method == 'POST': if request.form and request.form.get('optionsRadios'): user_id = session['profil']['id'] query_id = request.form.get('optionsRadios') api_key = session['api_key'] options_api = request.form.getlist('api_part') part = ', '.join(request.form.getlist('part')) param = {'part': part, 'api_key': api_key} if 'captions' in options_api: def send_request(): requests.post("http://restapp:" + app.config['REST_PORT'] + "/" + user_id + "/query/" + query_id + "/add_captions", json=param) Thread(target=send_request).start() if 'comments' in options_api: def send_request(): requests.post("http://restapp:" + app.config['REST_PORT'] + "/" + user_id + "/query/" + query_id + "/add_comments", json=param) Thread(target=send_request).start() if 'related' in options_api: def send_request(): requests.post("http://restapp:" + app.config['REST_PORT'] + "/" + user_id + "/query/" + query_id + "/add_related", json=param) Thread(target=send_request).start() if 'statistics' in options_api: # r = requests.post("http://restapp:5053/" + user_id + "/query/" + query_id + "/add_statistics", json=param) current_query = Video(mongo_curs, api_key=api_key) current_query.add_stats_for_each_entry(query_id) return render_template('methods/download_process.html') return render_template('aggregate.html', stats=stats)
#!/usr/bin/python3 import sys sys.path.insert(0,'..') import youtube as youtube from youtube import Search, Video streams = Video("https://www.youtube.com/watch?v=B6_iQvaIjXw").streams for n in streams: print(n) print(n.url) print("\n\n") print(streams.ffresolution(720).av) # y = youtube.Video("https://www.youtube.com/watch?v=5sFDOiGyAG8") # print(y) if __name__ == '__main__': print(youtube.__version__)