Commits

Sergio Berlotto committed 823772c

Ajustes no Snippet e envio de dimensoes dos videos

  • Participants
  • Parent commits a7807e6

Comments (0)

Files changed (6)

File templates/fileitem.html

     {% if file.poster %}
     <a href="" id="icon-poster" filename="{{file.filename}}"></a>
     {% endif %}
-    <a href="/v/{{file.filename}}">{{file.filename}}</a><br/>
+    <a href="http://{{url}}/v/{{file.filename}}">{{file.filename}}</a><br/>
     <span id="filesize">Tamanho: {{file.size}}</span><br/>
     <span id="filesize">Data: {{file.date}}</span>
 </div>

File templates/index.html

             document.getElementById('progressNumber').innerHTML = '';
             var progressBar = document.getElementById('progressBar');
             progressBar.style.display = 'block';
-            progressBar.style.width = '0px';        
+            progressBar.style.width = '0px';
             
             /* If you want to upload only a file along with arbitary data that
                is not in the form, use this */
             if( document.getElementById('poster').files.length > 0 ){
                 fd.append("poster", document.getElementById('poster').files[0]);
             }
+            fd.append("size", document.getElementById('t_w').value + 'x' +
+                      document.getElementById('t_h').value);
     
             /* If you want to simply post the entire form, use this */
             //var fd = document.getElementById('form1').getFormData();
                             width: 900,
                             height: 300
                         });
-                        $("pre.htmlCode").snippet("html",{style:"dull",transparent:true,showNum:true});
+                        $("pre.htmlCode").snippet("html",{style:"dull",transparent:true,showNum:false});
                     });
                     return false;
                 });
                 <input type="file" id="poster" name="poster" value="" />
               </div>
               <div class="row">
+                <label for="poster">Tamanho (W x H):</label><br />
+                <input type="text" id="t_w" name="t_w" value="" size="3" />&nbsp;X&nbsp;
+                <input type="text" id="t_h" name="t_h" value="" size="3" />
+              </div>
+              <div class="row">
                 <input type="button" onclick="uploadFile()" value="Upload" />
               </div>
               <div id="progressBar" class="floatLeft"></div>

File templates/play.html

 <html lang="pt-br">
     <head>
-        <link href="/static/video-js/video-js.css" rel="stylesheet">
-        <script src="/static/video-js/video.js"></script>
-        <script>
-          _V_.options.flash.swf = "/static/video-js/video-js.swf"
-        </script>
+        <link href="http://vjs.zencdn.net/c/video-js.css" rel="stylesheet">
+        <script src="http://vjs.zencdn.net/c/video.js"></script>
     </head>
     <body>
         
         <h1>V&iacute;deo: <em>{{filename}}</em></h1>
         
-        <video id="my_video_1" class="video-js vjs-default-skin" controls
-            preload="auto" width="640" height="264" 
+        <video id="{{filename}}" class="video-js vjs-default-skin" controls
+            preload="auto" width="{{w}}" height="{{h}}"
+            {% if poster %}
+            poster="http://{{url}}/poster/{{filename}}"
+            {% endif %}
             data-setup="{}">
-            <source src="http://localhost:8000/v/{{filename}}" type='video/mp4'>
+            <source src="http://{{url}}/v/{{filename}}" type='video/mp4'>
         </video>
         
     </body>

File templates/poster.html

-<img src='/poster/{{filename}}'></img>
+<img src='http://{{url}}/poster/{{filename}}'></img>

File templates/snippet.html

 <pre id="s-code" class="htmlCode">
-    &lt;video id="_video_{{filename}}" class="video-js vjs-default-skin" controls
-        preload="auto" width="640" height="264" 
-        data-setup="{}"&gt;
-        &lt;source src="http://localhost:8000/v/{{filename}}" type='video/mp4'&gt;
-    &lt;/video&gt;
+&lt;IFRAME src="http://{{url}}/play/{{filename}}" width="{{w}}" height="{{h}}"
+scrolling="no" frameborder="0"&gt;
+[Your browser does not support frames or is currently configured not to display frames.
+Please use an up-to-date browser that is capable of displaying frames.]
+&lt;/IFRAME&gt;
 </pre>
 UPLOADED_FILES_DENY = ''
 APP_PORT = 8000
 APP_HOST = "0.0.0.0"
+APP_URL = 'localhost:8000'
 #---------------------------------------------------------------------
 
 try:
 
 app = Flask(__name__)
 app.config['UPLOAD_FOLDER'] = UPLOADED_FILES_DEST
+app.config['URL'] = APP_URL
 
 UPLOADED_FILES_ALLOW = ('ogg', 'ogv', 'webm', 'mp4')
 videos = UploadSet('videos', UPLOADED_FILES_ALLOW)
 
 def allowed_file(filename):
     '''
-    Verify the allowed file extensions
+    Verifica as extensoes permitidas para os videos.
     '''
     print "Verifiing %s " % filename
     return '.' in filename and filename.rsplit('.', 1)[1] in UPLOADED_FILES_ALLOW
 
