-
Notifications
You must be signed in to change notification settings - Fork 0
/
audio-extractor.py
67 lines (51 loc) · 2.19 KB
/
audio-extractor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#/usr/bin/env python
# -*- coding: utf-8 -*-
import subprocess
import os
import moviepy.editor as mp
# VIDEO_LINK from github actions
# FINAL_MUSIC_NAME from github actions
video_link = os.environ["VIDEO_LINK"]
final_music_name = os.environ["FINAL_MUSIC_NAME"]
print(video_link)
print(final_music_name)
# p = subprocess.run(["you-get", "--debug","--output-filename", final_music_name, "--no-caption", video_link],
# timeout=10000,
# capture_output=True,
# encoding="utf-8")
# process = subprocess.Popen(
# ["you-get", "--debug","--output-filename", final_music_name, "--no-caption", video_link],
# stdout=subprocess.PIPE,
# stderr=subprocess.PIPE
# )
# process.wait()
# output, error = process.communicate()
# if process.returncode != 0:
# raise Exception("File handling failed %d %s %s" % (process.returncode, output, error))
'''
you-get -O 镰仓殿的13人 --no-caption https://www.bilibili.com/video/BV1KY411g7iA
site: Bilibili
title: 【鎌倉殿の13人 (OP) 】 窥探历史的陈迹 钢琴曲【高音質】
stream:
- format: flv
container: flv
quality: 高清 1080P
size: 32.5 MiB (34072623 bytes)
# download-with: you-get --format=flv [URL]
Downloading 镰仓殿的13人.flv ...
100% ( 32.5/ 32.5MB) ├███████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████┤[1/1] 770 kB/s
Skipping captions or danmaku.
'''
files = os.listdir(os.getcwd())
fileName = ''
for file in files:
print(file)
if(file.startswith(final_music_name)):
fileName = file
break
my_clip = mp.VideoFileClip(filename=fileName)
my_clip.audio.write_audiofile(final_music_name + ".mp3")
my_clip.close()
f = open('song_name.txt','w+')
f.write(final_music_name + '.mp3' )
f.close()