diff --git a/.gitignore b/.gitignore index 0ae34c0..245d2f1 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,8 @@ out-0.log err-0.log *.gif -*.ass \ No newline at end of file +temp/*.ass +*~ +*# + +!media/* \ No newline at end of file diff --git a/README.md b/README.md index cad322f..ecb246b 100644 --- a/README.md +++ b/README.md @@ -1,33 +1,123 @@ -![图片](https://dn-coding-net-production-pp.qbox.me/f5beb81a-abf9-424b-a92e-625b008d30b7.gif) +![图片](https://raw.githubusercontent.com/xtyxtyx/sorry/master/media/1.gif) -## 代码库 +[V2EX](https://www.v2ex.com/t/431802) + +## 微信小程序试用 +小程序在 2019 年因为「内容安全」被下线了,2023.4 刚申诉上线,大家可以扫码试用一下。 + +![图片](https://github.com/xtyxtyx/sorry/blob/master/media/gh_b404536005f9_258.jpg) + + +## 常用特效代码 +出现在句子中的特效代码会对其后的字符产生影响 +``` +咕咕{\i1}{\fs40}咕咕咕{\r}咕 +``` +![示例](https://raw.githubusercontent.com/xtyxtyx/sorry/master/media/2.png) +``` +\n 折行 +\h 空格 + +{\i1} 斜体 +{\i0} 取消斜体 + +{\b1} 粗体 +{\b0} 取消粗体 + +{\u1} 下划线 +{\u0} 取消下划线 + +{\fs60} 调整字号 + +{\fad(100,200)} 100ms淡入,200ms淡出 + +{\r} 重置所有特效 +``` +## 源代码库 ``` ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── public # 静态文件目录 +├── views # 主页目录 +├── templates # 模板目录 ├── README.md -├── resource # 模板文件目录,里边存放用于生成gif的文件 ├── site_config.yml # 站点配置文件 ├── src # 这里就是源代码 └── temp # 把临时文件安放在这里 ``` +另有 +- [python版](https://github.com/East196/sorrypy),由@East196编写 +- [java版](https://github.com/li24361/sorryJava),由@li24361编写 +- [nodejs版](https://github.com/q809198545/node-sorry),由@q809198545编写 +- [C# ASP.NET版](https://github.com/shuangrain/SorryNet),由@shuangrain编写 +- [微信小程序](https://github.com/CoXier/iemoji-wechat),由@CoXier编写 +- [微信小程序](https://github.com/trumanwong/remix-mini-program),由@trumanwong编写 +- [nodejs版(使用Drawtext filter渲染)](https://github.com/SnailDev/SnailDev.GifMaker),由@SnailDev编写 +- [网页版(使用Canvas渲染)](https://coding.net/u/hhhhhg/p/wjzGif-JavaScript/git),由@hhhhhg编写 +- [PHP版](https://github.com/PrintNow/php-sorry-gif),由@PrintNow编写 +- [Golang版](https://github.com/Hentioe/sorry-generator),由@Hentioe编写 +- [AlfredWork版](https://github.com/BlackDragonF/AlfredWorkflows),由@BlackDragonF编写 +- [nodejs版(使用koa2)](https://github.com/wadejs/sorry-template),由@wadejs编写 +- [VuePress版](https://github.com/fritx/SorryPress),由@fritx编写 +- [网页版](https://github.com/WincerChan/Meme-generator),由@WincerChan编写 + +## API + +制作GIF: +``` +POST https://sorry.xuty.tk/api//make +{ + "0": "好啊", + "1": "...", + ... +} + +# 返回GIF下载地址 +-> 200 /cache/c2f4069ed207dc38e0f2d9359a2fa6b7.gif + +# 或服务器忙 +-> 503 +``` +目前支持的template_name有: +``` +- sorry +- wangjingze +- jinkela # 金坷垃 +- marmot # 土拨鼠 +- dagong # 窃格瓦拉 +- diandongche # 窃格瓦拉偷电动车 +``` -## 部署 +## 部署指南 + +### 使用Docker +``` +docker build -t sorry ./app +docker run --rm -it -p 4567:4567 sorry +``` + +### docker-compose 一键启动 +``` +docker-compose up +``` + +### 手工部署 首先,机器上得安装好ruby :gem: 接下来: ```bash +cd ./app + # 安装bundler gem install bundler # [可选] 使用国内镜像 -gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ +gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ # [可选] Linux服务器一般需要安装中文字体 -apt install language-pack-zh-hans apt install ttf-wqy-microhei # 安装编译依赖 @@ -47,7 +137,7 @@ APP_ENV=production ruby src/sorry.rb ``` -### [可选] 使用PM2监控&自动重启 +#### [可选] 使用PM2监控&自动重启 ``` npm install pm2 -g @@ -62,9 +152,13 @@ sudo chmod 755 /etc/authbind/byport/80 alias pm2='authbind --deep pm2' authbind --deep pm2 update + +# [可选] 定时重启服务 +crontab -e +10 22 * * * pm2 start sorry ``` -## 定时清除缓存 +### 定时清除缓存 ``` crontab -e @@ -73,32 +167,28 @@ crontab -e 10 * * * * find /root/sorry/public/cache -name '*.gif' -mmin +700 -exec rm {} \; ``` -## 适配新Gif -目前,想要适配新的gif,需要改动3个文件 -``` -public/index.html -resource/sorry.mp4 -resource/sorry.erb -``` -其中 +## 添加GIF模板 +向网站中添加模板需要加入以下文件 + ``` -index.html 按照句子的多少删掉或者增加即可 -sorry.mp4 替换成新视频 -sorry.erb 替换成新的字幕模板 +templates//template.mp4 # 视频模板 +templates//template.ass # 字幕模板 +public//example.png # 展示图片 +views/.erb # 模板主页 ``` -### 字幕模板sorry.erb -首先使用aegisub为模板视频创建字幕,保存为sorry.ass(aegisub教程可以看这个 https://tieba.baidu.com/p/1360405931 ) -![图片](https://dn-coding-net-production-pp.qbox.me/56a213df-9ff7-41e0-9b6c-96b1f0fe2cb6.png) +其中`index.erb` 参考其他模板主页,增减``的数量即可 -然后把文本替换成模板字符串 <%= sentences[n] %> -![图片](https://dn-coding-net-production-pp.qbox.me/6b07bc65-c3d7-4251-aad2-bd7b05af9102.png) +然后发个Pull request -最后保存为sorry.erb +如果你不熟悉aegisub的使用,也可以只提供视频模板。如果你是github用户,可以发个issue, 也可以[发送邮件](mailto:xty50337@hotmail.com) -现在这个网站就可以制作新的gif了 +## 制作字幕模板template.ass +首先使用aegisub为模板视频创建字幕,保存为template.ass(aegisub教程可以看这个 https://tieba.baidu.com/p/1360405931 ) +![图片](https://raw.githubusercontent.com/xtyxtyx/sorry/master/media/3.png) -如果你不熟悉aegisub的使用,也可以发个issue,同时附上模板视频🎞️ +然后把文本替换成模板字符串 <%= sentences[n] %> +![图片](https://raw.githubusercontent.com/xtyxtyx/sorry/master/media/4.png) ## TODO @@ -108,3 +198,9 @@ sorry.erb 替换成新的字幕模板 - [x] 定时删除缓存,不然有多少硬盘空间也不够用 - [ ] 写个脚本,自动配置新的gif - [ ] 写测试 + +## 服务器 + +- [Cloudcone](https://app.cloudcone.com/?ref=940) sorry.xuty.tk部署在Cloudcone上 +- [Vultr 最低2.5$/月](https://www.vultr.com/?ref=7019614) +- [DigitalOcean 注册送10美金](https://m.do.co/c/67a58d6cf3da) diff --git a/app/Dockerfile b/app/Dockerfile new file mode 100644 index 0000000..4030243 --- /dev/null +++ b/app/Dockerfile @@ -0,0 +1,28 @@ +FROM ubuntu:bionic + +ADD ./Gemfile /app/ +WORKDIR /app + +# 使用国内清华源加快apt速度 +COPY ./sources.list /etc/apt/sources.list +RUN apt-get update +RUN apt-get install -y \ + locales \ + locales-all \ + ttf-wqy-microhei \ + ffmpeg \ + cron \ + build-essential \ + ruby-dev + +# 使用国内Gem镜像 +RUN gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/ +RUN gem install bundler +RUN bundle config mirror.https://rubygems.org https://gems.ruby-china.com +RUN bundle install + +ADD ./ /app + +# 定时任务 +RUN crontab cron-sorry +CMD cron && ruby src/sorry.rb diff --git a/Gemfile b/app/Gemfile similarity index 100% rename from Gemfile rename to app/Gemfile diff --git a/Gemfile.lock b/app/Gemfile.lock similarity index 100% rename from Gemfile.lock rename to app/Gemfile.lock diff --git a/app/cron-sorry b/app/cron-sorry new file mode 100644 index 0000000..bbe9234 --- /dev/null +++ b/app/cron-sorry @@ -0,0 +1 @@ +10 * * * * find /app/public/cache -name '*.gif' -mmin +700 -exec rm {} \; diff --git a/process.yml b/app/process.yml similarity index 100% rename from process.yml rename to app/process.yml diff --git a/public/404.html b/app/public/404.html similarity index 100% rename from public/404.html rename to app/public/404.html diff --git a/public/cookies.js b/app/public/cookies.js similarity index 100% rename from public/cookies.js rename to app/public/cookies.js diff --git a/app/public/dagong/example.png b/app/public/dagong/example.png new file mode 100644 index 0000000..5c63ac5 Binary files /dev/null and b/app/public/dagong/example.png differ diff --git a/app/public/diandongche/example.png b/app/public/diandongche/example.png new file mode 100644 index 0000000..1873cb4 Binary files /dev/null and b/app/public/diandongche/example.png differ diff --git a/public/favicon.ico b/app/public/favicon.ico similarity index 100% rename from public/favicon.ico rename to app/public/favicon.ico diff --git a/public/image/404.png b/app/public/image/404.png similarity index 100% rename from public/image/404.png rename to app/public/image/404.png diff --git a/public/invalid.html b/app/public/invalid.html similarity index 100% rename from public/invalid.html rename to app/public/invalid.html diff --git a/app/public/jinkela/example.png b/app/public/jinkela/example.png new file mode 100644 index 0000000..0e83aa8 Binary files /dev/null and b/app/public/jinkela/example.png differ diff --git a/app/public/kongming/example.png b/app/public/kongming/example.png new file mode 100644 index 0000000..32cb208 Binary files /dev/null and b/app/public/kongming/example.png differ diff --git a/public/main.js b/app/public/main.js similarity index 90% rename from public/main.js rename to app/public/main.js index e3beec5..226a1ff 100644 --- a/public/main.js +++ b/app/public/main.js @@ -3,6 +3,7 @@ var show_sidebar_btn = document.getElementById("show_sidebar") var sidebar_close_btn = document.getElementById("sidebar_close") var sidebar = document.getElementById("sidebar") var result = document.getElementById("result") +var wechat_checkbox = document.getElementById("wechat-checkbox") function make_body() { var body = {} @@ -43,7 +44,13 @@ function submit() { }; save_input() - xhttp.open("POST", "make", true); + + if (wechat_checkbox && wechat_checkbox.checked) { + xhttp.open("POST", "wechat/make", true); + } else { + xhttp.open("POST", "make", true); + } + xhttp.send(make_body()); } @@ -78,6 +85,7 @@ function save_input() { function sidebar_open() { sidebar.style.display = "block"; } + function sidebar_close() { sidebar.style.display = "none"; } @@ -85,4 +93,5 @@ function sidebar_close() { submit_btn.onclick = submit; show_sidebar_btn.onclick = sidebar_open; sidebar_close_btn.onclick = sidebar_close; + restore_input() diff --git a/app/public/marmot/example.png b/app/public/marmot/example.png new file mode 100644 index 0000000..c86c0db Binary files /dev/null and b/app/public/marmot/example.png differ diff --git a/public/robots.txt b/app/public/robots.txt similarity index 100% rename from public/robots.txt rename to app/public/robots.txt diff --git a/app/public/sorry/example.png b/app/public/sorry/example.png new file mode 100644 index 0000000..d995e9d Binary files /dev/null and b/app/public/sorry/example.png differ diff --git a/public/w3.css b/app/public/w3.css similarity index 100% rename from public/w3.css rename to app/public/w3.css diff --git a/app/public/wangjingze/example.png b/app/public/wangjingze/example.png new file mode 100644 index 0000000..68b57ce Binary files /dev/null and b/app/public/wangjingze/example.png differ diff --git a/app/site_config.yml b/app/site_config.yml new file mode 100644 index 0000000..47a3d4c --- /dev/null +++ b/app/site_config.yml @@ -0,0 +1,9 @@ +page_404: public/404.html +page_invalid: public/invalid.html + +server_ip: 0.0.0.0 +server_port: 4567 + +max_jobs: 8 + +ffmpeg_command: ffmpeg \ No newline at end of file diff --git a/app/sources.list b/app/sources.list new file mode 100644 index 0000000..3383584 --- /dev/null +++ b/app/sources.list @@ -0,0 +1,11 @@ +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security main restricted +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security universe +deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu bionic-security multiverse + diff --git a/app/src/serve.rkt b/app/src/serve.rkt new file mode 100644 index 0000000..5c596a9 --- /dev/null +++ b/app/src/serve.rkt @@ -0,0 +1,46 @@ +#lang racket + +(require racket/date) + +(define (go) + 'yep-it-works) + +(define (serve port-no) + (define main-cust (make-custodian)) + (parameterize ([current-custodian main-cust]) + (define listener (tcp-listen port-no 5 #t)) + (define (loop) + (accept-and-handle listener) + (loop)) + (thread loop)) + (lambda () + (custodian-shutdown-all main-cust))) + +(define (accept-and-handle listener) + (define cust (make-custodian)) + (parameterize ([current-custodian cust]) + (define-values (in out) (tcp-accept listener)) + (thread + (lambda () (handle in out) + (close-input-port in) + (close-output-port out)))) + ;; Watcher thread + (thread (lambda () + (sleep 10) + (custodian-shutdown-all cust)))) + +(define (handle in out) + (regexp-match #rx"(\r\n|^)\r\n" in) + + (display "HTTP/1.0 200 Okay\r\n" out) + (display "\r\n" out) + (display + (format "

~a

" (format-time)) + out)) + +(define (format-time) + (parameterize ([date-display-format 'chinese]) + (date->string (current-date)))) + +(println "Server is running...") +(define stop (serve 1234)) \ No newline at end of file diff --git a/app/src/sorry.rb b/app/src/sorry.rb new file mode 100644 index 0000000..af8be45 --- /dev/null +++ b/app/src/sorry.rb @@ -0,0 +1,130 @@ +require 'sinatra' +require 'json' +require 'erb' + +require_relative "./sorry/make_gif.rb" +require_relative "./sorry/config.rb" +require_relative "./sorry/check_deps.rb" + +# 检查依赖 +DepsChecker.check_all() + +# 默认跳转到sorry模板 +get "/" do + redirect to('/sorry/') +end + +# 兼容旧版 +get "/index.html" do + redirect to('/sorry/') +end + +# 跳转到// +get "/:template_name" do + template_name = params['template_name'] + redirect to("/#{template_name}/") +end + + +# 模板主页 +get "/:template_name/" do + template_name = params['template_name'] + path_to_file = "views/#{template_name}.erb" + + if File.exist?(path_to_file) + erb params['template_name'].to_sym + else + send_file Config::PAGE_404 + end + +end + +# Gif制作请求 +post "/:template_name/make" do + template_name = params['template_name'] + + body = JSON.parse(request.body.read) + sentences = [] + i = 0 + while sentence = body[i.to_s] + sentences[i] = sentence + i += 1 + end + + path_to_template_dir = "templates/#{template_name}/" + if ! Dir.exist?(path_to_template_dir) + halt 404 + end + + Sorry.render_gif("templates/#{template_name}/", sentences) +end + +# Gif制作请求(微信兼容版) +post "/sorry/wechat/make" do + template_name = "sorry" + + body = JSON.parse(request.body.read) + sentences = [] + i = 0 + while sentence = body[i.to_s] + sentences[i] = sentence + i += 1 + end + + Sorry.render_gif("templates/sorry/wechat/", sentences) +end + +# API +post "/api/:template_name/make" do + template_name = params['template_name'] + + body = JSON.parse(request.body.read) + if body.is_a?(Array) + sentences = body + else + sentences = [] + i = 0 + while sentence = body[i.to_s] + sentences[i] = sentence + i += 1 + end + end + + path_to_template_dir = "templates/#{template_name}/" + if ! Dir.exist?(path_to_template_dir) + halt 404 + end + + status_code, msg = Sorry.render_gif_api("templates/#{template_name}/", sentences) + + status(status_code) + msg +end + +# 兼容旧版 +post "/make" do + "

请刷新或清空浏览器缓存🍃

" +end + + +# 404页面 +not_found do + if %r<^/cache/.+> =~ request.path_info + send_file Config::PAGE_INVALID + else + send_file Config::PAGE_404 + end +end + + +# 静态文件 +set :static, true +set :public_folder, Dir.pwd + '/public' + + +# 设置监听地址 +set :port, Config::SERVER_PORT +set :bind, Config::SERVER_IP + +# 设置网页模板目录 +set :views, Dir.pwd + '/views' \ No newline at end of file diff --git a/app/src/sorry.rkt b/app/src/sorry.rkt new file mode 100644 index 0000000..5ba53f5 --- /dev/null +++ b/app/src/sorry.rkt @@ -0,0 +1,53 @@ +#lang racket +(require web-server/servlet + web-server/servlet-env + web-server/dispatch) + +(define (start req) + (sorry-dispatch req)) + +(define-values (sorry-dispatch sorry-url) + (dispatch-rules + [((string-arg) "") show-page] + [((string-arg) "make") make-gif])) + +(define (show-page req template-name) `(p "show")) + +(define template-table (make-hash)) + +(struct template (template-video + template-subtitle + example-image)) + +(define (load-templates dir) + (map load-template (scan-directories))) + +(define (scan-directories) + (filter directory-exists? (directory-list "templates"))) + +(define (load-template dir) + (let ([t-name (path-string dir)] + [t-video (build-path "templates" dir "template.mp4")] + [t-subtitle (build-path "templates" dir "template.erb")] ;; FIX!! + [t-image (build-path "templates" dir "example.png")]) + (if (andmap file-exists? (list + t-video + t-subtitle + t-image)) + (hash-set! template-table t-name + (template t-name t-video t-subtitle t-image)) + (printf "Error loading template: ~a\n" t-name)))) + +(define (make-gif req template-name) + (response/xexpr `(p + (a ((href "/cache/...") (target "_blank")) + (p "点击下载"))))) + +(serve/servlet start + #:launch-browser? #f + #:listen-ip "0.0.0.0" + #:port 4567 + #:servlet-regexp #rx"" + #:extra-files-paths + (list + (build-path (current-directory) "public"))) \ No newline at end of file diff --git a/src/sorry/cache.rb b/app/src/sorry/cache.rb similarity index 65% rename from src/sorry/cache.rb rename to app/src/sorry/cache.rb index 527fb51..78990a7 100644 --- a/src/sorry/cache.rb +++ b/app/src/sorry/cache.rb @@ -18,20 +18,20 @@ def get_url(filename) class LocalCache < Cache def initialize() - @temp_folder = Config::CACHE_FOLDER - @path = File.expand_path(@temp_folder, "./public/") + @cache_path = "cache/" + @local_cache_path = "public/cache/" end # TODO: rewrite this def file_exists?(filename) - File.exists?(@path + '/' + filename) + File.exists?(@local_cache_path + filename) end def add_file(path, filename = nil) - FileUtils.cp path, @path + FileUtils.cp path, @local_cache_path end def get_url(filename) - "/" + @temp_folder + filename + "/" + @cache_path + filename end end \ No newline at end of file diff --git a/app/src/sorry/check_deps.rb b/app/src/sorry/check_deps.rb new file mode 100644 index 0000000..ea8dc9a --- /dev/null +++ b/app/src/sorry/check_deps.rb @@ -0,0 +1,29 @@ +require_relative "./config.rb" + +# 检查依赖的安装情况 + +module DepsChecker + def DepsChecker.check_ffmpeg + if system "#{Config::FFMPEG_COMMAND} -version" + return + end + + print <<-MSG +看起来系统中没有安装ffmpeg😥 + +安装方式: +# Ubuntu +apt install ffmpeg + +# CentOS +yum install ffmpeg +MSG + exit + end + + def check_all() + check_ffmpeg() + end + + module_function :check_all +end \ No newline at end of file diff --git a/app/src/sorry/config.rb b/app/src/sorry/config.rb new file mode 100644 index 0000000..f76ec4f --- /dev/null +++ b/app/src/sorry/config.rb @@ -0,0 +1,15 @@ +require "yaml" + +module Config + config = YAML.load(File.read "site_config.yml") + + PAGE_404 = config["page_404"] + PAGE_INVALID = config["page_invalid"] + + SERVER_PORT = config["server_port"].to_i + SERVER_IP = config["server_ip"] + + MAX_JOBS = config['max_jobs'] + + FFMPEG_COMMAND = config['ffmpeg_command'] +end \ No newline at end of file diff --git a/app/src/sorry/make_gif.rb b/app/src/sorry/make_gif.rb new file mode 100644 index 0000000..f7ef028 --- /dev/null +++ b/app/src/sorry/make_gif.rb @@ -0,0 +1,101 @@ +require 'erb' +require 'digest' +require "thread" + +require_relative './cache.rb' +require_relative './config.rb' + +module Sorry + + $cache = LocalCache.new + + $jobs = 0 + $mutex = Mutex.new + + def Sorry.calculate_hash(template_dir,sentences) + Digest::MD5.hexdigest(template_dir + sentences.to_s) + end + + def Sorry.ffmpeg_avaliable? + $jobs < Config::MAX_JOBS + end + + def Sorry.make_gif_with_ffmpeg(template_dir, sentences, filename) + $mutex.lock + $jobs += 1 + $mutex.unlock + + gif_path = "temp/" + filename + ass_path = render_ass(template_dir, sentences, filename) + video_path = template_dir + "template.mp4" + + cmd = <<-CMD + #{Config::FFMPEG_COMMAND} -i #{video_path} \ + -vf ass=#{ass_path} -y #{gif_path} + CMD + + pid = spawn(cmd, [:out, :err]=>"/dev/null") + Process.wait(pid) + + gif_path + ensure + $mutex.lock + $jobs -= 1 + $mutex.unlock + puts "[ Current jobs ] #{$jobs}" + end + + def Sorry.ass_text(template_dir) + File.read(template_dir + "template.ass") + end + + def Sorry.render_ass(template_dir, sentences, filename) + output_file_path = "temp/" + filename + ".ass" + + rendered_ass_text = ERB.new(ass_text(template_dir)).result(binding) + + File.write(output_file_path, rendered_ass_text) + + output_file_path + end + + def render_gif(template_dir, sentences) + gif_file = calculate_hash(template_dir, sentences) + ".gif" + + if !$cache.file_exists?(gif_file) + if ffmpeg_avaliable? + path = make_gif_with_ffmpeg(template_dir, sentences, gif_file) + $cache.add_file(path) + File.delete(path) + else + return <<-HTML +

服务器忙!等下说不定就能用了⏳

+ HTML + end + end + + <<-HTML +

点击下载

+ HTML + end + + def render_gif_api(template_dir, sentences) + gif_file = calculate_hash(template_dir, sentences) + ".gif" + + if !$cache.file_exists?(gif_file) + if ffmpeg_avaliable? + path = make_gif_with_ffmpeg(template_dir, sentences, gif_file) + $cache.add_file(path) + File.delete(path) + else + return 503, "" + end + end + + return 200, $cache.get_url(gif_file) + end + + + module_function :render_gif + module_function :render_gif_api +end diff --git a/src/sorry/version.rb b/app/src/sorry/version.rb similarity index 100% rename from src/sorry/version.rb rename to app/src/sorry/version.rb diff --git a/app/templates/dagong/template.ass b/app/templates/dagong/template.ass new file mode 100644 index 0000000..942392c --- /dev/null +++ b/app/templates/dagong/template.ass @@ -0,0 +1,32 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 296 +PlayResY: 182 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.619565 +Video Zoom Percent: 2.500000 +Active Line: 2 +Video Position: 85 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.18696,0.593478,2,5,5,5,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.00,0:00:01.80,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:01.88,0:00:03.76,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:03.81,0:00:04.66,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:04.66,0:00:05.90,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:06.02,0:00:08.42,sorry,,0,0,0,,<%= sentences[4] %> +Dialogue: 0,0:00:08.42,0:00:10.75,sorry,,0,0,0,,<%= sentences[5] %> diff --git a/app/templates/dagong/template.mp4 b/app/templates/dagong/template.mp4 new file mode 100644 index 0000000..65f89db Binary files /dev/null and b/app/templates/dagong/template.mp4 differ diff --git a/app/templates/dagong/template_origin.mp4 b/app/templates/dagong/template_origin.mp4 new file mode 100644 index 0000000..3144a0b Binary files /dev/null and b/app/templates/dagong/template_origin.mp4 differ diff --git a/app/templates/diandongche/template.ass b/app/templates/diandongche/template.ass new file mode 100644 index 0000000..fcbcd88 --- /dev/null +++ b/app/templates/diandongche/template.ass @@ -0,0 +1,32 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 298 +PlayResY: 184 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.750000 +Active Line: 4 +Video Position: 83 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,25,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.20476,0.547619,2,5,5,6,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.00,0:00:02.50,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:02.98,0:00:04.90,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:05.36,0:00:07.34,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:07.34,0:00:09.85,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:10.33,0:00:12.35,sorry,,0,0,0,,<%= sentences[4] %> +Dialogue: 0,0:00:12.83,0:00:15.24,sorry,,0,0,0,,<%= sentences[5] %> diff --git a/app/templates/diandongche/template.mp4 b/app/templates/diandongche/template.mp4 new file mode 100644 index 0000000..12c59b9 Binary files /dev/null and b/app/templates/diandongche/template.mp4 differ diff --git a/app/templates/diandongche/template_origin.mp4 b/app/templates/diandongche/template_origin.mp4 new file mode 100644 index 0000000..e37e0ce Binary files /dev/null and b/app/templates/diandongche/template_origin.mp4 differ diff --git a/app/templates/jinkela/template.ass b/app/templates/jinkela/template.ass new file mode 100644 index 0000000..50b49a3 --- /dev/null +++ b/app/templates/jinkela/template.ass @@ -0,0 +1,30 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 300 +PlayResY: 186 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.500000 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,25,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.21786,0.553571,2,5,5,6,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.00,0:00:02.56,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:02.56,0:00:04.31,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:04.31,0:00:05.56,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:05.56,0:00:08.68,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:09.81,0:00:11.93,sorry,,0,0,0,,<%= sentences[4] %> +Dialogue: 0,0:00:12.06,0:00:14.68,sorry,,0,0,0,,<%= sentences[5] %> diff --git a/app/templates/jinkela/template.mp4 b/app/templates/jinkela/template.mp4 new file mode 100644 index 0000000..34d1030 Binary files /dev/null and b/app/templates/jinkela/template.mp4 differ diff --git a/app/templates/jinkela/template_origin.mp4 b/app/templates/jinkela/template_origin.mp4 new file mode 100644 index 0000000..7619946 Binary files /dev/null and b/app/templates/jinkela/template_origin.mp4 differ diff --git a/app/templates/kongming/template.ass b/app/templates/kongming/template.ass new file mode 100644 index 0000000..a5d1887 --- /dev/null +++ b/app/templates/kongming/template.ass @@ -0,0 +1,27 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 298 +PlayResY: 184 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.500000 +Video Position: 50 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,25,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.2,0.5,2,5,5,2,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.81,0:00:01.81,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:02.31,0:00:05.42,sorry,,0,0,0,,<%= sentences[1] %> diff --git a/app/templates/kongming/template.mp4 b/app/templates/kongming/template.mp4 new file mode 100644 index 0000000..359d648 Binary files /dev/null and b/app/templates/kongming/template.mp4 differ diff --git a/app/templates/kongming/template_origin.mp4 b/app/templates/kongming/template_origin.mp4 new file mode 100644 index 0000000..c1862f7 Binary files /dev/null and b/app/templates/kongming/template_origin.mp4 differ diff --git a/app/templates/marmot/template.ass b/app/templates/marmot/template.ass new file mode 100644 index 0000000..414fb41 --- /dev/null +++ b/app/templates/marmot/template.ass @@ -0,0 +1,28 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 298 +PlayResY: 184 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.500000 +Active Line: 1 +Video Position: 58 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,25,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.2,0.5,2,5,5,2,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.90,0:00:02.46,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:07.30,0:00:09.33,sorry,,0,0,0,,<%= sentences[1] %> diff --git a/app/templates/marmot/template.mp4 b/app/templates/marmot/template.mp4 new file mode 100644 index 0000000..c37e2c4 Binary files /dev/null and b/app/templates/marmot/template.mp4 differ diff --git a/app/templates/marmot/template_origin.mp4 b/app/templates/marmot/template_origin.mp4 new file mode 100644 index 0000000..daf7367 Binary files /dev/null and b/app/templates/marmot/template_origin.mp4 differ diff --git a/app/templates/sorry/template.ass b/app/templates/sorry/template.ass new file mode 100644 index 0000000..1ba6233 --- /dev/null +++ b/app/templates/sorry/template.ass @@ -0,0 +1,35 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 300 +PlayResY: 168 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.000000 +Active Line: 8 +Video Position: 25 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.1,0.5,2,5,5,5,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:01.18,0:00:01.56,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:03.18,0:00:04.43,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:05.31,0:00:07.43,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:07.56,0:00:09.93,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:10.06,0:00:11.56,sorry,,0,0,0,,<%= sentences[4] %> +Dialogue: 0,0:00:11.93,0:00:13.06,sorry,,0,0,0,,<%= sentences[5] %> +Dialogue: 0,0:00:13.81,0:00:16.31,sorry,,0,0,0,,<%= sentences[6] %> +Dialogue: 0,0:00:18.06,0:00:19.56,sorry,,0,0,0,,<%= sentences[7] %> +Dialogue: 0,0:00:19.60,0:00:21.60,sorry,,0,0,0,,<%= sentences[8] %> diff --git a/templates/sorry/template.erb b/app/templates/sorry/template.erb similarity index 100% rename from templates/sorry/template.erb rename to app/templates/sorry/template.erb diff --git a/app/templates/sorry/template.mp4 b/app/templates/sorry/template.mp4 new file mode 100644 index 0000000..e989d91 Binary files /dev/null and b/app/templates/sorry/template.mp4 differ diff --git a/templates/sorry/template.mp4 b/app/templates/sorry/template_origin.mp4 similarity index 100% rename from templates/sorry/template.mp4 rename to app/templates/sorry/template_origin.mp4 diff --git a/app/templates/sorry/wechat/template.ass b/app/templates/sorry/wechat/template.ass new file mode 100644 index 0000000..8fb9c1d --- /dev/null +++ b/app/templates/sorry/wechat/template.ass @@ -0,0 +1,35 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 236 +PlayResY: 132 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.781250 +Video Zoom Percent: 2.375000 +Active Line: 8 +Video Position: 165 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,0.8,0.4,2,4,4,2,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:01.18,0:00:01.56,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:03.18,0:00:04.43,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:05.31,0:00:07.43,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:07.56,0:00:09.93,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:10.06,0:00:11.56,sorry,,0,0,0,,<%= sentences[4] %> +Dialogue: 0,0:00:11.93,0:00:13.06,sorry,,0,0,0,,<%= sentences[5] %> +Dialogue: 0,0:00:13.81,0:00:16.31,sorry,,0,0,0,,<%= sentences[6] %> +Dialogue: 0,0:00:18.06,0:00:19.56,sorry,,0,0,0,,<%= sentences[7] %> +Dialogue: 0,0:00:19.60,0:00:21.60,sorry,,0,0,0,,<%= sentences[8] %> diff --git a/app/templates/sorry/wechat/template.mp4 b/app/templates/sorry/wechat/template.mp4 new file mode 100644 index 0000000..9d73856 Binary files /dev/null and b/app/templates/sorry/wechat/template.mp4 differ diff --git a/app/templates/wangjingze/template.ass b/app/templates/wangjingze/template.ass new file mode 100644 index 0000000..7f728ef --- /dev/null +++ b/app/templates/wangjingze/template.ass @@ -0,0 +1,30 @@ +[Script Info] +; Script generated by Aegisub 3.2.2 +; http://www.aegisub.org/ +Title: Default Aegisub file +ScriptType: v4.00+ +WrapStyle: 0 +ScaledBorderAndShadow: yes +YCbCr Matrix: TV.601 +PlayResX: 298 +PlayResY: 184 + +[Aegisub Project Garbage] +Audio File: template.mp4 +Video File: template.mp4 +Video AR Mode: 4 +Video AR Value: 1.619565 +Video Zoom Percent: 2.500000 +Active Line: 3 +Video Position: 50 + +[V4+ Styles] +Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding +Style: sorry,WenQuanYi Micro Hei,23,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,1.2,0.6,2,5,5,5,1 + +[Events] +Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text +Dialogue: 0,0:00:00.00,0:00:01.04,sorry,,0,0,0,,<%= sentences[0] %> +Dialogue: 0,0:00:01.46,0:00:02.90,sorry,,0,0,0,,<%= sentences[1] %> +Dialogue: 0,0:00:03.09,0:00:04.33,sorry,,0,0,0,,<%= sentences[2] %> +Dialogue: 0,0:00:04.59,0:00:05.93,sorry,,0,0,0,,<%= sentences[3] %> diff --git a/templates/wangjingze/template.erb b/app/templates/wangjingze/template.erb similarity index 94% rename from templates/wangjingze/template.erb rename to app/templates/wangjingze/template.erb index 73f22ae..2466597 100644 --- a/templates/wangjingze/template.erb +++ b/app/templates/wangjingze/template.erb @@ -26,4 +26,4 @@ Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:01.04,sorry,,0,0,0,,<%= sentences[0] %> Dialogue: 0,0:00:01.46,0:00:02.90,sorry,,0,0,0,,<%= sentences[1] %> Dialogue: 0,0:00:03.09,0:00:04.33,sorry,,0,0,0,,<%= sentences[2] %> -Dialogue: 0,0:00:04.39,0:00:06.37,sorry,,0,0,0,,<%= sentences[3] %> +Dialogue: 0,0:00:04.49,0:00:06.37,sorry,,0,0,0,,<%= sentences[3] %> diff --git a/app/templates/wangjingze/template.mp4 b/app/templates/wangjingze/template.mp4 new file mode 100644 index 0000000..e7b620c Binary files /dev/null and b/app/templates/wangjingze/template.mp4 differ diff --git a/templates/wangjingze/template_origin.mp4 b/app/templates/wangjingze/template_origin.mp4 similarity index 100% rename from templates/wangjingze/template_origin.mp4 rename to app/templates/wangjingze/template_origin.mp4 diff --git a/app/views/dagong.erb b/app/views/dagong.erb new file mode 100644 index 0000000..b774bb2 --- /dev/null +++ b/app/views/dagong.erb @@ -0,0 +1,47 @@ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/app/views/diandongche.erb b/app/views/diandongche.erb new file mode 100644 index 0000000..4b18321 --- /dev/null +++ b/app/views/diandongche.erb @@ -0,0 +1,47 @@ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/app/views/jinkela.erb b/app/views/jinkela.erb new file mode 100644 index 0000000..9e907c4 --- /dev/null +++ b/app/views/jinkela.erb @@ -0,0 +1,47 @@ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/app/views/kongming.erb b/app/views/kongming.erb new file mode 100644 index 0000000..1df3c58 --- /dev/null +++ b/app/views/kongming.erb @@ -0,0 +1,19 @@ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/public/wangjingze/index.html b/app/views/layout.erb similarity index 61% rename from public/wangjingze/index.html rename to app/views/layout.erb index a545f6f..79c8949 100644 --- a/public/wangjingze/index.html +++ b/app/views/layout.erb @@ -15,12 +15,17 @@
- +
@@ -32,39 +37,7 @@

在线生成Sorry,动图

-

- - -

- -

- - -

- -

- - -

- -

- - -

- -
- -

- -

+ <%= yield %>
diff --git a/app/views/marmot.erb b/app/views/marmot.erb new file mode 100644 index 0000000..6d9c491 --- /dev/null +++ b/app/views/marmot.erb @@ -0,0 +1,19 @@ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/app/views/sorry.erb b/app/views/sorry.erb new file mode 100644 index 0000000..fa88d43 --- /dev/null +++ b/app/views/sorry.erb @@ -0,0 +1,71 @@ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ + + + +
+ +

+ +

\ No newline at end of file diff --git a/app/views/wangjingze.erb b/app/views/wangjingze.erb new file mode 100644 index 0000000..2a94d72 --- /dev/null +++ b/app/views/wangjingze.erb @@ -0,0 +1,33 @@ +

+ + +

+ +

+ + +

+ +

+ + +

+ +

+ + +

+ +
+ +

+ +

\ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..c65e96e --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.4" + +services: + sorry: + build: app + restart: always + ports: + - 127.0.0.1:4567:4567 + volumes: + - ./temp:/app/temp + environment: + APP_ENV: production + LANG: UTF-8 \ No newline at end of file diff --git a/media/1.gif b/media/1.gif new file mode 100644 index 0000000..e7a4bc9 Binary files /dev/null and b/media/1.gif differ diff --git a/media/2.png b/media/2.png new file mode 100644 index 0000000..104ae02 Binary files /dev/null and b/media/2.png differ diff --git a/media/3.png b/media/3.png new file mode 100644 index 0000000..724a63d Binary files /dev/null and b/media/3.png differ diff --git a/media/4.png b/media/4.png new file mode 100644 index 0000000..c7f8830 Binary files /dev/null and b/media/4.png differ diff --git a/media/gh_b404536005f9_258.jpg b/media/gh_b404536005f9_258.jpg new file mode 100644 index 0000000..ae6e2f3 Binary files /dev/null and b/media/gh_b404536005f9_258.jpg differ diff --git a/public/cache/0d3c0765304c60d6e02c9783e0067e42.gif b/public/cache/0d3c0765304c60d6e02c9783e0067e42.gif deleted file mode 100644 index 8f88977..0000000 Binary files a/public/cache/0d3c0765304c60d6e02c9783e0067e42.gif and /dev/null differ diff --git a/public/cache/35c615e5237fa4ca747c4a5544b08e41.gif b/public/cache/35c615e5237fa4ca747c4a5544b08e41.gif deleted file mode 100644 index e384114..0000000 Binary files a/public/cache/35c615e5237fa4ca747c4a5544b08e41.gif and /dev/null differ diff --git a/public/cache/3aff7060f2ff31c5f8ee4d280f4aec0d.gif b/public/cache/3aff7060f2ff31c5f8ee4d280f4aec0d.gif deleted file mode 100644 index 39c4f92..0000000 Binary files a/public/cache/3aff7060f2ff31c5f8ee4d280f4aec0d.gif and /dev/null differ diff --git a/public/cache/3cfab5c16f5148f88b72640c51cefde4.gif b/public/cache/3cfab5c16f5148f88b72640c51cefde4.gif deleted file mode 100644 index 591a17c..0000000 Binary files a/public/cache/3cfab5c16f5148f88b72640c51cefde4.gif and /dev/null differ diff --git a/public/cache/460ce56b5ef38a60c7408db76a46ec95.gif b/public/cache/460ce56b5ef38a60c7408db76a46ec95.gif deleted file mode 100644 index bba1846..0000000 Binary files a/public/cache/460ce56b5ef38a60c7408db76a46ec95.gif and /dev/null differ diff --git a/public/cache/4ecec26d173b8353e88479b0996afcbf.gif b/public/cache/4ecec26d173b8353e88479b0996afcbf.gif deleted file mode 100644 index 0b888c9..0000000 Binary files a/public/cache/4ecec26d173b8353e88479b0996afcbf.gif and /dev/null differ diff --git a/public/cache/6ebd255556083c4c62f870462777ae19.gif b/public/cache/6ebd255556083c4c62f870462777ae19.gif deleted file mode 100644 index b539e4b..0000000 Binary files a/public/cache/6ebd255556083c4c62f870462777ae19.gif and /dev/null differ diff --git a/public/cache/c3669261f48eac82c555975e9dffebc3.gif b/public/cache/c3669261f48eac82c555975e9dffebc3.gif deleted file mode 100644 index 3483978..0000000 Binary files a/public/cache/c3669261f48eac82c555975e9dffebc3.gif and /dev/null differ diff --git a/public/cache/cc59cba5c49aedc60cabd70cd4b9ee40.gif b/public/cache/cc59cba5c49aedc60cabd70cd4b9ee40.gif deleted file mode 100644 index 63c7a66..0000000 Binary files a/public/cache/cc59cba5c49aedc60cabd70cd4b9ee40.gif and /dev/null differ diff --git a/public/cache/e1b2909f4ccbb2db6cf6410b39975458.gif b/public/cache/e1b2909f4ccbb2db6cf6410b39975458.gif deleted file mode 100644 index 0a0383c..0000000 Binary files a/public/cache/e1b2909f4ccbb2db6cf6410b39975458.gif and /dev/null differ diff --git a/public/cache/f8b3b607a5a65ecf7224e1a39352ffaf.gif b/public/cache/f8b3b607a5a65ecf7224e1a39352ffaf.gif deleted file mode 100644 index c65ca3b..0000000 Binary files a/public/cache/f8b3b607a5a65ecf7224e1a39352ffaf.gif and /dev/null differ diff --git a/public/sorry/example.png b/public/sorry/example.png deleted file mode 100644 index 533decd..0000000 Binary files a/public/sorry/example.png and /dev/null differ diff --git a/public/sorry/index.html b/public/sorry/index.html deleted file mode 100644 index bbd795d..0000000 --- a/public/sorry/index.html +++ /dev/null @@ -1,117 +0,0 @@ - - - - - - - Sorry! 在线生成 - - - - - - - - - - -
- -
- - -
-
- Lights -

在线生成Sorry,动图

-
- -
- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -

- - -

- -
- -

- -

- -
- -
- - - - - \ No newline at end of file diff --git a/public/wangjingze/example.png b/public/wangjingze/example.png deleted file mode 100644 index 75ecc70..0000000 Binary files a/public/wangjingze/example.png and /dev/null differ diff --git a/site_config.yml b/site_config.yml deleted file mode 100644 index 03bab3a..0000000 --- a/site_config.yml +++ /dev/null @@ -1,22 +0,0 @@ -title: Sorry! 在线生成 -header: 在线生成Sorry,动图 - -page_index: public/index.html -page_404: public/404.html -page_invalid: public/invalid.html - -template_folder: templates/ - -server_ip: 0.0.0.0 -server_port: 4567 - -# useless, reserved for future use -cache_mode: local - -# use to storage generated .ass file -temp_folder: temp/ - -# means public/cache/ -cache_folder: cache/ - -max_jobs: 8 \ No newline at end of file diff --git a/src/sorry.rb b/src/sorry.rb deleted file mode 100644 index 3b8bf68..0000000 --- a/src/sorry.rb +++ /dev/null @@ -1,65 +0,0 @@ -require 'sinatra' -require 'json' - -require_relative "./sorry/make_gif.rb" -require_relative "./sorry/config.rb" - -get "/" do - # Enter `sorry` template by default - redirect to('/sorry/') -end - - - -get "/:template_name" do - template_name = params['template_name'] - redirect to("/#{template_name}/") -end - - - -get "/:template_name/" do - template_name = params['template_name'] - path_to_file = "public/#{template_name}/index.html" - - if File.exist?(path_to_file) - send_file path_to_file - else - send_file Config::PAGE_404 - end -end - - - -post "/:template_name/make" do - template_name = params['template_name'] - - body = JSON.parse(request.body.read) - sentences = [] - i = 0 - while sentence = body[i.to_s] - sentences[i] = sentence - i += 1 - end - - Sorry.render_gif(template_name, sentences) -end - - - -not_found do - if %r<^/cache/.+> =~ request.path_info - send_file Config::PAGE_INVALID - else - send_file Config::PAGE_404 - end -end - - - -set :static, true -set :public_folder, Dir.pwd + '/public' - - -set :port, Config::SERVER_PORT -set :bind, Config::SERVER_IP \ No newline at end of file diff --git a/src/sorry/config.rb b/src/sorry/config.rb deleted file mode 100644 index 08728b7..0000000 --- a/src/sorry/config.rb +++ /dev/null @@ -1,21 +0,0 @@ -require "psych" - -module Config - config = Psych.load(File.read "site_config.yml") - - PAGE_INDEX = config["page_index"] - PAGE_404 = config["page_404"] - PAGE_INVALID = config["page_invalid"] - - TEMPLATE_FOLDER = config["template_folder"] - - SERVER_PORT = config["server_port"].to_i - SERVER_IP = config["server_ip"] - - CACHE_MODE = config["cache_mode"] - - TEMP_FOLDER = config["temp_folder"] - CACHE_FOLDER = config["cache_folder"] - - MAX_JOBS = config['max_jobs'] -end \ No newline at end of file diff --git a/src/sorry/make_gif.rb b/src/sorry/make_gif.rb deleted file mode 100644 index c73b3d4..0000000 --- a/src/sorry/make_gif.rb +++ /dev/null @@ -1,97 +0,0 @@ -require 'erb' -require 'digest' -require "thread" - -require_relative './cache.rb' -require_relative './config.rb' - -module Sorry - - $cache = LocalCache.new - - def Sorry.calculate_hash(sentences) - Digest::MD5.hexdigest sentences.to_s - end - - ###################### - - $jobs = 0 - $mutex = Mutex.new - - def Sorry.ffmpeg_avaliable? - $jobs < Config::MAX_JOBS - end - - def Sorry.make_gif_with_ffmpeg(template_name, sentences, filename) - $mutex.lock - $jobs += 1 - $mutex.unlock - - ass_path = render_ass(template_name, sentences, filename) - gif_path = Config::TEMP_FOLDER + filename - video_path = Config::TEMPLATE_FOLDER + template_name + "/template.mp4" - - cmd = <<-CMD - ffmpeg \ - -i #{video_path} \ - -r 8 \ - -vf ass=#{ass_path},scale=300:-1 \ - -y \ - #{gif_path} - CMD - - pid = spawn(cmd, [:out, :err]=>"/dev/null") - Process.wait pid - - $mutex.lock - $jobs -= 1 - $mutex.unlock - puts "[ Current jobs ] #{$jobs}" - - gif_path - end - - ################################ - - def Sorry.ass_text(template_name) - File.read( - Config::TEMPLATE_FOLDER + template_name + "/template.erb" - ) - end - - def Sorry.render_ass(template_name, sentences, filename) - output_file_path = Config::TEMP_FOLDER + filename + ".ass" - - rendered_ass_text = - ERB.new(ass_text(template_name)) - .result(binding) - - File.write(output_file_path, rendered_ass_text) - - output_file_path - end - - def render_gif(template_name, sentences) - filename = calculate_hash(sentences) + ".gif" - - if !$cache.file_exists?(filename) - if ffmpeg_avaliable? - path = make_gif_with_ffmpeg(template_name, sentences, filename) - $cache.add_file(path) - File.delete(path) - else - return <<-HTML -

服务器忙!等下说不定就能用了⏳

- HTML - end - end - - <<-HTML -

点击下载

- HTML - end - - - - module_function :render_gif -end diff --git a/templates/wangjingze/template.mp4 b/templates/wangjingze/template.mp4 deleted file mode 100644 index e5f46f2..0000000 Binary files a/templates/wangjingze/template.mp4 and /dev/null differ