Skip to content

Instantly share code, notes, and snippets.

@mgaspari
Forked from stefan-lz/youtube-to-mp3.rb
Created August 23, 2017 18:48
Show Gist options
  • Save mgaspari/bccbf650bf03faa6d5ba3460fa1d8165 to your computer and use it in GitHub Desktop.
Save mgaspari/bccbf650bf03faa6d5ba3460fa1d8165 to your computer and use it in GitHub Desktop.

Revisions

  1. Stefan Leszkiewicz revised this gist Jun 13, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion youtube-to-mp3.rb
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@
    #usage: youtube-to-mp3 <youtube-url>
    #example: youtube-to-mp3 http://www.youtube.com/playlist?list=PL398CE05652474A1E
    #desc: downloads a single youtube vid or a playlist, then converts to mp3.
    # Quality is not that great. Requires youtube-dl and ffmpeg
    # Requires youtube-dl and ffmpeg

    url = ARGV[0]
    system("youtube-dl -citA #{url}")
  2. Stefan Leszkiewicz renamed this gist Jun 13, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. Stefan Leszkiewicz created this gist Jun 13, 2012.
    17 changes: 17 additions & 0 deletions youtube-to-mp3
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    #!/usr/bin/ruby

    #usage: youtube-to-mp3 <youtube-url>
    #example: youtube-to-mp3 http://www.youtube.com/playlist?list=PL398CE05652474A1E
    #desc: downloads a single youtube vid or a playlist, then converts to mp3.
    # Quality is not that great. Requires youtube-dl and ffmpeg

    url = ARGV[0]
    system("youtube-dl -citA #{url}")

    Dir.foreach(".") do |file|
    filename = file[/(^\d{5}.*)[\-].*/,1]
    if filename != nil
    mp3_file = filename + ".mp3"
    system("ffmpeg -i \"#{file}\" -vn -acodec libmp3lame -ar 44100 -ac 2 -ab 128000 \"#{mp3_file}\"")
    end
    end