diff --git a/app/logical/downloads/rewrite_strategies/pixiv.rb b/app/logical/downloads/rewrite_strategies/pixiv.rb index 71c7336de..91e1e6f90 100644 --- a/app/logical/downloads/rewrite_strategies/pixiv.rb +++ b/app/logical/downloads/rewrite_strategies/pixiv.rb @@ -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] diff --git a/app/logical/pixiv_ugoira_service.rb b/app/logical/pixiv_ugoira_service.rb index 594f0bd7c..9068c1d4e 100644 --- a/app/logical/pixiv_ugoira_service.rb +++ b/app/logical/pixiv_ugoira_service.rb @@ -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 diff --git a/app/logical/sources/strategies/pixiv.rb b/app/logical/sources/strategies/pixiv.rb index 02c44e51e..4e31d2a13 100644 --- a/app/logical/sources/strategies/pixiv.rb +++ b/app/logical/sources/strategies/pixiv.rb @@ -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 diff --git a/app/models/pixiv_ugoira_frame_data.rb b/app/models/pixiv_ugoira_frame_data.rb index 9e1f6e1e4..005dbe68f 100644 --- a/app/models/pixiv_ugoira_frame_data.rb +++ b/app/models/pixiv_ugoira_frame_data.rb @@ -1,4 +1,4 @@ class PixivUgoiraFrameData < ActiveRecord::Base - attr_accessible :post_id, :data + attr_accessible :post_id, :data, :content_type serialize :data end diff --git a/app/models/post.rb b/app/models/post.rb index 909da7225..8dd4dd8fd 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -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? diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index e64c60803..cbd2bbb14 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -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? diff --git a/app/views/posts/partials/show/_ugoira.html.erb b/app/views/posts/partials/show/_ugoira.html.erb new file mode 100644 index 000000000..31a038812 --- /dev/null +++ b/app/views/posts/partials/show/_ugoira.html.erb @@ -0,0 +1,43 @@ +<%= content_tag(:canvas, nil, :width => post.image_width, :height => post.image_height, :id => "ugoira-canvas") %> + +
+ <%= 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 %> +
+ +<% content_for(:html_header) do %> + <%= javascript_include_tag "ugoira_player" %> + +<% end %> diff --git a/config/initializers/assets.rb b/config/initializers/assets.rb index 5842fed68..8e6e91e7c 100644 --- a/config/initializers/assets.rb +++ b/config/initializers/assets.rb @@ -1 +1 @@ -Rails.application.config.assets.precompile += %w( stupidtable.js ) \ No newline at end of file +Rails.application.config.assets.precompile += %w( stupidtable.js ugoira_player.js ) \ No newline at end of file diff --git a/db/migrate/20141009231234_create_pixiv_ugoira_frame_data.rb b/db/migrate/20141009231234_create_pixiv_ugoira_frame_data.rb index cb03d1287..ec175ee0e 100644 --- a/db/migrate/20141009231234_create_pixiv_ugoira_frame_data.rb +++ b/db/migrate/20141009231234_create_pixiv_ugoira_frame_data.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index 2c1f3c0e5..405cb4e1e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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: --