Commit e3297aa9 authored by Cool Fire's avatar Cool Fire
Browse files

Added youtube-dl intergration

parent a7836f9a
Pipeline #2 skipped
......@@ -3,8 +3,9 @@
# Plugin to retreive information about a youtube video trough the google data API
class Youtube
require 'net/http'
require 'json'
require 'net/http' # HTTP requests
require 'json' # JSON parsing
require 'uri' # URI validation
# This method is called when the plugin is first loaded
def initialize( status, config, output, irc, timer )
......@@ -96,11 +97,43 @@ class Youtube
@irc.message( from, result )
# Download video and transcode
def mp3( nick, user, host, from, msg, arguments, con )
# Check for valid url
if( arguments =~ /\A#{URI::regexp(['http', 'https'])}\z/ )
# Check for youtube url
if( arguments =~ /youtu(be\.com|\.be)/ )
# Send to youtube-dl
@irc.message( from, "Working..." )
cmd = "youtube-dl --output '~/downloads/%(title)s.%(ext)s' --no-call-home --restrict-filenames --no-color --extract-audio --audio-format mp3 #{arguments}"
res = %x(#{cmd})
# Parse output
if( res =~ /\[ffmpeg\] Destination: (.+\.mp3)/ )
file = $1
if( file =~ /([^\/]+\.mp3)$/ )
@irc.message( from, "Available here for 10 minutes:{$1}" )
@timer.action( 600, "%x(rm #{file})" )
@irc.message( from, "Could not get mp3 file." )
@irc.message( from, "No support for non-youtube URLs at this time." )
@irc.message( from, "This does not appear to be a valid URL." )
# Function to send help about this plugin (Can also be called by the help plugin.)
def help( nick, user, host, from, msg, arguments, con )
help = [
"Plugin to retreive data from youtube videos",
" youtube url - Grab data for youtube video."
" youtube url - Grab data for youtube video.",
" youtube mp3 - Grab the youtube video and transcode it to mp3."
# Print out help
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment