add ugoira support in view

This commit is contained in:
r888888888
2014-10-16 14:25:05 -07:00
parent 3bb06c2be4
commit 4c73fb9f79
10 changed files with 69 additions and 8 deletions

View File

@@ -34,6 +34,7 @@ module Downloads
data[:ugoira_frame_data] = source.ugoira_frame_data
data[:ugoira_width] = source.ugoira_width
data[:ugoira_height] = source.ugoira_height
data[:ugoira_content_type] = source.ugoira_content_type
return [source.file_url, headers, data]
else
return [url, headers, data]

View File

@@ -1,12 +1,12 @@
class PixivUgoiraService
attr_reader :width, :height, :frame_data
attr_reader :width, :height, :frame_data, :content_type
def process(post)
save_frame_data(post)
end
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
def generate_resizes(source_path, output_path, preview_path)
@@ -17,5 +17,6 @@ class PixivUgoiraService
@frame_data = data[:ugoira_frame_data]
@width = data[:ugoira_width]
@height = data[:ugoira_height]
@content_type = data[:ugoira_content_type]
end
end

View File

@@ -5,7 +5,7 @@ require 'csv'
module Sources
module Strategies
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)
url =~ /^https?:\/\/(?:\w+\.)?pixiv\.net/
@@ -46,7 +46,7 @@ module Sources
@artist_name, @profile_url = get_profile_from_page(page)
@pixiv_moniker = get_moniker_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)
@page_count = get_page_count_from_page(page)
@@ -190,6 +190,7 @@ module Sources
data = JSON.parse(json)
zip_url = data["src"].sub("_ugoira600x600.zip", "_ugoira1920x1080.zip")
frame_data = data["frames"]
content_type = data["mime_type"]
if javascript =~ /illustSize\s*=\s*\[\s*(\d+)\s*,\s*(\d+)\s*\]/
image_width = $1.to_i
@@ -199,7 +200,7 @@ module Sources
image_height = 600
end
return [zip_url, frame_data, image_width, image_height]
return [zip_url, frame_data, image_width, image_height, content_type]
end
end

View File

@@ -1,4 +1,4 @@
class PixivUgoiraFrameData < ActiveRecord::Base
attr_accessible :post_id, :data
attr_accessible :post_id, :data, :content_type
serialize :data
end

View File

@@ -138,7 +138,11 @@ class Post < ActiveRecord::Base
end
def is_video?
file_ext =~ /webm|zip/i
file_ext =~ /webm/i
end
def is_ugoira?
file_ext =~ /zip/i
end
def has_preview?

View File

@@ -167,6 +167,8 @@ class PostPresenter < Presenter
template.render("posts/partials/show/flash", :post => @post)
elsif @post.is_video?
template.render("posts/partials/show/video", :post => @post)
elsif @post.is_ugoira?
template.render("posts/partials/show/ugoira", :post => @post)
elsif !@post.is_image?
template.render("posts/partials/show/download", :post => @post)
elsif @post.is_image?

View 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 %>

View File

@@ -1 +1 @@
Rails.application.config.assets.precompile += %w( stupidtable.js )
Rails.application.config.assets.precompile += %w( stupidtable.js ugoira_player.js )

View File

@@ -3,6 +3,7 @@ class CreatePixivUgoiraFrameData < ActiveRecord::Migration
create_table :pixiv_ugoira_frame_data do |t|
t.integer :post_id
t.text :data
t.string :content_type
t.timestamps
end

View File

@@ -2368,6 +2368,7 @@ CREATE TABLE pixiv_ugoira_frame_data (
id integer NOT NULL,
post_id integer,
data text,
content_type character varying(255),
created_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);
--
-- 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:
--