add ugoira support in view
This commit is contained in:
@@ -34,6 +34,7 @@ module Downloads
|
|||||||
data[:ugoira_frame_data] = source.ugoira_frame_data
|
data[:ugoira_frame_data] = source.ugoira_frame_data
|
||||||
data[:ugoira_width] = source.ugoira_width
|
data[:ugoira_width] = source.ugoira_width
|
||||||
data[:ugoira_height] = source.ugoira_height
|
data[:ugoira_height] = source.ugoira_height
|
||||||
|
data[:ugoira_content_type] = source.ugoira_content_type
|
||||||
return [source.file_url, headers, data]
|
return [source.file_url, headers, data]
|
||||||
else
|
else
|
||||||
return [url, headers, data]
|
return [url, headers, data]
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
class PixivUgoiraService
|
class PixivUgoiraService
|
||||||
attr_reader :width, :height, :frame_data
|
attr_reader :width, :height, :frame_data, :content_type
|
||||||
|
|
||||||
def process(post)
|
def process(post)
|
||||||
save_frame_data(post)
|
save_frame_data(post)
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_frame_data(post)
|
def save_frame_data(post)
|
||||||
PixivUgoiraFrameData.create(:data => @frame_data, :post_id => post.id)
|
PixivUgoiraFrameData.create(:data => @frame_data, :content_type => @content_type, :post_id => post.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_resizes(source_path, output_path, preview_path)
|
def generate_resizes(source_path, output_path, preview_path)
|
||||||
@@ -17,5 +17,6 @@ class PixivUgoiraService
|
|||||||
@frame_data = data[:ugoira_frame_data]
|
@frame_data = data[:ugoira_frame_data]
|
||||||
@width = data[:ugoira_width]
|
@width = data[:ugoira_width]
|
||||||
@height = data[:ugoira_height]
|
@height = data[:ugoira_height]
|
||||||
|
@content_type = data[:ugoira_content_type]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ require 'csv'
|
|||||||
module Sources
|
module Sources
|
||||||
module Strategies
|
module Strategies
|
||||||
class Pixiv < Base
|
class Pixiv < Base
|
||||||
attr_reader :zip_url, :ugoira_frame_data, :ugoira_width, :ugoira_height
|
attr_reader :zip_url, :ugoira_frame_data, :ugoira_width, :ugoira_height, :ugoira_content_type
|
||||||
|
|
||||||
def self.url_match?(url)
|
def self.url_match?(url)
|
||||||
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
|
||||||
@@ -46,7 +46,7 @@ module Sources
|
|||||||
@artist_name, @profile_url = get_profile_from_page(page)
|
@artist_name, @profile_url = get_profile_from_page(page)
|
||||||
@pixiv_moniker = get_moniker_from_page(page)
|
@pixiv_moniker = get_moniker_from_page(page)
|
||||||
@image_url = get_image_url_from_page(page)
|
@image_url = get_image_url_from_page(page)
|
||||||
@zip_url, @ugoira_frame_data, @ugoira_width, @ugoira_height = get_zip_url_from_page(page)
|
@zip_url, @ugoira_frame_data, @ugoira_width, @ugoira_height, @ugoira_content_type = get_zip_url_from_page(page)
|
||||||
@tags = get_tags_from_page(page)
|
@tags = get_tags_from_page(page)
|
||||||
@page_count = get_page_count_from_page(page)
|
@page_count = get_page_count_from_page(page)
|
||||||
|
|
||||||
@@ -190,6 +190,7 @@ module Sources
|
|||||||
data = JSON.parse(json)
|
data = JSON.parse(json)
|
||||||
zip_url = data["src"].sub("_ugoira600x600.zip", "_ugoira1920x1080.zip")
|
zip_url = data["src"].sub("_ugoira600x600.zip", "_ugoira1920x1080.zip")
|
||||||
frame_data = data["frames"]
|
frame_data = data["frames"]
|
||||||
|
content_type = data["mime_type"]
|
||||||
|
|
||||||
if javascript =~ /illustSize\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/
|
if javascript =~ /illustSize\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/
|
||||||
image_width = $1.to_i
|
image_width = $1.to_i
|
||||||
@@ -199,7 +200,7 @@ module Sources
|
|||||||
image_height = 600
|
image_height = 600
|
||||||
end
|
end
|
||||||
|
|
||||||
return [zip_url, frame_data, image_width, image_height]
|
return [zip_url, frame_data, image_width, image_height, content_type]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
class PixivUgoiraFrameData < ActiveRecord::Base
|
class PixivUgoiraFrameData < ActiveRecord::Base
|
||||||
attr_accessible :post_id, :data
|
attr_accessible :post_id, :data, :content_type
|
||||||
serialize :data
|
serialize :data
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -138,7 +138,11 @@ class Post < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
def is_video?
|
def is_video?
|
||||||
file_ext =~ /webm|zip/i
|
file_ext =~ /webm/i
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_ugoira?
|
||||||
|
file_ext =~ /zip/i
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_preview?
|
def has_preview?
|
||||||
|
|||||||
@@ -167,6 +167,8 @@ class PostPresenter < Presenter
|
|||||||
template.render("posts/partials/show/flash", :post => @post)
|
template.render("posts/partials/show/flash", :post => @post)
|
||||||
elsif @post.is_video?
|
elsif @post.is_video?
|
||||||
template.render("posts/partials/show/video", :post => @post)
|
template.render("posts/partials/show/video", :post => @post)
|
||||||
|
elsif @post.is_ugoira?
|
||||||
|
template.render("posts/partials/show/ugoira", :post => @post)
|
||||||
elsif !@post.is_image?
|
elsif !@post.is_image?
|
||||||
template.render("posts/partials/show/download", :post => @post)
|
template.render("posts/partials/show/download", :post => @post)
|
||||||
elsif @post.is_image?
|
elsif @post.is_image?
|
||||||
|
|||||||
43
app/views/posts/partials/show/_ugoira.html.erb
Normal file
43
app/views/posts/partials/show/_ugoira.html.erb
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<%= content_tag(:canvas, nil, :width => post.image_width, :height => post.image_height, :id => "ugoira-canvas") %>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= link_to "Play", "#", :id => "ugoira-play" %>
|
||||||
|
| <%= link_to "Pause", "#", :id => "ugoira-pause" %>
|
||||||
|
| <%= link_to "Rewind", "#", :id => "ugoira-rewind" %>
|
||||||
|
| <%= link_to "Stop", "#", :id => "ugoira-stop" %>
|
||||||
|
| <%= link_to "Save as video (right click and save)", post.large_file_url %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<% content_for(:html_header) do %>
|
||||||
|
<%= javascript_include_tag "ugoira_player" %>
|
||||||
|
<script type="text/javascript">
|
||||||
|
Danbooru.Ugoira = {};
|
||||||
|
|
||||||
|
Danbooru.Ugoira.create_player = function() {
|
||||||
|
var meta_data = {
|
||||||
|
mime_type: <%= raw @post.pixiv_ugoira_frame_data.content_type.to_json %>,
|
||||||
|
frames: <%= raw @post.pixiv_ugoira_frame_data.data.to_json %>
|
||||||
|
};
|
||||||
|
var options = {
|
||||||
|
canvas: document.getElementById("ugoira-canvas"),
|
||||||
|
source: "<%= @post.file_url %>",
|
||||||
|
metadata: meta_data,
|
||||||
|
chunkSize: 300000,
|
||||||
|
loop: true,
|
||||||
|
autoStart: true,
|
||||||
|
debug: false,
|
||||||
|
}
|
||||||
|
this.player = new ZipImagePlayer(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
Danbooru.Ugoira.player = null;
|
||||||
|
|
||||||
|
$(function() {
|
||||||
|
Danbooru.Ugoira.create_player();
|
||||||
|
$("#ugoira-play").click(function() {Danbooru.Ugoira.player.play();})
|
||||||
|
$("#ugoira-pause").click(function() {Danbooru.Ugoira.player.pause();})
|
||||||
|
$("#ugoira-rewind").click(function() {Danbooru.Ugoira.player.rewind();})
|
||||||
|
$("#ugoira-stop").click(function() {Danbooru.Ugoira.player.stop();})
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
<% end %>
|
||||||
@@ -1 +1 @@
|
|||||||
Rails.application.config.assets.precompile += %w( stupidtable.js )
|
Rails.application.config.assets.precompile += %w( stupidtable.js ugoira_player.js )
|
||||||
@@ -3,6 +3,7 @@ class CreatePixivUgoiraFrameData < ActiveRecord::Migration
|
|||||||
create_table :pixiv_ugoira_frame_data do |t|
|
create_table :pixiv_ugoira_frame_data do |t|
|
||||||
t.integer :post_id
|
t.integer :post_id
|
||||||
t.text :data
|
t.text :data
|
||||||
|
t.string :content_type
|
||||||
t.timestamps
|
t.timestamps
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -2368,6 +2368,7 @@ CREATE TABLE pixiv_ugoira_frame_data (
|
|||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
post_id integer,
|
post_id integer,
|
||||||
data text,
|
data text,
|
||||||
|
content_type character varying(255),
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone
|
updated_at timestamp without time zone
|
||||||
);
|
);
|
||||||
@@ -6300,6 +6301,13 @@ CREATE INDEX index_forum_subscriptions_on_user_id ON forum_subscriptions USING b
|
|||||||
CREATE INDEX index_forum_topic_visits_on_forum_topic_id ON forum_topic_visits USING btree (forum_topic_id);
|
CREATE INDEX index_forum_topic_visits_on_forum_topic_id ON forum_topic_visits USING btree (forum_topic_id);
|
||||||
|
|
||||||
|
|
||||||
|
--
|
||||||
|
-- Name: index_forum_topic_visits_on_last_read_at; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE INDEX index_forum_topic_visits_on_last_read_at ON forum_topic_visits USING btree (last_read_at);
|
||||||
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Name: index_forum_topic_visits_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
-- Name: index_forum_topic_visits_on_user_id; Type: INDEX; Schema: public; Owner: -; Tablespace:
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user