/
foldervideo.py
executable file
·227 lines (191 loc) · 5.62 KB
/
foldervideo.py
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# Autor: @dodilei
# DATA: 10 de Junho de 2012
# Folder-Video lê arquivos de video em sua pasta e gera uma interface em html5 para acessá-lo via browser.
import os
import sys
import webbrowser
pasta_origem = os.listdir("../")
pasta_origem.sort()
arquivo_destino = "index.html"
formatos_aceitos = ["mp4","ogv","webm"]
cmd = os.getcwd()
folder = cmd.split('/')
n = len(folder)
pasta_atual = folder[n-1]
local_storage = pasta_atual.replace(' ', '')
jquery = "jquery.min.js"
videojs = "video.min.js"
videojscss = "video-js.min.css"
quantidade = 0
lista_videos = []
for arquivos in pasta_origem:
try:
ehvideo = arquivos.rsplit('.', 1)[1] in formatos_aceitos
if ehvideo:
quantidade += 1
lista_videos.append(arquivos)
print "escrevendo o arquivo %s " % arquivos
else:
print "o arquivo %s nao eh video" % arquivos
except:
print "*** erro ao escrever"
print "--- %d arquivos tratados" % quantidade
quantidade += 1
escreve = open(arquivo_destino, 'w')
html="""
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Folder-Video</title>
"""
escreve.write(html)
bibliotecas='<script src="%s"></script>\n<script src="%s">\n</script><link href="%s" rel="stylesheet">\n' % (jquery,videojs,videojscss)
escreve.write(bibliotecas)
html="""
<style type="text/css" media="screen">
div#lista_videos {
padding: 15px;
border: 1px solid black;
-moz-column-count: 8;
-webkit-column-count: 8;
-moz-column-width: 40px;
-webkit-column-width: 40px;
-moz-column-gap: 40px;
-webkit-column-gap: 40px;
}
#video {
margin: auto;
box-shadow: 0 0 30px #000;
max-width: 100%;
max-height: 100%;
}
/* estiliza os botoes */
button:active {
position: relative;
top: 2px;
}
button.play {
}
button.pause {
}
</style>
</head>
<body>
<video id="video" class="video-js vjs-default-skin"
controls preload="auto" width="640" height="360"
data-setup="{}">
"""
escreve.write(html)
formatovideo = lista_videos[0].rsplit('.', 1)[1]
escreve.write('<source src="../%s" type="video/%s"/>' % (lista_videos[0],formatovideo))
html="""
</video>
<hgroup>
<h1>Marque seus videos e saiba aonde parou!</h1>
<h3></h3>
</hgroup>
<div id="lista_videos">
"""
escreve.write(html)
for x in range(1,quantidade):
#print x+'\n'
escreve.write('<p><input type="checkbox" value="%s" name="checks"> <span>%s</span> <button class="play" value="%s">></button><button class="pause">II</button></p>\n' % (x,x,x))
html="""
</div>
<script type="text/javascript">
// Coloca no localStorage o que foi marcado no checkbox
var checks = [];
if (localStorage['%s'] == null) {
localStorage.clear();
localStorage['%s']=JSON.stringify(checks);
} else {
//localStorage['%s']=JSON.stringify(checks);
checks = JSON.parse(localStorage['%s']);
}
$('input:checkbox[name=checks]').each(function () {
//init the checkbox
$(this).prop("checked", checks[this.value]?true:false);
$(this).change(function () {
$('input:checkbox[name=checks]').each(function () {
checks[this.value] = this.checked;
});
localStorage['%s']=JSON.stringify(checks);
});
});
// Adicionq lista de videos contidos na pasta em questao
""" % (local_storage.lower(),local_storage.lower(),local_storage.lower(),local_storage.lower(),local_storage.lower(),)
escreve.write(html)
escreve.write('var videoList = %s;' % lista_videos)
html="""
allVideos = JSON.parse(localStorage['%s'])
allVideos.shift()
var marcados = []
for(var i=0;i<allVideos.length;i++){
if(allVideos[i]==true)
marcados.push(i)
}
if(marcados.length >0) {
console.log("foi marcado")
console.log(marcados.length)
ultimoMarcado = marcados.length-1
onload = function () {
document.getElementsByTagName('video')[0].src = "../" + videoList[marcados[ultimoMarcado]];
}
}
function searchVideo(video) {
var buttonValueInt = parseInt(video),
videoNumber = buttonValueInt -1;
document.getElementsByTagName('video')[0].src = "../" + videoList[videoNumber];
document.getElementsByTagName('h3')[0].innerHTML = "Você está assistindo o VÍDEO " + buttonValueInt + ": " + videoList[videoNumber];
}
var videoAteFinal = function(){
var myPlayer = this;
foiateofim = JSON.parse(localStorage['videoateofim']);
$('input:checkbox[value='+foiateofim+']').attr('checked', true);
$('input:checkbox[name=checks]').each(function () {
checks[this.value] = this.checked;
});
localStorage['%s']=JSON.stringify(checks);
};
// PLAY e PAUSE do video
$(".play").click(function() {
// chama a lista de videos dinamicamente
searchVideo(this.value);
var numeroVideo = [];
numeroVideo = this.value;
localStorage['videoateofim']=JSON.stringify(numeroVideo);
_V_("video").ready(function(){
var myPlayer = this;
myPlayer.play();
myPlayer.addEvent("ended", videoAteFinal);
});
});
$(".pause").click(function() {
_V_("video").ready(function(){
var myPlayer = this;
myPlayer.pause();
});
});
</script>
</body>
</html>
""" % (local_storage.lower(), local_storage.lower())
escreve.write(html)
escreve.close()
def openurl(url):
try:
webbrowser.open(url)
except ImportError: # pre-webbrowser.py compatibility
if sys.platform == 'win32':
os.system('start "%s"' % url)
elif sys.platform == 'mac':
try: import ic
except ImportError: pass
else: ic.launchurl(url)
else:
rc = os.system('google-chrome -remote "openURL(%s)" &' % url)
if rc: os.system('google-chrome "%s" &' % url)
openurl(arquivo_destino)