forked from mdale/html5videowall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharchiveUtil.js
116 lines (94 loc) · 2.8 KB
/
archiveUtil.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
( function( global, $ ) {
// URL param
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results && results[ 1 ] || "camels";
};
var _this = {},
windowParam = $.urlParam( "name" ),
baseUrl = "http://archive.org/",
searchPath = "advancedsearch.php",
detailsPath = "details/",
downloadPath = "download/",
ogvURL = "http://archive.org/download/" + windowParam + "/format=Ogg+video",
jsonP = "&output=json&callback=?";
// Set up reference
global.archiveUtil = _this;
// ********************************
// Searches for a query
_this.search = function( query, callback ) {
var url = baseUrl + searchPath;
// Return the useful data
function _callback( data ) {
callback( data.response.docs );
}
// remove any unsafe query parmas:
query = query.replace(':', '');
// Create object if it's a string
if ( typeof query === "string" ) {
query = {
q: query
};
}
// Archive needs this
query.output = "json";
$.ajax({
url: url,
dataType: "jsonP",
data: query,
success: _callback
});
};
// ********************************
// Gets detailed info for an identifier, id
_this.details = function( id, callback ) {
var url = baseUrl + detailsPath + id;
$.ajax({
url: url,
dataType: "jsonP",
data: {
output: "json"
},
success: callback
});
};
// ********************************
// Makes the download link given a format
_this.downloadFile = function( id, format ) {
var url = baseUrl + downloadPath + id + "/format=";
if ( format === "ogv" ) {
url += "Ogg+video";
console.log( url );
return url;
}
};
// ********************************
// Searches the TV archive given a query
_this.searchTV = function( query, callback ) {
var url = baseUrl + detailsPath + "tv";
// remove any unsafe query parmas:
query = query.replace(':', '');
query = {
q: query,
output: "json"
};
$.ajax({
url: url,
dataType: "jsonP",
data: query,
success: callback
});
};
// ********************************
// Gets files of a particular type and returns an array
_this.getFiles = function( files, type ) {
var result = [];
type = "." + type + "$"; //regex
$.each( files, function( fileURL, fileMetaData ) {
if ( fileURL.search( type ) !== -1 ) {
result.push( fileURL );
}
});
return result;
};
}( window, window.jQuery ) );