unexist.dev

Changeset 334:94e7f469023c

Updated xbmc script
author unexist
date Tue, 04 Dec 2012 15:28:33 +0100
parents 8ce7a8235034
children 7d45f34a28f9
files xbmc/xbmc.rb
diffstat 1 files changed, 40 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/xbmc/xbmc.rb	Tue Dec 04 15:07:57 2012 +0100
+++ b/xbmc/xbmc.rb	Tue Dec 04 15:28:33 2012 +0100
@@ -9,6 +9,7 @@
 
 require "rubygems"
 require "sinatra"
+require "newrelic_rpm"
 require "dm-core"
 require "dm-migrations"
 require "json"
@@ -26,10 +27,11 @@
 class Uri
   include DataMapper::Resource
 
-  property(:id, Serial)
-  property(:vid, String)
-  property(:Title, String)
-  property(:created_at, DateTime)
+  property(id:         Serial)
+  property(vid:        String)
+  property(Title:      String)
+  property(times:      Integer, default: 0)
+  property(created_at: DateTime)
 end
 
 DataMapper.auto_migrate! unless File.exist?(DBFILE)
@@ -40,6 +42,18 @@
 
   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
@@ -47,6 +61,26 @@
   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
@@ -58,7 +92,8 @@
         { vid: vid, Title: title }
       )
 
-      uri.created_at = Time.now
+      uri.created_at  = Time.now
+      uri.times      += 1
       uri.save
     rescue => err
       p err