Skip to content

Instantly share code, notes, and snippets.

@halkeye
Created February 14, 2015 07:10
Show Gist options
  • Save halkeye/e46fc7023979088b04aa to your computer and use it in GitHub Desktop.
Save halkeye/e46fc7023979088b04aa to your computer and use it in GitHub Desktop.
Simple set of scripts to create nfo files from a bunch of youtube-dl files
#!/usr/bin/env ruby
require 'optparse'
require 'youtube_it'
require 'rubygems'
options = {
:debug => false,
:showtitle => "Lets Play - Final Fantasy XIII",
:directory => "/media/Webseries/Lets Play/Final Fantasy XIII",
:episode => 1,
:season => 1
}
OptionParser.new do |opts|
opts.banner = "Usage: download-patv.rb [options]"
opts.on("-d","--debug", "use local files for debugging purposes") do |v|
options[:debug] = true
end
end.parse!
options[:debug] = true if ENV['VIM']
client = YouTubeIt::Client.new
Dir.foreach(options[:directory]).each do |file|
next if file.start_with?('.')
next if file.end_with?('.nfo')
#puts file
ep_info = {}
ep_info[:video_id] = File.basename(file,'.mp4')[-11,11]
begin
video = client.video_by('https://www.youtube.com/watch?v='+ep_info[:video_id])
rescue OpenURI::HTTPError => e
raise "Unable to download [#{file}] - https://www.youtube.com/watch?v=#{ep_info[:video_id]} -- " + e.to_s
end
ep_info[:episode] = options[:episode]
ep_info[:season] = options[:season]
ep_info[:nfofile] = File::join(
#File.dirname(file),
options[:directory],
File.basename(file,'.mp4') + '.nfo'
)
ep_info[:year] = video.published_at.year
ep_info[:uniqueid] = video.unique_id
#ep_info[:plot] = video.description
ep_info[:premiered] = video.published_at
ep_info[:aired] = video.published_at
ep_info[:studio] = "YouTube"
part_file = File.basename(file,'.mp4').gsub('-' + ep_info[:video_id], '')
match = part_file.match('^Final\s*Fantasy\s*XIII\s*[_-]\s*Part\s*(\d+)(\s*[-_]\s*(.*))?$')
raise "unable to process #{part_file}" unless match
ep_info[:title] = match[3]
ep_info[:episode] = match[1]
ep_info[:title] = "??? Un-named ???" unless ep_info[:title]
raise "unable to process #{part_file}" unless ep_info[:title]
ep_info[:nfofile] = '/dev/stdout' if options[:debug]
if !File.exists?(ep_info[:nfofile]) || options[:debug]
File.open(ep_info[:nfofile], 'w') do |f|
f.puts '<?xml version="1.0" encoding="utf-8" standalone="yes" ?>'
f.puts "<tvshow>"
f.puts " <title>#{ep_info[:title]}</title>"
f.puts " <showtitle>#{options[:showtitle]}</showtitle>"
f.puts " <season>#{ep_info[:season]}</season>"
f.puts " <episode>#{ep_info[:episode]}</episode>"
f.puts " <uniqueid>#{ep_info[:uniqueid]}</uniqueid>"
f.puts " <plot><![CDATA[#{ep_info[:plot]}]]></plot>" if ep_info[:plot]
f.puts " <premiered>#{ep_info[:premiered].strftime('%04Y-%02m-%02d')}</premiered>"
f.puts " <aired>#{ep_info[:aired].strftime('%04Y-%02m-%02d')}</aired>"
f.puts " <studio>#{ep_info[:studio]}</studio>"
f.puts " <tvdbid>#{ep_info[:show][:tvdbid]}</tvdbid>" if ep_info[:show] and ep_info[:show][:tvdbid]
f.puts " <year>#{ep_info[:year]}</year>"
f.puts "</tvshow>"
end
end
end
source 'https://rubygems.org'
gem 'youtube_it', '2.4.0'
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.5)
builder (3.2.2)
crack (0.4.1)
safe_yaml (~> 0.9.0)
excon (0.31.0)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
json (1.7.7)
jwt (0.1.11)
multi_json (>= 1.5)
mini_portile (0.5.2)
multi_json (1.8.4)
multi_xml (0.5.5)
multipart-post (2.0.0)
nokogiri (1.6.1)
mini_portile (~> 0.5.0)
oauth (0.4.7)
oauth2 (0.9.3)
faraday (>= 0.8, < 0.10)
jwt (~> 0.1.8)
multi_json (~> 1.3)
multi_xml (~> 0.5)
rack (~> 1.2)
rack (1.5.2)
safe_yaml (0.9.7)
simple_oauth (0.2.0)
webmock (1.17.1)
addressable (>= 2.2.7)
crack (>= 0.3.2)
youtube_it (2.4.0)
builder
excon
faraday (~> 0.8)
json (~> 1.7.7)
nokogiri (~> 1.6.0)
oauth (~> 0.4.4)
oauth2 (~> 0.6)
simple_oauth (>= 0.1.5)
webmock
PLATFORMS
ruby
DEPENDENCIES
youtube_it (= 2.4.0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment