Merge remote-tracking branch 'origin/main'
This commit is contained in:
+31
-17
@@ -1,23 +1,37 @@
|
|||||||
from google.colab import files
|
|
||||||
import shutil
|
|
||||||
import os
|
import os
|
||||||
|
import random
|
||||||
|
import shutil
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
from google.colab import files
|
||||||
|
|
||||||
basepath = os.getcwd()
|
basepath = os.getcwd()
|
||||||
uploaded = files.upload() # 上传文件
|
uploaded = files.upload() # 上传文件
|
||||||
for filename in uploaded.keys():
|
for filename in uploaded.keys():
|
||||||
assert(filename.endswith(".txt")), "speaker-videolink info could only be .txt file!"
|
assert (filename.endswith(".txt")), "speaker-videolink info could only be .txt file!"
|
||||||
shutil.move(os.path.join(basepath, filename), os.path.join("./speaker_links.txt"))
|
shutil.move(os.path.join(basepath, filename), os.path.join("./speaker_links.txt"))
|
||||||
|
|
||||||
with open("./speaker_links.txt", 'r', encoding='utf-8') as f:
|
|
||||||
lines = f.readlines()
|
def generate_infos():
|
||||||
speakers = []
|
infos = []
|
||||||
for line in lines:
|
with open("./speaker_links.txt", 'r', encoding='utf-8') as f:
|
||||||
line = line.replace("\n", "").replace(" ", "")
|
lines = f.readlines()
|
||||||
if line == "":
|
for line in lines:
|
||||||
continue
|
line = line.replace("\n", "").replace(" ", "")
|
||||||
speaker, link = line.split("|")
|
if line == "":
|
||||||
if speaker not in speakers:
|
continue
|
||||||
speakers.append(speaker)
|
speaker, link = line.split("|")
|
||||||
# download link
|
filename = speaker + "_" + str(random.randint(0, 1000000))
|
||||||
import random
|
infos.append({"link": link, "filename": filename})
|
||||||
filename = speaker + "_" + str(random.randint(0, 1000000))
|
return infos
|
||||||
|
|
||||||
|
|
||||||
|
def download_video(info):
|
||||||
|
link = info["link"]
|
||||||
|
filename = info["filename"]
|
||||||
os.system(f"youtube-dl -f 0 {link} -o ./video_data/{filename}.mp4")
|
os.system(f"youtube-dl -f 0 {link} -o ./video_data/{filename}.mp4")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
infos = generate_infos()
|
||||||
|
with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
|
||||||
|
executor.map(download_video, infos)
|
||||||
|
|||||||
+22
-5
@@ -1,10 +1,27 @@
|
|||||||
from moviepy.editor import AudioFileClip
|
|
||||||
import os
|
import os
|
||||||
|
from concurrent.futures import ThreadPoolExecutor
|
||||||
|
|
||||||
|
from moviepy.editor import AudioFileClip
|
||||||
|
|
||||||
video_dir = "./video_data/"
|
video_dir = "./video_data/"
|
||||||
audio_dir = "./raw_audio/"
|
audio_dir = "./raw_audio/"
|
||||||
filelist = list(os.walk(video_dir))[0][2]
|
filelist = list(os.walk(video_dir))[0][2]
|
||||||
for file in filelist:
|
|
||||||
if file.endswith(".mp4"):
|
|
||||||
my_audio_clip = AudioFileClip(video_dir + file)
|
|
||||||
my_audio_clip.write_audiofile(audio_dir + file.rstrip(".mp4") + ".wav")
|
|
||||||
|
|
||||||
|
|
||||||
|
def generate_infos():
|
||||||
|
videos = []
|
||||||
|
for file in filelist:
|
||||||
|
if file.endswith(".mp4"):
|
||||||
|
videos.append(file)
|
||||||
|
return videos
|
||||||
|
|
||||||
|
|
||||||
|
def clip_file(file):
|
||||||
|
my_audio_clip = AudioFileClip(video_dir + file)
|
||||||
|
my_audio_clip.write_audiofile(audio_dir + file.rstrip(".mp4") + ".wav")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
infos = generate_infos()
|
||||||
|
with ThreadPoolExecutor(max_workers=os.cpu_count()) as executor:
|
||||||
|
executor.map(clip_file, infos)
|
||||||
|
|||||||
Reference in New Issue
Block a user