def upload(files, token, assume_yes): """Uploads a file(s) to YouTube using the YouTube service API This function uploads a list of videos and/or directories of videos to YouTube. Args: token - location of an oauth2 token files - list of files and directories to upload assume_yes - if True, assume yes to all interaction (default: False) """ # check if token exists if not os.path.exists(token): print("{} does not exist, please specify a valid token file".format(token)) else: # Gather videos specified and vids from folders specified into list videos = gather_videos(files) # Now begin upload process if not videos: print("Nothing to upload") # Prompt for confirmation elif prompt_user(videos, confirmation=assume_yes): youtube_service = YoutubeService() # Authorize with OAuth2 token youtube_service.authorize(token) for video in videos: response_code, response = youtube_service.upload_video(video) handle_response(response_code, response) # Response was no, so do nothing else: print("Exiting...")
def upload(files, token, assume_yes): """Uploads a file(s) to YouTube using the YouTube service API This function uploads a list of videos and/or directories of videos to YouTube. Args: token - location of an oauth2 token files - list of files and directories to upload assume_yes - if True, assume yes to all interaction (default: False) """ # check if token exists if not os.path.exists(token): print("{} does not exist, please specify a valid token file".format( token)) else: # Gather videos specified and vids from folders specified into list videos = gather_videos(files) # Now begin upload process if not videos: print("Nothing to upload") # Prompt for confirmation elif prompt_user(videos, confirmation=assume_yes): youtube_service = YoutubeService() # Authorize with OAuth2 token youtube_service.authorize(token) for video in videos: response_code, response = youtube_service.upload_video(video) handle_response(response_code, response) # Response was no, so do nothing else: print("Exiting...")
def upload(self, files, token, yes): """Uploads a file(s) to YouTube using the YouTube service API This function uploads a list of videos and/or directories of videos to YouTube. Args: token - location of an oauth2 token files - list of files and directories to upload yes - if True, assume yes to all interaction (default: False) """ # check if token exists if not os.path.exists(token): print( "{} does not exist, please specify a valid token file".format( token)) return # gather videos specified and vids from folders specified into list videos = [] for item in files: # crawl subfolders if os.path.isdir(item): for root, dirs, files_ in os.walk(item): for f in files_: filepath = os.path.join(root, f) # check if its a video and make sure its not a duplicate if YoutubeService.valid_video_file( filepath) and filepath not in videos: videos.append(filepath) # if it exists it is a single file, check if its a video, and make sure its not a duplicate elif os.path.exists(item) and YoutubeService.valid_video_file( item) and item not in videos: videos.append(item) # now begin upload process if not videos: print("Nothing to upload") else: youtube_service = YoutubeService() # authorize with OAuth2 token youtube_service.authorize(token) if not yes: print("Found videos:") print("\n".join(videos)) question = "Are you sure you would like to upload these videos? [Y/n] " if yes or raw_input(question).lower() in ('', 'y', 'yes'): for video in videos: self.handle_response(youtube_service.upload_video(video))
def upload(self, files, token, yes): """Uploads a file(s) to YouTube using the YouTube service API This function uploads a list of videos and/or directories of videos to YouTube. Args: token - location of an oauth2 token files - list of files and directories to upload yes - if True, assume yes to all interaction (default: False) """ # check if token exists if not os.path.exists(token): print("{} does not exist, please specify a valid token file".format(token)) return # gather videos specified and vids from folders specified into list videos = [] for item in files: # crawl subfolders if os.path.isdir(item): for root, dirs, files_ in os.walk(item): for f in files_: filepath = os.path.join(root, f) # check if its a video and make sure its not a duplicate if YoutubeService.valid_video_file(filepath) and filepath not in videos: videos.append(filepath) # if it exists it is a single file, check if its a video, and make sure its not a duplicate elif os.path.exists(item) and YoutubeService.valid_video_file(item) and item not in videos: videos.append(item) # now begin upload process if not videos: print("Nothing to upload") else: youtube_service = YoutubeService() # authorize with OAuth2 token youtube_service.authorize(token) if not yes: print("Found videos:") print("\n".join(videos)) question = "Are you sure you would like to upload these videos? [Y/n] " if yes or raw_input(question).lower() in ('', 'y', 'yes'): for video in videos: self.handle_response(youtube_service.upload_video(video))