Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flash support in modern browsers #644

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/css/post-main-view.styl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@

.post-content
margin: 0
background-size: cover
background-repeat: no-repeat

.darktheme .post-view
>.sidebar
Expand Down
1 change: 1 addition & 0 deletions client/html/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,6 @@
<div id='content-holder'></div>
<script type='text/javascript' src='js/vendor.min.js'></script>
<script type='text/javascript' src='js/app.min.js'></script>
<script type='text/javascript' src='https://unpkg.com/@ruffle-rs/ruffle' async></script>
</body>
</html>
5 changes: 3 additions & 2 deletions client/html/post_content.tpl
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<div class='post-content post-type-<%- ctx.post.type %>'>
<div class='post-content post-type-<%- ctx.post.type %>' style='<%- ctx.post.type === 'flash' ? 'background-image: url('+ctx.post.thumbnailUrl+')' : '' %>'>
<% if (['image', 'animation'].includes(ctx.post.type)) { %>

<img class='resize-listener' alt='' src='<%- ctx.post.contentUrl %>'/>

<% } else if (ctx.post.type === 'flash') { %>

<object class='resize-listener' width='<%- ctx.post.canvasWidth %>' height='<%- ctx.post.canvasHeight %>' data='<%- ctx.post.contentUrl %>'>
<param name='wmode' value='opaque'/>
<param name='wmode' value='transparent'/>
<param name='movie' value='<%- ctx.post.contentUrl %>'/>
<div class='messages'><div class='message-wrapper'><div class='message error'>Your browser does not support Flash.</div></div></div>
</object>

<% } else if (ctx.post.type === 'video') { %>
Expand Down
13 changes: 13 additions & 0 deletions client/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ const pools = require("./pools.js");
const api = require("./api.js");
const settings = require("./models/settings.js");

const rgb2hex = (rgb) => `#${rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/).slice(1).map(n => parseInt(n, 10).toString(16).padStart(2, '0')).join('')}`

window.RufflePlayer = window.RufflePlayer || {};
window.RufflePlayer.config = {
"polyfills": true,
"autoplay": "off",
"warnOnUnsupportedContent": false,
"showSwfDownload": true,
"splashScreen": false,
};

Promise.resolve()
.then(() => api.fetchConfig())
.then(
Expand Down Expand Up @@ -99,6 +110,8 @@ Promise.resolve()
if (settings.get().darkTheme) {
document.body.classList.add("darktheme");
}

window.RufflePlayer.config.autoplay = settings.get().autoplayVideos ? "auto" : "off"
})
.then(() => api.loginFromCookies())
.then(
Expand Down
1 change: 1 addition & 0 deletions client/js/views/settings_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class SettingsView extends events.EventTarget {

_evtSubmit(e) {
e.preventDefault();
window.RufflePlayer.config.autoplay = this._find("autoplay-videos").checked ? "auto" : "off"
this.dispatchEvent(
new CustomEvent("submit", {
detail: {
Expand Down
23 changes: 18 additions & 5 deletions server/szurubooru/func/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class Image:
def __init__(self, content: bytes) -> None:
self.content = content
self._reload_info()
if self.info["format"]["format_name"] == "swf":
self.content = self.swf_to_png()
self._reload_info()

@property
def width(self) -> int:
Expand Down Expand Up @@ -60,10 +63,7 @@ def resize_fill(self, width: int, height: int) -> None:
"png",
"-",
]
if (
"duration" in self.info["format"]
and self.info["format"]["format_name"] != "swf"
):
if "duration" in self.info["format"]:
duration = float(self.info["format"]["duration"])
if duration > 3:
cli = [
Expand All @@ -76,6 +76,19 @@ def resize_fill(self, width: int, height: int) -> None:
self.content = content
self._reload_info()

def swf_to_png(self) -> bytes:
return self._execute(
[
"--silent",
"-g",
"gl",
"--",
"{path}",
"-",
],
program="exporter",
)

def to_png(self) -> bytes:
return self._execute(
[
Expand Down Expand Up @@ -315,7 +328,7 @@ def _reload_info(self) -> None:
)
assert "format" in self.info
assert "streams" in self.info
if len(self.info["streams"]) < 1:
if len(self.info["streams"]) < 1 and self.info["format"]["format_name"] != "swf":
logger.warning("The video contains no video streams.")
raise errors.ProcessingError(
"The video contains no video streams."
Expand Down