Skip to content

Instantly share code, notes, and snippets.

@ayabusa
Last active March 18, 2024 19:43
Show Gist options
  • Save ayabusa/de9760d7df8de2f1203572f4886bf57c to your computer and use it in GitHub Desktop.
Save ayabusa/de9760d7df8de2f1203572f4886bf57c to your computer and use it in GitHub Desktop.
A tool to convert a single file containing multiple song into multiple files
"""
This work is licensed under a Creative Commons Attribution 4.0 International License
To view a copy of this license, visit https://creativecommons.org/licenses/by/4.0/
"""
import os
"""
##### Playlist Sequencer #####
Contributors:
Ayabusa
Le_Zozoien
This script can be used to convert a single audio file containing multiple songs into multiple audio files.
It can be useful to split a youtube playlist.
This is just a script for me so I'm not going to maintain or port it to any other os but it should work.
It was tested on linux mint but should work on any os as long as you have ffmpeg installed and added to your PATH.
Please modify the script and change at least :
- the inputFile
- the variable containing chapter time codes
- the names of your songs
Enjoy :)
"""
# change this to match your song and output folder
inputFile = "my_incredible_song.mp3"
outputFolder = "outputPlaylist"
# the chapter list that you can find in description / comment of the video
chapterTimeList = [
"0:00",
"3:30",
"7:25",
"11:37",
"14:51",
"18:19",
"22:25",
"26:53",
"30:47",
"34:33",
"38:52",
"42:03",
"45:44",
"49:27",
"52:38",
"55:53",
"58:45",
"1:02:35",
"1:06:24",
"1:10:38",
"1:13:51",
"1:16:50",
"1:19:56",
"1:23:45",
"1:27:49",
"1:31:51",
"1:35:19",
"1:39:17",
"1:42:45",
"1:47:13"
]
# the name of the music in the same order as the chapter
chapterNameList = [
"Stereo Hearts - Gym Class Heroes",
"Wild Ones - Flo Rida",
"Rockabye - Clean Bandit",
"HandClap - Fitz and The Tantrums",
"Young, Wild & Free - Snoop Dogg & Wiz Khalifa",
"Titanium - David Guetta",
"A Sky Full Of Stars - Coldplay",
"Locked Out of Heaven - Bruno Mars",
"Whistle - Flo Rida",
"Can't Hold Us - Macklemore & Ryan Lewis",
"GDFR - Flo Rida",
"Primadonna - Marina and The Diamonds",
"Ass Back Home - Gym Class Heroes",
"Take You Dancing - Jason Derulo",
"U - David Guetta",
"Boom Clap - Charli XCX",
"Low - Flo Rida",
"Rather Be - Clean Bandit",
"I Like It Like That - Rete Rodriguez",
"Hey Mama - David Guetta",
"Floating Through Space - Sia & David Guetta",
"Not Your Barbie Girl - Ava Max",
"Young Girls - Bruno Mars",
"I'm Yours - Jason Mraz",
"I Won't Give Up - Jason Mraz",
"Somewhere Only We Know - Lily Allen",
"Infinity - Jaymes Young",
"Sing to You - John Splithoff",
"Yellow - Coldplay",
"Marvin Gaye - Charlie Puth"
]
###### END OF WHAT YOU NEED TO MODIFY #######
# create folder if not already created
if not os.path.isdir(outputFolder):
os.mkdir(outputFolder)
# the main loop
for i in range(len(chapterTimeList)):
# the if/else is to prevent "error: index out of list"
if(i+1<len(chapterTimeList)):
command = f"ffmpeg -i {inputFile} -ss {chapterTimeList[i]} -to {chapterTimeList[i+1]} \"{outputFolder}/{str(i+1).zfill(2)} - {chapterNameList[i]}.mp3\""
else:
command = f"ffmpeg -i {inputFile} -ss {chapterTimeList[i]} \"{outputFolder}/{str(i+1).zfill(2)} - {chapterNameList[i]}.mp3\""
# just for debugging
print("executing :",command)
# executing the command
os.system(command)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment