Log each downloaded video in database
This commit is contained in:
parent
86272fd846
commit
068cb4406a
1 changed files with 18 additions and 1 deletions
19
script.rb
19
script.rb
|
@ -3,6 +3,8 @@
|
||||||
require 'rss'
|
require 'rss'
|
||||||
require 'open-uri'
|
require 'open-uri'
|
||||||
require 'youtube-dl'
|
require 'youtube-dl'
|
||||||
|
require 'sequel'
|
||||||
|
require 'date'
|
||||||
|
|
||||||
if ARGV.empty?
|
if ARGV.empty?
|
||||||
puts "Please specify the URL of the feed as a parameter"
|
puts "Please specify the URL of the feed as a parameter"
|
||||||
|
@ -11,9 +13,24 @@ end
|
||||||
|
|
||||||
url=ARGV[0]
|
url=ARGV[0]
|
||||||
|
|
||||||
|
DB = Sequel.connect('sqlite://videos.db')
|
||||||
|
DB.create_table? :videos do
|
||||||
|
primary_key :id
|
||||||
|
String :url
|
||||||
|
String :filename
|
||||||
|
Integer :filesize
|
||||||
|
DateTime :downloaded
|
||||||
|
end
|
||||||
|
|
||||||
|
videos=DB[:videos]
|
||||||
|
|
||||||
open(url) do |rss|
|
open(url) do |rss|
|
||||||
feed=RSS::Parser.parse(rss)
|
feed=RSS::Parser.parse(rss)
|
||||||
feed.items.each do |item|
|
feed.items.each do |item|
|
||||||
YoutubeDL.download "#{item.link}"
|
video=YoutubeDL.download "#{item.link}"
|
||||||
|
videos.insert(:url => "#{item.link}",
|
||||||
|
:filename => "#{video.filename}",
|
||||||
|
:filesize => File.size("#{video.filename}"),
|
||||||
|
:downloaded => DateTime.now)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Reference in a new issue