MediaCrush embedding (the right way?)
This commit is contained in:
parent
6f6766b9a0
commit
9fb8ab50e1
@ -4808,11 +4808,56 @@
|
|||||||
},
|
},
|
||||||
MediaCrush: {
|
MediaCrush: {
|
||||||
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i,
|
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i,
|
||||||
style: 'border: 0; width: 640px; height: 480px; resize: both;',
|
style: 'border: 0;',
|
||||||
el: function(a) {
|
el: function(a) {
|
||||||
return $.el('iframe', {
|
var el;
|
||||||
src: "https://mediacru.sh/" + a.dataset.uid
|
|
||||||
|
el = $.el('div');
|
||||||
|
$.cache("https://mediacru.sh/" + a.dataset.uid + ".json", function() {
|
||||||
|
var embed, file, files, status, type, _i, _j, _len, _len1, _ref;
|
||||||
|
|
||||||
|
status = this.status;
|
||||||
|
if (![200, 304].contains(status)) {
|
||||||
|
return div.innerHTML = "ERROR " + status;
|
||||||
|
}
|
||||||
|
files = JSON.parse(this.response).files;
|
||||||
|
_ref = ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg'];
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
type = _ref[_i];
|
||||||
|
for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
|
||||||
|
file = files[_j];
|
||||||
|
if (file.type === type) {
|
||||||
|
embed = file;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (embed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!embed) {
|
||||||
|
return div.innerHTML = "ERROR: Not a valid filetype";
|
||||||
|
}
|
||||||
|
return el.innerHTML = (function() {
|
||||||
|
switch (embed.type) {
|
||||||
|
case 'video/mp4':
|
||||||
|
case 'video/ogv':
|
||||||
|
return "<video autoplay loop>\n <source src=\"https://mediacru.sh/" + a.dataset.uid + ".mp4\" type=\"video/mp4;\">\n <source src=\"https://mediacru.sh/" + a.dataset.uid + ".ogv\" type=\"video/ogg; codecs='theora, vorbis'\">\n</video>";
|
||||||
|
case 'image/png':
|
||||||
|
case 'image/gif':
|
||||||
|
case 'image/jpeg':
|
||||||
|
return "<a target=_blank href='" + a.dataset.href + "'><img src='https://mediacru.sh/" + file.file + "'></a>";
|
||||||
|
case 'image/svg':
|
||||||
|
case 'image/svg+xml':
|
||||||
|
return "<embed src='https://mediacru.sh/" + file.file + "' type='image/svg+xml' />";
|
||||||
|
case 'audio/mpeg':
|
||||||
|
return "<audio controls><source src='https://mediacru.sh/" + file.file + "'></audio>";
|
||||||
|
default:
|
||||||
|
return "ERROR: No valid filetype.";
|
||||||
|
}
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pastebin: {
|
pastebin: {
|
||||||
|
|||||||
@ -4815,11 +4815,56 @@
|
|||||||
},
|
},
|
||||||
MediaCrush: {
|
MediaCrush: {
|
||||||
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i,
|
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i,
|
||||||
style: 'border: 0; width: 640px; height: 480px; resize: both;',
|
style: 'border: 0;',
|
||||||
el: function(a) {
|
el: function(a) {
|
||||||
return $.el('iframe', {
|
var el;
|
||||||
src: "https://mediacru.sh/" + a.dataset.uid
|
|
||||||
|
el = $.el('div');
|
||||||
|
$.cache("https://mediacru.sh/" + a.dataset.uid + ".json", function() {
|
||||||
|
var embed, file, files, status, type, _i, _j, _len, _len1, _ref;
|
||||||
|
|
||||||
|
status = this.status;
|
||||||
|
if (![200, 304].contains(status)) {
|
||||||
|
return div.innerHTML = "ERROR " + status;
|
||||||
|
}
|
||||||
|
files = JSON.parse(this.response).files;
|
||||||
|
_ref = ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg'];
|
||||||
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||||
|
type = _ref[_i];
|
||||||
|
for (_j = 0, _len1 = files.length; _j < _len1; _j++) {
|
||||||
|
file = files[_j];
|
||||||
|
if (file.type === type) {
|
||||||
|
embed = file;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (embed) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!embed) {
|
||||||
|
return div.innerHTML = "ERROR: Not a valid filetype";
|
||||||
|
}
|
||||||
|
return el.innerHTML = (function() {
|
||||||
|
switch (embed.type) {
|
||||||
|
case 'video/mp4':
|
||||||
|
case 'video/ogv':
|
||||||
|
return "<video autoplay loop>\n <source src=\"https://mediacru.sh/" + a.dataset.uid + ".mp4\" type=\"video/mp4;\">\n <source src=\"https://mediacru.sh/" + a.dataset.uid + ".ogv\" type=\"video/ogg; codecs='theora, vorbis'\">\n</video>";
|
||||||
|
case 'image/png':
|
||||||
|
case 'image/gif':
|
||||||
|
case 'image/jpeg':
|
||||||
|
return "<a target=_blank href='" + a.dataset.href + "'><img src='https://mediacru.sh/" + file.file + "'></a>";
|
||||||
|
case 'image/svg':
|
||||||
|
case 'image/svg+xml':
|
||||||
|
return "<embed src='https://mediacru.sh/" + file.file + "' type='image/svg+xml' />";
|
||||||
|
case 'audio/mpeg':
|
||||||
|
return "<audio controls><source src='https://mediacru.sh/" + file.file + "'></audio>";
|
||||||
|
default:
|
||||||
|
return "ERROR: No valid filetype.";
|
||||||
|
}
|
||||||
|
})();
|
||||||
});
|
});
|
||||||
|
return el;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
pastebin: {
|
pastebin: {
|
||||||
|
|||||||
@ -293,33 +293,35 @@ Linkify =
|
|||||||
|
|
||||||
MediaCrush:
|
MediaCrush:
|
||||||
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i
|
regExp: /.*(?:mediacru.sh\/)([0-9a-z_]+)/i
|
||||||
style: 'border: 0; width: 640px; height: 480px; resize: both;'
|
style: 'border: 0;'
|
||||||
el: (a) ->
|
el: (a) ->
|
||||||
$.el 'iframe',
|
el = $.el 'div'
|
||||||
src: "https://mediacru.sh/#{a.dataset.uid}"
|
$.cache "https://mediacru.sh/#{a.dataset.uid}.json", ->
|
||||||
# MediaCrush CORS When?
|
{status} = @
|
||||||
#
|
return div.innerHTML = "ERROR #{status}" unless [200, 304].contains status
|
||||||
# el = $.el 'div'
|
{files} = JSON.parse @response
|
||||||
# $.cache "https://mediacru.sh/#{a.dataset.uid}.json", ->
|
for type in ['video/mp4', 'video/ogv', 'image/svg+xml', 'image/png', 'image/gif', 'image/jpeg', 'image/svg', 'audio/mpeg']
|
||||||
# {status} = @
|
for file in files
|
||||||
# return unless [200, 304].contains status
|
if file.type is type
|
||||||
# {files} = JSON.parse req.response
|
embed = file
|
||||||
# file = file for file of files when files.hasOwnProperty file
|
break
|
||||||
# el.innerHTML = switch file.type
|
break if embed
|
||||||
# when 'video/mp4', 'video/ogv'
|
return div.innerHTML = "ERROR: Not a valid filetype" unless embed
|
||||||
# """
|
el.innerHTML = switch embed.type
|
||||||
#<video autoplay loop>
|
when 'video/mp4', 'video/ogv' then """
|
||||||
# <source src="https://mediacru.sh/#{a.dataset.uid}.mp4" type="video/mp4;">
|
<video autoplay loop>
|
||||||
# <source src="https://mediacru.sh/#{a.dataset.uid}.ogv" type="video/ogg; codecs='theora, vorbis'">
|
<source src="https://mediacru.sh/#{a.dataset.uid}.mp4" type="video/mp4;">
|
||||||
#</video>"""
|
<source src="https://mediacru.sh/#{a.dataset.uid}.ogv" type="video/ogg; codecs='theora, vorbis'">
|
||||||
# when 'image/png', 'image/gif', 'image/jpeg'
|
</video>"""
|
||||||
# "<a target=_blank href='#{a.dataset.href}'><img src='https://mediacru.sh/#{file.file}'></a>"
|
when 'image/png', 'image/gif', 'image/jpeg'
|
||||||
# when 'image/svg', 'image/svg+xml'
|
"<a target=_blank href='#{a.dataset.href}'><img src='https://mediacru.sh/#{file.file}'></a>"
|
||||||
# "<embed src='https://mediacru.sh/#{file.file}' type='image/svg+xml' />"
|
when 'image/svg', 'image/svg+xml'
|
||||||
# when 'audio/mpeg'
|
"<embed src='https://mediacru.sh/#{file.file}' type='image/svg+xml' />"
|
||||||
# "<audio controls><source src='https://mediacru.sh/#{file.file}'></audio>"
|
when 'audio/mpeg'
|
||||||
# el
|
"<audio controls><source src='https://mediacru.sh/#{file.file}'></audio>"
|
||||||
|
else
|
||||||
|
"ERROR: No valid filetype."
|
||||||
|
el
|
||||||
|
|
||||||
pastebin:
|
pastebin:
|
||||||
regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/
|
regExp: /.*(?:pastebin.com\/(?!u\/))([^#\&\?]*).*/
|
||||||
|
|||||||
@ -58,4 +58,3 @@ Time =
|
|||||||
S: -> Time.zeroPad @getSeconds()
|
S: -> Time.zeroPad @getSeconds()
|
||||||
y: -> @getFullYear().toString()[2..]
|
y: -> @getFullYear().toString()[2..]
|
||||||
Y: -> @getFullYear()
|
Y: -> @getFullYear()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user