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
117
118
119
120
|
var Admin =
{
videos: {},
viewRoom: function ()
{
var videoKey = ''
var hash = document.location.hash
if (hash.indexOf("#") !== -1)
hash = hash.substr(1)
var partz = hash.split("&")
for (i in partz)
{
var pair = partz[i].split("=")
if (pair[0] === "v")
videoKey = pair[1]
}
d.warn("VIEWING ROOM "+Room.name)
$.post(API.URL.room.view, {'room':Room.name,'session':Auth.session,}).success(Admin.viewCallback).error(Admin.viewError)
},
viewError: function (raw)
{
d.warn(raw)
},
viewCallback: function (raw)
{
var lines = API.parse("/room/view", raw)
if (! lines)
return d.error("UNABLE TO LOAD ROOM")
var ll = lines.shift().split("\t")
if (ll[0] === '0')
return d.error(ll[1])
Lastlog.update(lines.shift())
Admin.storeVideos(lines)
},
storeVideos: function (lines)
{
var rows = []
var lastDate = ""
for (i in lines.reverse())
{
var row = lines[i].split("\t")
if (row[0].indexOf("ROOM") === 0)
{
Room.updateSetting(row[1],row[2])
continue
}
if (row[0].indexOf("VIDEO") === 0)
{
var type = "??"
if (row[5].indexOf("youtube") !== -1)
type = "yt"
else if (row[5].indexOf("vimeo") !== -1)
type = "vm"
else if (row[5].indexOf("soundcloud") !== -1)
type = "sc"
else if (row[5].indexOf("mp3") !== -1)
type = "au"
// 0 VIDEO 1 id 2 date 3 userid 4 username 5 url 6 title
var d = new Date(parseInt(row[2])*1000)
var thisDate = makeClockDate(d)
if (thisDate === lastDate)
thisDate = ""
else
lastDate = thisDate
var li = "<li id='video_"+row[1]+"'>"
li += "<span class='date'>"+thisDate+"</span>"
li += "<span class='time'>"+makeClockTime(d)+"</span>"
var domain = window.location.hostname.split('.').slice(-2).join('.')
li += "<a class='user' href='http://"+row[4]+"."+domain+"/' target='_blank'>"+row[4]+"</a>"
li += "<span class='type'>"+type+"</span>"
li += "<a class='title' href='"+row[5]+"' target='_blank'>"+row[6]+"</a>"
li += "<span class='remove' id='remove_"+row[1]+"'>remove</span>"
li += "</li>"
rows.push(li)
Admin.videos[row[1]] = { id: row[1], title: row[6], username: row[4] }
}
}
$("#videos").css({"display": "inline-block", "vertical-align": "top"})
$("#videos").html(rows.join(""))
},
removeVideoClick: function ()
{
var id = $(this).attr("id")
var idx = id.substr(id.indexOf("_")+1)
var video = Admin.videos[idx]
d.act("+ remove video "+idx)
if (confirm(video.title+"\nposted by "+video.username+"\n\nThis video will be removed from the queue."))
$.post(API.URL.video.remove, {session:Auth.session, video:idx, room:Room.name}).success(Admin.removeVideoSuccess)
},
removeVideoSuccess: function (raw)
{
var lines = API.parse("/video/remove", raw)
if (! lines)
return d.error("UNABLE TO REMOVE VIDEO")
var l = lines.shift().split("\t")
if (l[0] === '0')
{
d.error(l[1])
return
}
d.warn(l[1])
$("#video_"+l[0]).fadeOut(500)
}
}
var months = "Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec".split(" ")
function makeClockDate(d)
{
var date = d.getDate()
var month = months[d.getMonth()]
return date+"-"+month
}
function makeClockTime(d)
{
var h = d.getHours()
var m = d.getMinutes()
if (m < 10)
m = "0" + m
return h+":"+m
}
|