You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.1 KiB

#!/usr/bin/ruby
filename = "links.txt"
template = "#EP#_#TITLE##EXT#"
if ARGV[0].nil? or ARGV[0].empty? then
puts "Please enter iprima series URL"
exit 1
end
url = ARGV[0]
data = `curl #{url} 2> /dev/null | grep hover-preview`.split("\n").reverse
links = []
fd = File.open(filename, "w+")
data.each {
|line|
if line =~ /.*href="(\/\/.*?)".*/ then
links.push "http:#{$1}"
fd.puts "http:#{$1}"
end
}
fd.puts
fd.close
count = links.size
if count > 0 then
puts "Links found: #{count}"
puts links
if `which youtube-dl`.empty? then
puts "ERROR: youtube-dl not found"
exit 1
end
puts
puts "Trying to download links..."
system("youtube-dl -f best -a #{filename}")
basedir = '.'
files = Dir.glob("*.mp4").sort
files.each {
|name|
if name =~/^(.*) \((\d+)\) - (.*)-p\d+(\.mp4)$/ then
season=$1
ep=$2
title=$3
ext=$4
if ep.to_i < 10 then
ep = "0#{ep}"
end
newname = template.gsub("#EP#", ep).gsub("#TITLE#", title).gsub("#SEASON#", season).gsub("#EXT#", ext)
puts "Got: #{name}"
puts "Renaming to: #{newname}"
File.rename(name, newname)
end
}
else
puts "No links found..."
end