Browse Source

Add youtube config, and some other stuff too.

deprecated/v1
Brandon Anzaldi 9 months ago
parent
commit
7ddaaaa1f4
2 changed files with 36 additions and 23 deletions
  1. 3
    1
      config/config_sample.yml
  2. 33
    22
      main.rb

+ 3
- 1
config/config_sample.yml View File

@@ -3,4 +3,6 @@
mastodon:
client_key: xxxxxxx
client_secret: xxxxxx
access_token: xxxxxx
access_token: xxxxxx
youtube:
api_key: xxxxxx

+ 33
- 22
main.rb View File

@@ -7,6 +7,7 @@ require 'sqlite3'
require 'time-lord'
require 'json'
require 'mastodon'
require 'yt'
require 'yaml'
# require 'bitly'

@@ -27,6 +28,10 @@ SQL

$config = YAML::load_file('/home/caff/code/sotdbot/config/config.yml')

Yt.configure do |config|
config.api_key = $config['youtube']['api_key']
end

SotdHelp = Class.new do
include Cinch::Plugin

@@ -53,8 +58,8 @@ module SotdParse
if !link.host || !link.port then
return 1
elsif /youtu(?:be)?\.(?:be|com)/i =~ link.host then
@doc = Nokogiri::HTML(open(link.to_s, :allow_redirections => :safe), nil, "UTF-8")
@display = @doc.css("title")[0].content.sub(/\s-\sYouTube$/, '')
ytl = Yt::URL.new link.to_s
@display = ytl.resource.title
elsif /bandcamp\.com/ =~ link.host then
@doc = Nokogiri::HTML(open(link.to_s, :allow_redirections => :safe))
@name = @doc.css(".trackTitle")[0].content.strip
@@ -62,7 +67,7 @@ module SotdParse
@display = "#{@artist} - #{@name}"
elsif /soundcloud\.com/ =~ link.host then
@doc = Nokogiri::HTML(open(link.to_s, :allow_redirections => :safe))
@display = @doc.css("[itemprop='name']")[0].content.sub(/\W+/, ' ').strip
@display = @doc.css("[itemprop='name']")[0].content.gsub(/[\n\t\s]+/, ' ').strip
# Parsing Archive.org is temporarily broken :( Sorry
elsif /archive\.org/ =~ link.host then
return 2
@@ -162,7 +167,8 @@ class SotdStats
include Cinch::Plugin
extend Invisibleify

match "sotdstats"
# match "sotdstats"
match /sotdstats/

def execute(m)
rows = $db.execute <<-SQL
@@ -188,27 +194,32 @@ class SotdGet

match "sotd"
match /sotd ([a-zA-Z0-9]+)/
match /listsotd/

def execute(m, username = "")
if username.to_s.empty? then
rows = $db.execute <<-SQL
SELECT sotd.username, sotd.display, sotd.link, sotd.created_at
FROM sotd sotd
INNER JOIN (
SELECT MAX(created_at) created_at, username
FROM sotd
WHERE created_at > DATETIME('now', '-2 days')
GROUP BY username
) AS s1
ON sotd.username = s1.username
AND sotd.created_at = s1.created_at
ORDER BY sotd.created_at DESC
SQL
rows.each do |row|
time = DateTime.parse(row[3]).to_time
period = TimeLord::Period.new(time, Time.now).to_words
m.reply "#{Invisibleify.invisibleify(row[0])}: #{row[1]} <#{row[2]}> (#{period})"
sleep 0.25
if m.channel? and m.channel.name == "#tildetown" then
m.reply "Check out http://tilde.town/~severak/town_radio.html, or run this command in another channel such as #music, #bots, or #sotd for a list of current SOTDs"
else
rows = $db.execute <<-SQL
SELECT sotd.username, sotd.display, sotd.link, sotd.created_at
FROM sotd sotd
INNER JOIN (
SELECT MAX(created_at) created_at, username
FROM sotd
WHERE created_at > DATETIME('now', '-2 days')
GROUP BY username
) AS s1
ON sotd.username = s1.username
AND sotd.created_at = s1.created_at
ORDER BY sotd.created_at DESC
SQL
rows.each do |row|
time = DateTime.parse(row[3]).to_time
period = TimeLord::Period.new(time, Time.now).to_words
m.reply "#{Invisibleify.invisibleify(row[0])}: #{row[1]} <#{row[2]}> (#{period})"
sleep 0.25
end
end
else
rows = $db.execute <<-SQL

Loading…
Cancel
Save