minify css
This commit is contained in:
		@@ -43,7 +43,7 @@ else:
 | 
			
		||||
    except Exception as e:
 | 
			
		||||
        print(e)
 | 
			
		||||
    else:
 | 
			
		||||
        with open("/app/chromecast.css", "w") as f:
 | 
			
		||||
        with open("/app/setup/chromecast.css", "w") as f:
 | 
			
		||||
            f.write(resp.text)
 | 
			
		||||
    with open("/app/version/chromecast.txt", "w") as f:
 | 
			
		||||
        f.write(chromecast_version)
 | 
			
		||||
 
 | 
			
		||||
@@ -171,9 +171,7 @@ try:
 | 
			
		||||
    with open("/app/favicon.png", "rb") as f:
 | 
			
		||||
        favicon = f.read()
 | 
			
		||||
    with open("/app/style.css", "r") as f:
 | 
			
		||||
        custom_style_raw = bytes(f.read().strip(), "utf-8")
 | 
			
		||||
        b64 = str(base64.b64encode(custom_style_raw), "ascii")
 | 
			
		||||
        custom_style = f'data:text/css;charset=utf-8;base64,{b64}'
 | 
			
		||||
        custom_style = f.read()
 | 
			
		||||
except Exception as e:
 | 
			
		||||
    logger.info(e)
 | 
			
		||||
 | 
			
		||||
@@ -210,7 +208,6 @@ class MainHandler(tornado.web.RequestHandler):
 | 
			
		||||
            data["videojs_version"] = videojs_version
 | 
			
		||||
            data["chromecast_version"] = chromecast_version
 | 
			
		||||
            data["font_awesome_version"] = font_awesome_version
 | 
			
		||||
            data["custom_style"] = custom_style
 | 
			
		||||
            rendered_html = template_html.generate(data=data, meta=provider_data.meta(), title=provider_data.title())
 | 
			
		||||
            self.write(rendered_html)
 | 
			
		||||
        else:
 | 
			
		||||
@@ -222,18 +219,25 @@ class MainHandler(tornado.web.RequestHandler):
 | 
			
		||||
    async def head(self):
 | 
			
		||||
        await self.handle_any(False)
 | 
			
		||||
 | 
			
		||||
class FileHandler(tornado.web.RequestHandler):
 | 
			
		||||
class PlaylistHandler(tornado.web.RequestHandler):
 | 
			
		||||
    def get(self):
 | 
			
		||||
        self.set_header("Content-Type", "text/plain; charset=utf-8")
 | 
			
		||||
        self.write(playlist)
 | 
			
		||||
 | 
			
		||||
class IconHandler(tornado.web.RequestHandler):
 | 
			
		||||
    def get(self):
 | 
			
		||||
        self.set_header("Content-Type", "image/png")
 | 
			
		||||
        self.write(favicon)
 | 
			
		||||
 | 
			
		||||
class StyleHandler(tornado.web.RequestHandler):
 | 
			
		||||
    def get(self):
 | 
			
		||||
        self.set_header("Content-Type", "text/css; charset=utf-8")
 | 
			
		||||
        self.write(custom_style)
 | 
			
		||||
try:
 | 
			
		||||
    handlers = []
 | 
			
		||||
    handlers.append((tornado.routing.PathMatches("/sources.m3u8"), FileHandler))
 | 
			
		||||
    handlers.append((tornado.routing.PathMatches("/sources.m3u8"), PlaylistHandler))
 | 
			
		||||
    handlers.append((tornado.routing.PathMatches("/favicon.ico"), IconHandler))
 | 
			
		||||
    handlers.append((tornado.routing.PathMatches("/style.css"), StyleHandler))
 | 
			
		||||
    handlers.append((tornado.routing.AnyMatches(), MainHandler))
 | 
			
		||||
    app_web = tornado.web.Application(handlers)
 | 
			
		||||
    app_web.listen(8080)
 | 
			
		||||
 
 | 
			
		||||
@@ -3,24 +3,33 @@
 | 
			
		||||
const fs = require("fs");
 | 
			
		||||
const css = require("css");
 | 
			
		||||
 | 
			
		||||
fs.readFile("/app/chromecast.css", "utf-8", (err, data) => {
 | 
			
		||||
    const ast = css.parse(data);
 | 
			
		||||
    for(const rule of ast.stylesheet.rules) {
 | 
			
		||||
        const decls = [];
 | 
			
		||||
        if(Symbol.iterator in Object(rule.declarations)) {
 | 
			
		||||
            for(const decl of rule.declarations) {
 | 
			
		||||
                const isNotUrl = !(decl.value.toLowerCase().startsWith("url"));
 | 
			
		||||
                const isNotContent = !(decl.property.toLowerCase() == "content");
 | 
			
		||||
                if(isNotContent && isNotUrl) {
 | 
			
		||||
                    decls.push(decl);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            rule.declarations = decls;
 | 
			
		||||
        }
 | 
			
		||||
fs.readFile("/app/style.css", "utf-8", (err, a) => {
 | 
			
		||||
    let data = "";
 | 
			
		||||
    if(err === null) {
 | 
			
		||||
        data = a + "\n";
 | 
			
		||||
    }
 | 
			
		||||
    fs.appendFile("/app/style.css", css.stringify(ast, {"compress": true}), (err) => {
 | 
			
		||||
        if(err !== null) {
 | 
			
		||||
            console.log(err);
 | 
			
		||||
    fs.readFile("/app/setup/chromecast.css", "utf-8", (err, b) => {
 | 
			
		||||
        if(err === null) {
 | 
			
		||||
            data += b + "\n";
 | 
			
		||||
        }
 | 
			
		||||
        const ast = css.parse(data);
 | 
			
		||||
        for(const rule of ast.stylesheet.rules) {
 | 
			
		||||
            const decls = [];
 | 
			
		||||
            if(Symbol.iterator in Object(rule.declarations)) {
 | 
			
		||||
                for(const decl of rule.declarations) {
 | 
			
		||||
                    const isNotUrl = !(decl.value.toLowerCase().startsWith("url"));
 | 
			
		||||
                    const isNotContent = !(decl.property.toLowerCase() == "content");
 | 
			
		||||
                    if(isNotContent && isNotUrl) {
 | 
			
		||||
                        decls.push(decl);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                rule.declarations = decls;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        fs.writeFile("/app/style.css", css.stringify(ast, {"compress": true}), (err) => {
 | 
			
		||||
            if(err !== null) {
 | 
			
		||||
                console.log(err);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user