+
+def getSize(size):
+    '''
+    Retorna o tamanho de um arquivo, em formato humano.
+    '''
+    if (size > 1024 * 1024):
+        bytesTransfered = str(round(size * 100 / (1024 * 1024)) / 100) + 'MB'
+    elif(size > 1024):
+        bytesTransfered = str(round(size * 100 / 1024) / 100) + 'KB'
+    else:
+        bytesTransfered = str(round(size * 100) / 100) + 'Bytes'
+    return bytesTransfered
+
+
+def has_poster(filename):
+    '''
+    Verifica se o video tem imagem de poster.
+    '''
+    f = re.compile('^poster_%s' % filename)
+    for dirname, dirnames, filenames in os.walk(UPLOADED_FILES_DEST):
+        for filename in filenames:
+            if f.match(filename):
+                return True
+    return False
+
+
+def getDimension(filename):
+    '''
+    Le o arquivo de configuracao do video e retorna os valores para WIDTH e HEIGHT
+    '''
+    f = open(os.path.join(app.config['UPLOAD_FOLDER'], "%s.txt" % filename[:-4]))
+    linha = f.readline()
+    width, height = [int(x) for x in linha.split('=')[1].split("x")]
+    return width, height
 #---------------------------------------------------------------------
 
 
 def upload():
     #print "Uploading..."
     if request.method == 'POST':
-        print "Tem", len(request.files), "arquivos!"
+        print "Tem", len(request.files), "arquivos!", request.form['size']
         if len(request.files) <= 0:
             return "Voc&ecirc; n&atilde;o enviou nenhum v&iacute;deo."
         try:
                 #print dir(f)
                 filename = secure_filename(f.filename)
                 f.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
-                #print 'filename=', filename
+                #Grava as informacoes adicionais em um arquivo texto
+                file_infos = open("%s.txt" % os.path.join(app.config['UPLOAD_FOLDER'], filename)[:-4], 'w')
+                file_infos.write("SIZE=%s" % request.form['size'])
+                file_infos.close()
                 #Trata o poster
-                if len(request.files) > 1 :
+                if len(request.files) > 1:
                     print "Saving poster"
                     poster_file = request.files['poster']
                     print poster_file.filename
                     pFileName = "poster_%s_%s" % (secure_filename(filename), secure_filename(poster_file.filename))
                     poster_file.save(os.path.join(app.config['UPLOAD_FOLDER'], pFileName))
-                    
                 return "Seu arquivo <i>%s</i> foi recebido com sucesso!" % filename
             else:
                 return "Exten&ccedil;&atilde;o de arquivo n&atilde;o permitida!"
         return render_template('index.html')
 
 
-def getSize(size):
-    if (size > 1024 * 1024):
-        bytesTransfered = str(round(size * 100 / (1024 * 1024)) / 100) + 'MB'
-    elif(size > 1024):
-        bytesTransfered = str(round(size * 100 / 1024) / 100) + 'KB'
-    else:
-        bytesTransfered = str(round(size * 100) / 100) + 'Bytes'
-    return bytesTransfered
-
-
 @app.route('/lista-videos')
 def lista():
     arquivos = []
                 st = os.stat(os.path.join(app.config['UPLOAD_FOLDER'], filename))
                 arquivos.append({'filename': filename, 'size': getSize(st[ST_SIZE]),
                                  'date': time.asctime(time.localtime(st[ST_MTIME])),
-                                 'poster': has_poster(filename) })
-    return render_template('fileitem.html', files=arquivos)
+                                 'poster': has_poster(filename)})
+    return render_template('fileitem.html', files=arquivos, url=app.config['URL'])
 
 
 @app.route('/v/<filename>')
     return send_from_directory(app.config['UPLOAD_FOLDER'], filename)
 
 
-def has_poster(filename):
-    f = re.compile('^poster_%s' % filename)
-    for dirname, dirnames, filenames in os.walk(UPLOADED_FILES_DEST):
-        for filename in filenames:
-            if f.match(filename):
-                return True
-    return False
-
-
 @app.route('/poster/<filename>')
 def show_p(filename):
     f = re.compile('^poster_%s' % filename)
 
 @app.route('/poster/view/<filename>')
 def view_p(filename):
-    return render_template('poster.html', filename=filename )
+    return render_template('poster.html', filename=filename, url=app.config['URL'])
 
 
 @app.route('/play/<filename>')
 def player(filename):
-    return render_template('play.html', filename=filename)
+    w, h = getDimension(filename)
+    return render_template('play.html', filename=filename, w=w, h=h, poster=has_poster(filename), url=app.config['URL'])
 
 
 @app.route('/snippet/<filename>')
 def snippet(filename):
-    response = make_response(render_template('snippet.html', filename=filename))
+    w, h = getDimension(filename)
+    response = make_response(render_template('snippet.html', filename=filename, w=w, h=h, url=app.config['URL']))
     response.headers["Content-type"] = "text/plain"
     return response
     #return render_template('snippet.html', filename=filename)