unexist.dev

Changeset 349:ec20f93cf860

Re-added xbmc stuff
author unexist
date Mon, 21 Jan 2013 18:07:47 +0100
parents e63231263da9
children 165d6fc9b0de
files xbmc/xbmc.db xbmc/xbmc.rb
diffstat 2 files changed, 102 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
Binary file xbmc/xbmc.db has changed
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/xbmc/xbmc.rb	Mon Jan 21 18:07:47 2013 +0100
@@ -0,0 +1,102 @@
+#
+# @file xbmc
+# @copyright (c) 2009 Christoph Kappel
+# @version $Id$
+#
+# This program can be distributed under the terms of the GNU GPL.
+# See the file COPYING.
+#
+
+require "rubygems"
+require "sinatra"
+require "newrelic_rpm"
+require "dm-core"
+require "dm-migrations"
+require "json"
+
+# Config
+set :port, 31337
+
+# Constants
+DBFILE = Dir.pwd + "/xbmc.db"
+
+# Setup
+DataMapper.setup(:default, "sqlite3:///" + DBFILE)
+
+# Models
+class Uri
+  include DataMapper::Resource
+
+  property(:id,         Serial)
+  property(:vid,        String)
+  property(:Title,      String)
+  property(:times,      Integer)
+  property(:created_at, DateTime)
+end
+
+DataMapper.auto_migrate! unless File.exist?(DBFILE)
+DataMapper.finalize
+
+get("/") do # {{{
+  content_type :json
+
+  ret = []
+
+  # Separator
+  ret << { videoid: "oHg5SJYRHA0", Title: "--- Top 10 -------------------------------" }
+
+  # Top10
+  Uri.all(order: [ :times.desc ], limit: 10).each do |u|
+    ret << { videoid: u.vid, Title: u.Title }
+  end
+
+  # Separator
+  ret << { videoid: "oHg5SJYRHA0", Title: "--- All ----------------------------------" }
+
+  # All
+  Uri.all(order: [ :created_at.desc ]).each do |u|
+    ret << { videoid: u.vid, Title: u.Title }
+  end
+
+  ret.to_json
+end # }}}
+
+get("/html") do # {{{
+  ret = []
+
+  Uri.all(order: [ :created_at.desc ]).each do |u|
+    ret << '<a target="_blank" href="http://www.youtube.com/watch?v=%s">%s</a>' % [ u.vid, u.Title ]
+  end
+
+<<-HTML
+<html>
+  <head>
+    <title>Links</title>
+  </head>
+  <body>
+#{ret.join("<br/>")}
+  </body>
+</html>
+HTML
+end # }}}
+
+
+post("/") do # {{{
+  vid   = params["videoid"] || nil
+  title = params["Title"]   || nil
+
+  unless uri.nil? or title.nil?
+    begin
+      uri = Uri.first_or_create(
+        { vid: vid },
+        { vid: vid, Title: title }
+      )
+
+      uri.created_at  = Time.now
+      uri.times      += 1
+      uri.save
+    rescue => err
+      p err
+    end
+  end
+end # }}}