Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
c08d052
fix
xtyxtyx Mar 4, 2018
8dbc8ad
emoji
xtyxtyx Mar 4, 2018
ac43c0d
resize image
xtyxtyx Mar 4, 2018
6bf437f
adjust time
xtyxtyx Mar 4, 2018
f6da6c3
add docker support
gengjiawen Mar 6, 2018
1b51a16
Fix issue #8
xtyxtyx Mar 6, 2018
9e2229e
Merge pull request #11 from gengjiawen/master
xtyxtyx Mar 6, 2018
2f18e79
Dockerfile add the crontab
feng409 Mar 8, 2018
e4ac661
Merge pull request #13 from feng409/master
xtyxtyx Mar 9, 2018
b479c6a
add topic
xtyxtyx Mar 9, 2018
b412346
Merge branch 'master' of github.com:xtyxtyx/sorry
xtyxtyx Mar 9, 2018
9f4b9f7
使用国内Gem源
xtyxtyx Mar 9, 2018
7fcdefb
update README.md
xtyxtyx Mar 9, 2018
13b9400
add API
xtyxtyx Mar 9, 2018
cc493e1
update
xtyxtyx Mar 9, 2018
029dfed
兼容旧版index.html
xtyxtyx Mar 10, 2018
d9e0e07
update
xtyxtyx Mar 10, 2018
1f934d4
add deps checker
xtyxtyx Mar 12, 2018
40f34ab
support customizing ffmpeg path
xtyxtyx Mar 13, 2018
600a5dd
init
xtyxtyx Mar 17, 2018
3e30c3c
init
xtyxtyx Mar 18, 2018
ecc0150
update
xtyxtyx Mar 18, 2018
a450ffb
update
xtyxtyx Mar 19, 2018
442bc78
update
xtyxtyx Mar 19, 2018
71ed273
update
xtyxtyx Mar 19, 2018
3c21055
update
xtyxtyx Mar 19, 2018
90051e8
update
xtyxtyx Mar 19, 2018
63a6c14
update
xtyxtyx Mar 19, 2018
ab17bcf
adjust time
xtyxtyx Mar 19, 2018
b7b5b19
fix
xtyxtyx Mar 19, 2018
e353239
update
xtyxtyx Mar 19, 2018
55f6f1f
fix api
xtyxtyx Mar 19, 2018
1e8073f
update
xtyxtyx Mar 20, 2018
a3955f1
adjust time
xtyxtyx Mar 20, 2018
b1ced9b
set encoding to utf-8 so that it can be well used in Docker
nisiyu Mar 21, 2018
7a28578
Merge pull request #27 from nisiyu/master
xtyxtyx Mar 21, 2018
0177613
add new template
xtyxtyx Mar 22, 2018
03a9e32
add
xtyxtyx Mar 22, 2018
3e6bdbb
add
xtyxtyx Mar 22, 2018
39eda48
Merge branch 'master' of github.com:xtyxtyx/sorry
xtyxtyx Mar 22, 2018
1d630c3
rgb
xtyxtyx Mar 22, 2018
bfa3b05
add template marmot
xtyxtyx Mar 23, 2018
1721af6
add template diandongche
xtyxtyx Mar 23, 2018
a04ac81
smaller image size
xtyxtyx Mar 23, 2018
e10de84
smaller size
xtyxtyx Mar 23, 2018
3172a25
update
xtyxtyx Mar 23, 2018
5766f90
update
xtyxtyx Mar 23, 2018
a416066
add template
xtyxtyx Mar 24, 2018
7940f94
update
xtyxtyx Mar 25, 2018
ba8a22c
update
xtyxtyx Mar 25, 2018
42c3b16
update
xtyxtyx Mar 27, 2018
d48a556
update
xtyxtyx Mar 27, 2018
6c8d5b5
add template
xtyxtyx Mar 28, 2018
0965787
add template
xtyxtyx Mar 29, 2018
b2b5e9a
update
xtyxtyx Apr 1, 2018
f04eb76
update
xtyxtyx Apr 2, 2018
c4d5f62
fix
xtyxtyx Apr 5, 2018
0c6e4eb
add alternative api format
xtyxtyx Apr 5, 2018
f794a11
update
xtyxtyx Apr 14, 2018
ba2eb34
Update README
CoXier Apr 24, 2018
66b6027
update
xtyxtyx Apr 28, 2018
ca2aa0e
update
xtyxtyx Apr 28, 2018
a773d98
update
xtyxtyx Apr 28, 2018
c0c7869
update
xtyxtyx Jun 2, 2018
d4f96fc
国内Gem镜像地址失效,更改为新域名
Nov 24, 2018
ce9516d
Merge pull request #88 from yxlix/master
xtyxtyx Apr 3, 2020
1248f96
containerized!
xtyxtyx Apr 3, 2020
600dc7e
Restore images
xtyxtyx Jan 22, 2022
be146fe
Update README.md
xtyxtyx Jan 22, 2022
6833665
add mini program link
CoXier Apr 11, 2023
2bc4afb
Update README.md
CoXier Apr 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
out-0.log
err-0.log
*.gif
*.ass
temp/*.ass
*~
*#

!media/*
150 changes: 123 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/<template_name>/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

# 安装编译依赖
Expand All @@ -47,7 +137,7 @@ APP_ENV=production ruby src/sorry.rb

```

### [可选] 使用PM2监控&自动重启
#### [可选] 使用PM2监控&自动重启

```
npm install pm2 -g
Expand All @@ -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

Expand All @@ -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 按照句子的多少删掉或者增加<input>即可
sorry.mp4 替换成新视频
sorry.erb 替换成新的字幕模板
templates/<template_name>/template.mp4 # 视频模板
templates/<template_name>/template.ass # 字幕模板
public/<template_name>/example.png # 展示图片
views/<template_name>.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` 参考其他模板主页,增减`<input>`的数量即可

然后把文本替换成模板字符串 <%= 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

Expand All @@ -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)
28 changes: 28 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions app/cron-sorry
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10 * * * * find /app/public/cache -name '*.gif' -mmin +700 -exec rm {} \;
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added app/public/dagong/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/diandongche/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes
File renamed without changes.
Binary file added app/public/jinkela/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/public/kongming/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion public/main.js → app/public/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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());
}

Expand Down Expand Up @@ -78,11 +85,13 @@ function save_input() {
function sidebar_open() {
sidebar.style.display = "block";
}

function sidebar_close() {
sidebar.style.display = "none";
}

submit_btn.onclick = submit;
show_sidebar_btn.onclick = sidebar_open;
sidebar_close_btn.onclick = sidebar_close;

restore_input()
Binary file added app/public/marmot/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added app/public/sorry/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
Binary file added app/public/wangjingze/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions app/site_config.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 11 additions & 0 deletions app/sources.list
Original file line number Diff line number Diff line change
@@ -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

46 changes: 46 additions & 0 deletions app/src/serve.rkt
Original file line number Diff line number Diff line change
@@ -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 "<html><body><h1>~a</h1></body></html>" (format-time))
out))

(define (format-time)
(parameterize ([date-display-format 'chinese])
(date->string (current-date))))

(println "Server is running...")
(define stop (serve 1234))
Loading