Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_dataset(yt_uri, matching, in_stage, out_stage):
# Use vid as the diretory name for download and processing
vids = parse_qs(urlparse(yt_uri).query, keep_blank_values=True).get('v')
vid = None if vids == None else vids[0]
v_dir = os.path.join(data_path, vid)
in_dir = os.path.join(v_dir, in_stage)
out_dir = os.path.join(v_dir, out_stage)
ext_dir = os.path.join(v_dir, out_stage + 'ext')
# Get information on the YouTube content
try:
yt = YouTube(yt_uri)
except:
e = sys.exc_info()[0]
print("Exception: {}".format(e))
sys.exit(1)
# Creating array of wav files
files = []
for file in os.listdir(in_dir):
if file.endswith('.wav'):
files.append(file)
files.sort()
os.makedirs(out_dir, exist_ok=True)
os.makedirs(ext_dir, exist_ok=True)
# Speech client
def getYoutubeUrl(input_url):
if input_url[:32] == "https://www.youtube.com/watch?v=":
yt = YouTube(input_url) # additional sanitization needed
uid = input_url[32:]
elif input_url[:31] == "http://www.youtube.com/watch?v=":
yt = YouTube(input_url) # additional sanitization needed
uid = input_url[31:]
else:
try:
yt = YouTube("https://www.youtube.com/watch?v=%s" % input_url)
except Exception as e:
sys.exit("Error message: %s" % format(e))
videos = yt.get_videos()
for video in videos:
print(video)
yt.set_filename("intro-%s" % input_url)
video = yt.get('mp4', '360p')
return video.url
def retrieve_keyword_audio(vid, keyword):
audio_index = 0
v_url = URL_TEMPLATE.format(vid)
youtube = YouTube(v_url)
if int(youtube.length) > 2700:
# only consider video < 45 mins
return audio_index
caption = youtube.captions.get_by_language_code('en')
if caption:
# retrieve audio from video
youtube.streams.first().download(output_path=TEMP_DIR, filename=vid)
temp_file_name = TEMP_DIR+vid
if not os.path.isfile(temp_file_name + ".mp4"):
return audio_index
time.sleep(1) # need to wait before ffmpeg takes in as input file
cmd = FFMPEG_TEMPLATE.format(temp_file_name).split()
cp.print_progress(i + 1, " / ", args.size, " - ", url)
if url in url_set:
cp.print_warning("video is already processed", url)
continue
url_set.add(url)
if continuing:
if url != args.continue_from:
continue
else:
continuing = False
try:
video = PyTube(util.get_youtube_url(url))
except Exception as exception:
cp.print_error("failed to generate PyTube representation for video ", url)
cp.print_error(exception)
continue
if int(video.length) > args.video_length:
continue
caption = video.captions.get_by_language_code('en')
if not caption:
cp.print_warning("no caption available for video - ", url)
continue
try:
srt_captions = caption.generate_srt_captions().split('\n\n')
except Exception as exception:
cp.print_error("failed to retrieve srt for video - ", url)
def get_yt(link):
try:
# object creation using YouTube which was imported in the beginning
yt = YouTube(link, )
except:
print("YT Error")
return None
return yt
def downloadYtMp4(yURL, dlDir=os.getcwd()):
#find youtube video
yt = YouTube(yURL)
#filter to only mp4 files and take last in list (sorted lowest to highest quality)
hqMp4 = yt.filter('mp4')[-1]
#strip quality from video info.. example video info:
m = re.search("- (\d\d\dp) -", str(hqMp4))
#save quality capturing group
quality = m.group(1)
#get mp4 video with highest quality found
video = yt.get('mp4', quality)
#download and save video to specified dir
video.download(dlDir)
try:
os.mkdir(parent_full_path)
except OSError:
pass
category_full_path = parent_full_path + "/" + video_list[ii]['category']
if not os.path.exists(category_full_path):
try:
os.mkdir(category_full_path)
except OSError:
pass
video_url = video_list[ii]['url']
try:
youtube = YouTube(video_url)
except:
error_list.append(video_list[ii])
error_list_indices.append(ii)
print "ActivityNet V{0}: {1:.2f}% File ".format(version, float(ii) / float(
len(video_list)) * 100) + category_full_path + ' !! YOUTUBE ERROR !!'
continue
filename = youtube.filename
filename = re.sub('[^a-zA-Z0-9]','', filename)
youtube.set_filename(filename)
temp_path = "/home/damien/temp/"
video = youtube.videos[-2]
video_full_path = temp_path + filename + '.' + video.extension
outvideo_path = os.path.join(category_full_path, filename + ".avi")
def initialYouWork(self,url):
video_list = pytube.YouTube(url)
#로딩바 계산
video_list.register_on_progress_callback(self.showProgressDownLoading)
self.youtb = video_list.streams.all()
self.streamCombobox.clear()
for q in self.youtb:
#print('step1',q.itag,q.mime_type,q.abr)
tmp_list, str_list = [], []
tmp_list.append(str(q.mime_type or ''))
tmp_list.append(str(q.res or ''))
tmp_list.append(str(q.fps or ''))
tmp_list.append(str(q.abr or ''))
#print('step_2',tmp_list)
str_list = [x for x in tmp_list if x != '']
#print('step3',str_list)
print('join',','.join(str_list))
def handle_answer(self, message_entity=None):
message = helper.clean_message(message_entity)
if is_youtube_url(message):
yt = YouTube(message)
video = get_default_video(yt)
path = "app/assets/videos/" + yt.filename + ".mp4"
if os.path.exists(path):
os.remove(path)
video.download('app/assets/videos')
mac.send_video(self.instance, self.conversation, path, caption="video")