diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..75124d5 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*~ diff --git a/README.md b/README.md index 06163d1..529a03e 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ # iprima-series-dl -Simple ruby script for getting links via curl and downloading them via youtube-dl script from iprima.cz archive \ No newline at end of file +Simple ruby script for getting links via curl and downloading them via youtube-dl script from iprima.cz archive. + +Requirements: + * curl + * youtube-dl diff --git a/iprima-series-dl.rb b/iprima-series-dl.rb new file mode 100755 index 0000000..c4e2564 --- /dev/null +++ b/iprima-series-dl.rb @@ -0,0 +1,64 @@ +#!/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 epizoda`.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