Skip to content

Instantly share code, notes, and snippets.

@caiguanhao
Created February 21, 2016 13:43
Show Gist options
  • Save caiguanhao/9104a7f9041846abde63 to your computer and use it in GitHub Desktop.
Save caiguanhao/9104a7f9041846abde63 to your computer and use it in GitHub Desktop.
Make Non-Stop Pop FM mp3 files from YouTube
# This is a Ruby script to split the downloaded YouTube audio track into separate files
#
# 1. Download Non-Stop-Pop-FM.png from http://gta.wikia.com/wiki/File:Non-stop-pop.png
# 2. Download YouTube video "Non-Stop-Pop FM - GTA V Radio (Next-Gen)" using this command:
# youtube-dl -f 140 'https://www.youtube.com/watch?v=LGL50O1iBY0'
# 3. You may also need to increase the volume of original audio track:
# ffmpeg -i Non-Stop-Pop-FM.m4a -af 'volume=17.5dB' Non-Stop-Pop-FM.mp3
# 4. mkdir done
# 5. ruby nspfm.rb > nspfm.sh
# 6. bash nspfm.sh
def to_secs(input)
m = input.match('^((\d+):)?(\d+):(\d+)$')
m[1].to_i * 60 * 60 + m[3].to_i * 60 + m[4].to_i
end
def convert(src)
from = 0
src.lines.each do |line|
m = line.match('^\s+-\s+((\d+:)?\d+:\d+)\s+(.*)$')
next if m.nil?
name = m[3]
to = to_secs(m[1])
if name != "None" then
info = name.match('^\d+\.\s+(.+?)\s+-\s+(.+?)$')
if info.nil?
info = name.match('^\d+\.\s+(.*)$')
i = "-metadata title=\"#{info[1]}\" -metadata artist=\"Unknown\" -metadata album=\"Non-Stop Pop FM\""
else
i = "-metadata title=\"#{info[1]}\" -metadata artist=\"#{info[2]}\" -metadata album=\"Non-Stop Pop FM\""
end
puts "ffmpeg -i Non-Stop-Pop-FM.mp3 -ss #{from + 1} -t #{to - from - 1} -c copy -y tmp.mp3"
puts "ffmpeg -i tmp.mp3 -i Non-Stop-Pop-FM.png -map 0:0 -map 1:0 -c copy -id3v2_version 3 -metadata:s:v title='Album cover' -metadata:s:v comment='Cover (Front)' #{i} \"done/#{name}.mp3\""
end
from = to
end
end
convert(
<<SRC
- 13:20 None
- 16:23 01. Wait - Dr Robert & Kym Mazelle
- 18:03 02. Commercial
- 22:22 03. Smalltown Boy - Bronski Beat
- 25:43 04. Me & U - Cassie
- 26:43 05. Commercial
- 31:43 06. Days Go By - Dirty Vegas
- 32:21 07. News
- 36:06 08. Tennis Court - Lorde
- 39:46 09. Feel Good Inc. - Gorillaz featuring De La Soul
- 43:47 10. New Sensation - INXS
- 47:25 11. Alright - Jamiroquai
- 48:15 12. Commercial
- 52:01 13. Applause - Lady Gaga
- 54:58 14. Living In A Box - Living In A Box
- 58:34 15. Bad Girls - M.I.A
- 1:02:00 16. Midnight City - M83
- 1:06:06 17. Something Got Me Started (Steve "Silk" Hurley mix) - Simply Red
- 1:09:55 18. Tape Loop (Shortcheeba mix) - Morcheeba
- 1:13:32 19. Promises, Promises - Naked Eyes
- 1:17:02 20. Cooler Than Me - Mike Posner
- 1:17:49 21. News
- 1:21:34 22. The Time Is Now - Moloko
- 1:22:52 23. News & Commercial
- 1:26:34 None
- 1:29:53 24. Moves Like Jagger - Maroon 5 featuring Christina Aguilera
- 1:30:46 25. Commercial
- 1:34:34 26. Send Me an Angel - Real Life
- 1:38:50 27. Kids - Robbie Williams & Kylie Minogue
- 1:40:12 28. Commercial
- 1:43:57 29. 6 Underground - Sneaker Pimps
- 1:47:35 30. Let's Go All the Way - Sly Fox
SRC
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment