Skip to content

Commit

Permalink
1st commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dopplerreflect committed Jan 6, 2012
0 parents commit c0cc4f3
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 0 deletions.
Empty file added README.md
Empty file.
62 changes: 62 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
 var couchapp = require('couchapp')
, path = require('path')
;

ddoc =
{ _id:'_design/by'
, rewrites :
[ {from:"/", to:'index.html'}
, {from:"/api", to:'../../'}
, {from:"/api/*", to:'../../*'}
, {from:"/*", to:'*'}
]
, views : {}
, lists : {}
, shows : {}
}
;

ddoc.views.category = {map: function(doc) {emit(doc.category, null);},reduce:'_count'}
ddoc.views.commentCount = {map: function(doc) {emit(doc.commentCount, null);}}
ddoc.views.duration = {map: function(doc) {emit(doc.duration, null);}}
ddoc.views.favoriteCount = {map: function(doc) {emit(doc.favoriteCount, null);}}
ddoc.views.likeCount = {map: function(doc) {emit(doc.likeCount, null);}}
ddoc.views.rating = {map: function(doc) {emit(doc.rating, null);}}
ddoc.views.ratingCount = {map: function(doc) {emit(doc.ratingCount, null);}}
ddoc.views.title = {map: function(doc) {emit(doc.title, null);}}
ddoc.views.updated = {map: function(doc) {emit(doc.updated, null);}}
ddoc.views.uploaded = {map: function(doc) {emit(doc.uploaded, null);}}
ddoc.views.uploader = {map: function(doc) {emit(doc.uploader, null);},reduce:'_count'}
ddoc.views.viewCount = {map: function(doc) {emit(doc.viewCount, null);}}

ddoc.views.tag = {
map: function(doc) {
for(i in doc.tags) {
emit(doc.tags[i], null);
}
},
reduce: '_count'
}

ddoc.lists.html = function(head, req) {
var row, doc;
start({headers:{"Content-type":"text/html"}});
while(row = getRow()) {
doc = row.doc;
send("<div class='entry'>");
send("<h2><a href='"+doc.player.default+"' target='_blank'>"+doc.title+"</a></h2></div>");
send("<p><img class='thumbnail hqDefault' src='"+doc.thumbnail.hqDefault+"'/></p>");
send("<p class='description'>"+doc.description+"</p>");
send("</div>");
}
}

ddoc.validate_doc_update = function (newDoc, oldDoc, userCtx) {
if (newDoc._deleted === true && userCtx.roles.indexOf('_admin') === -1) {
throw "Only admin can delete documents on this database.";
}
}

couchapp.loadAttachments(ddoc, path.join(__dirname, 'attachments'));

module.exports = ddoc;
29 changes: 29 additions & 0 deletions attachments/couchify_youtube_data.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rubygems'
require 'couchrest'
require 'json'

@couch = CouchRest.database('youtube-sxsw')

@feedurl = "https://gdata.youtube.com/feeds/api/videos"

@params = {
'author' => 'sxsw',
'v' => 2,
'alt' => 'jsonc',
'start-index' => 1, # this will iterate upto 1000(- max-results) only. guess it's a youtube public api limitation
'max-results' => 50 # maximum allowed
}

def fetch_results
JSON.parse(RestClient.get(@feedurl, {:params => @params}))
end

while results = fetch_results
puts "fetching #{@params['max-results']} starting at #{@params['start-index']}"
items = results['data']['items']
# some youtube ids start with _, which is a no-no for couch
# lets append 'video-' to the id.
items.collect!{|item| item['_id'] = 'video-'+item['id']; item}
@couch.bulk_save(items)
@params['start-index'] = @params['start-index'].to_i + @params['max-results'].to_i
end
74 changes: 74 additions & 0 deletions attachments/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>index</title>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" charset="utf-8">
google.load("jquery", "1.7.1");
google.load("jqueryui", "1.8.16");
</script>
</head>
<body>
<div id='controls'>
<select id='category' class='control'>
<option value=''></option>
</select>
<select id='limit' class='control'>
<option value'10'>10</option>
<option value'25'>25</option>
<option value'50'>50</option>
<option value'100'>100</option>
<option value'250'>250</option>
<option value'500'>500</option>
</select>
</div>
<div id='output'></div>
</body>
<script type="text/javascript" charset="utf-8">
$(function(){
var design = "http://localhost:5984/youtube-sxsw/_design/by"
var list = design + "/_list/html/category"
var params = {
reduce: false,
include_docs: true,
};
var category = $('#category');

var loadContent = function() {
if(category.val() !== '') {
params['key'] = '"'+category.val()+'"';
}
params['limit'] = $('#limit').val();
$.ajax({
url: list,
data: params,
dataType: 'html',
success: function(response) {
// console.log(response);
$('#output').html(response);
}
});
};

var loadCategories = function() {
$.ajax({
url: design + "/_view/category",
data: {group:true},
dataType: 'json',
success: function(response) {
var key, value;
for(i in response.rows) {
key = response.rows[i].key;
value = response.rows[i].value;
category.append($('<option>').val(key).text(key + ' ('+value+')'))
}
}
})
}
loadCategories();
loadContent();

$('.control').change(function(){
loadContent();
});
})
</script>

0 comments on commit c0cc4f3

Please sign in to comment.