YOUTUBE_SEARCH_URL = "https://gdata.youtube.com/feeds/api/videos" YOUTUBE_URL_PREFIX = "http://youtube.com/watch?v=" function courtesy_s (quantity, noun) { if (quantity > 1) return quantity + " " + noun + "s" return quantity + " " + noun } var Search = { start: 0, limit: 20, sj: function () { Search.start = 0 Search.terms = $("#search-terms").val() Search.sjSearch (Search.terms, Search.start) }, sjSearch: function (terms, start) { var params = { "q": terms, "start": Search.start, "limit": Search.limit, "session": Auth.session, } $.post(API.URL.video.search, params, Search.sjCallback) $("#search-instructions").hide() $("#search-results").html("").hide() $("#search-loading").show() $("#search-results-container").show() }, sjCallback: function (raw) { var lines = API.parse ("/video/search", raw) var items = [] for (var i = 0; i < lines.length; i++) { // 0 id 1 score 2 user 3 usercount 4 title 5 url 6 thumbnail var line = lines[i].split("\t") if (line.length < 7) continue var video = { url: line[5], thumbnail: line[6], title: line[4], user: line[2], quantify: "", } if (parseInt(line[3]) > 1) video['user'] += " + " + courtesy_s (parseInt(line[3])-1, "other") if (parseInt(line[1]) > 0) video['quantify'] = courtesy_s (parseInt(line[1]), "like") var tag = Search.resultTag (video) items.push(tag) } if (items.length === Search.limit) { Search.start += Search.limit $("#search-next-page").show() } else { $("#search-next-page").hide() } $("#search-loading").hide() $("#search-results").html(items.join("")).show() $("#search-instructions").show() $("#curtain").bind("click", Search.close).css({"background-color": "transparent", "z-index": 99}).show() }, youtube: function () { var terms = $("#search-terms").val() var params = { "q": terms, "v": 2, "alt": "jsonc", } $.get(YOUTUBE_SEARCH_URL, params, Search.youtubeCallback, "jsonp") $("#search-results-container").show() $("#search-results").html("").hide() $("#search-loading").show() }, durationToString: function (duration) { return Math.floor(duration / 60) + ":" + (duration % 60) }, viewCountToString: function (viewCount) { if (! viewCount) return '0' var vc = viewCount.toString () var commas = /(\d+)(\d{3})/; while (commas.test(vc)) { vc = vc.replace(commas, '$1' + ',' + '$2'); } return vc }, resultTag: function (video) { var tag = "