-
Notifications
You must be signed in to change notification settings - Fork 0
/
__init__.py
32 lines (31 loc) · 1.17 KB
/
__init__.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
import random
import os
from pydub import AudioSegment
from pydub.utils import mediainfo
def MangleLibrary(src, dst, audio, splice=None):
if os.path.splitext(audio)[1] != ".mp3":
raise "Prank audio is not an mp3"
prank = AudioSegment.from_mp3(audio)
# Walk src
for root, dirs, files in os.walk(src):
# Loop through files in this dir
for fn in files:
# If file is an mp3
if os.path.splitext(fn)[1] == ".mp3":
# Import song
fullsong = AudioSegment.from_mp3(root+"/"+fn)
# Pick random location between 10s and end of song
start = random.randint(15,60)
print("Spliced {} after {} seconds".format(root+"/"+fn,start))
# Splice in prank song
if splice != None:
r = random.randint(0,len(splice)-1)
final = fullsong[:start*1000] + prank[splice[r][0]:splice[r][1]] + fullsong[start*1000:]
# final = fullsong[:start*1000] + prank + fullsong[start*1000:]
else:
final = fullsong[:start*1000] + prank
# Recreate directory structrue in dst
if not os.path.exists(dst+"/"+root):
os.makedirs(dst+"/"+root)
# Export song with tags
final.export(dst+"/"+root+"/"+fn, format="mp3", tags=mediainfo(root+"/"+fn).get('TAG', {}))