Browse Source

Add files via upload

MoeClub 5 years ago
parent
commit
a7b7ad9e51
2 changed files with 65 additions and 84 deletions
  1. 34 64
      ffmpeg/Player/Player.html
  2. 31 20
      ffmpeg/Player/Player.py

+ 34 - 64
ffmpeg/Player/Player.html

@@ -1,73 +1,23 @@
 <!DOCTYPE html>
-<html lang="zh">
+<html lang="zh-CN">
 <head>
   <meta charset="UTF-8">
   <title>{{ escape(PageTitle) }}</title>
   <meta name="referrer" content="no-referrer">
   <link rel="stylesheet" type="text/css" href="{{ escape(SubPath) }}{{ static_url("css/video-js.min.css") }}">
   <style type="text/css">
-    * {
-  		margin: 0;
-  		padding: 0;
-  	}
-  	html, body {
-  		height: 100%;
-  		overflow: hidden;
-  	}
-
-  	body {
-  		text-align: center;
-  		background: black;
-  	}
-
-    h1 {
-      padding: 30px;
-      color: #bdbdbd;
-      font-size: 45px;
-      font-weight: normal;
-      box-sizing: border-box;
-    }
-
-    video:focus {
-      outline: none;
-    }
-
-    .wrapper {
-      width: 100%;
-      margin: auto;
-      height: 100%;
-      text-align: center;
-    }
-
-    .video-js {
-      width: 100% !important;
-      height: 100% !important;
-      position: relative !important;
-    }
-
-    .vjs-big-play-button {
-      margin-top: -130px !important;
-    }
-
-    @media (max-width: 1200px) {
-      body{
-        background: #1d1d1d;
-      }
-
-      h1 {
-        padding: 0.75rem;
-        color: #bdbdbd;
-        font-size: 1.1252rem;
-        font-weight: normal;
-        box-sizing: border-box;
-      }
-    }
+    * {margin: 0; padding: 0;}
+  	html, body {height: 100%; overflow: hidden;}
+  	body {text-align: center; background: black;}
+    video:focus {outline: none;}
+    .wrapper {width: 100%; margin: auto; height: 100%; text-align: center;}
+    .video-js {width: 100% !important; height: 100% !important; position: relative !important;}
+    .vjs-big-play-button {margin-top: -130px !important;}
+    @media (max-width: 1200px) {body{background: #1d1d1d;}}
   </style>
 </head>
 <body>
 
-<h1>{{ escape(PageTitle) }}</h1>
-
 <div class="wrapper">
 	<video id=player width=960 height=540 class="video-js vjs-default-skin vjs-big-play-centered" controls>
 	  <source src="data:application/vnd.apple.mpegurl;base64,{{ escape(PageData) }}" type="application/vnd.apple.mpegurl">
@@ -77,6 +27,8 @@
 <script src="{{ escape(SubPath) }}{{ static_url("js/video.min.js") }}"></script>
 <script src="{{ escape(SubPath) }}{{ static_url("js/videojs.hotkeys.min.js") }}"></script>
 <script>
+let url = window.location.href, textTracks = document.getElementById('textTracks'), webvtt = url.substring(url, url.lastIndexOf(".")) + '.vtt'
+
 var player = videojs('player', {
   html5: {
     hls: {
@@ -88,9 +40,8 @@ var player = videojs('player', {
 
 videojs.Hls.xhr.beforeRequest = function(options) {
   if (options.headers) {
-      delete options.headers.Range
+      delete options.headers.Range;
   }
-
   return options;
 }
 
@@ -100,11 +51,30 @@ player.ready(function () {
     volumeStep: 0.1,
     enableModifiersForNumbers: false
   });
+  if (checkExists(vtt)) {
+	  player.addRemoteTextTrack({kind: "captions", label: "subtitles on", mode: "showing", src: webvtt});
+    textSetting = player.textTrackSettings.getValues();
+    textSetting.backgroundOpacity = "0";
+    textSetting.windowOpacity = "0";
+    textSetting.textOpacity = "1";
+    player.textTrackSettings.setValues(textSetting);
+  };
 });
 
-player.on('play', function (e) {
-  document.querySelector('h1').style.display = 'none';
-});
+function checkExists(url) {
+        let http = new XMLHttpRequest()
+        http.open("GET", url, false);
+        http.send();
+        if (http.readyState == 4) {
+            if (http.status == 200){
+                return true
+            }else{
+                return false
+            }
+        }else{
+            return false
+        }
+    }
 </script>
 </body>
 </html>

+ 31 - 20
ffmpeg/Player/Player.py

@@ -43,39 +43,37 @@ class Utils:
             return ""
         if int(time.time()) - second >= cls.treetime:
             cls.treelist = []
-            cls.tree(dirname=dirname)
+            cls.tree(dirname=dirname, FileType="m3u8")
             cls.treetime = int(time.time())
         return "\n".join(cls.treelist)
 
     @classmethod
-    def tree(cls, dirname, padding="    ", Print=False):
-        PRINTITEM1 = padding[:-1] + '+-' + os.path.basename(os.path.abspath(dirname)) + '/'
-        cls.treelist.append(PRINTITEM1)
+    def tree(cls, dirname, padding="    ", Print=False, FileType=None):
+        PRINTITEM = padding[:-1] + '+-' + os.path.basename(os.path.abspath(dirname)) + '/'
+        cls.treelist.append(PRINTITEM)
         if Print:
-            print(PRINTITEM1)
+            print(PRINTITEM)
         padding = padding + ' '
         files = os.listdir(dirname)
         count = 0
         for file in files:
             count += 1
-            PRINTITEM2 = padding + '|'
-            cls.treelist.append(PRINTITEM2)
-            if Print:
-                print(PRINTITEM2)
             path = dirname + os.sep + file
             if os.path.isdir(path):
                 if count == len(files):
-                    cls.tree(path, padding + ' ', Print)
+                    cls.tree(path, padding + ' ', Print, FileType)
                 else:
-                    cls.tree(path, padding + '|', Print)
+                    cls.tree(path, padding + '|', Print, FileType)
             else:
-                PRINTITEM3 = padding + '+-' + file
-                cls.treelist.append(PRINTITEM3)
-                if Print:
-                    print(PRINTITEM3)
+                if FileType is None or str(path).lower().endswith("." + str(FileType).lower()):
+                    PRINTITEM = padding + '+-' + file
+                    cls.treelist.append(PRINTITEM)
+                    if Print:
+                        print(PRINTITEM)
 
 
 class MainHandler(tornado.web.RequestHandler):
+    StringList = [chr(item) for item in range(65, 90 + 1)] + [chr(item) for item in range(48, 57 + 1)] + [chr(item) for item in range(97, 122 + 1)] + ["-", "_", ".", "@"]
     StaticFile = {}
 
     def check_argument(self, key):
@@ -107,7 +105,6 @@ class MainHandler(tornado.web.RequestHandler):
                 self.write(self.WriteString(data))
                 self.finish()
                 return
-            print(Item)
             if str(Item).strip().lstrip("/").startswith("static/"):
                 StaticPath = os.path.join(RootPath, Item)
                 if os.path.exists(StaticPath):
@@ -115,6 +112,8 @@ class MainHandler(tornado.web.RequestHandler):
                         self.set_header("Content-Type", "application/javascript; charset=utf-8")
                     elif str(StaticPath).endswith(".css"):
                         self.set_header("Content-Type", "text/css")
+                    else:
+                        self.set_header("Content-Type", "application/octet-stream")
                     if StaticPath not in self.StaticFile:
                         self.StaticFile[StaticPath] = Utils.load(StaticPath, "rb")
                     self.finish(self.StaticFile[StaticPath])
@@ -123,9 +122,22 @@ class MainHandler(tornado.web.RequestHandler):
                     self.set_status(404)
                     self.finish()
                 return
-            if not str(Item).strip().endswith(".m3u8"):
-                Item = str(Item).strip() + ".m3u8"
-            ItemPath = os.path.join(DataPath, Item)
+            if str(Item).strip().lower().endswith(".vtt"):
+                ItemPath = os.path.join(DataPath, Item)
+                if os.path.exists(ItemPath):
+                    self.set_header("Content-Type", "application/octet-stream")
+                    if ItemPath not in self.StaticFile:
+                        self.StaticFile[ItemPath] = Utils.load(ItemPath, "rb")
+                    self.finish(self.StaticFile[ItemPath])
+                    self.flush()
+                else:
+                    self.set_status(404)
+                    self.finish()
+                return
+            if str(Item).strip().lower().endswith(".m3u8"):
+                ItemPath = os.path.join(DataPath, Item)
+            else:
+                ItemPath = os.path.join(DataPath, Item + ".m3u8")
             if os.path.exists(ItemPath):
                 self.render("Player.html", PageTitle=str(Item).rstrip(".m3u8"), SubPath=str("/%s" % SubPath), PageData=Utils.b64(ItemPath))
             else:
@@ -170,4 +182,3 @@ class Web:
 
 if __name__ == "__main__":
     Web.main()
-