Skip to content

๐Ÿ“ฝ๏ธ NicoNicoDouga Comments Translator - Make Nico Great Again ๐Ÿ˜บ

Notifications You must be signed in to change notification settings

sarguments/NicoTrans

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

nicoTrans

contributed by larry, gram

saru_key

settings

<Google Cloud Translate auth>
export GOOGLE_APPLICATION_CREDENTIALS ...


<API key>
GOOGLE_API_KEY ...


<Nginx config>
/usr/local/etc/nginx/nginx.conf - MAC
/etc/nginx/nginx.conf - LINUX

server {
    listen 80;
    server_name localhost;
    location / {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://127.0.0.1:9090;
    }
}

server {
    listen 443 ssl;
    server_name localhost;
    ssl_certificate ํŒŒ์ผ๊ฒฝ๋กœ.crt;
    ssl_certificate_key /etc/ssl/private/nmsg.nicovideo.jp.key; (์˜ˆ์‹œ)
    location / {
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   Host      $http_host;
    proxy_pass         http://127.0.0.1:9090;
    }
}

์ฐธ๊ณ  : https://zetawiki.com/wiki/%EB%A6%AC%EB%88%85%EC%8A%A4_%EC%9E%90%EC%B2%B4%EC%84%9C%EB%AA%85_SSL_%EC%9D%B8%EC%A6%9D%EC%84%9C_%EC%83%9D%EC%84%B1

<Host config>
/etc/hosts
127.0.0.1   nmsg๋‹ทnicovideo๋‹ทjp
202๋‹ท248๋‹ท252๋‹ท234 pobi.god

์›๋ž˜ ์ž‘๋™ ์ˆœ์„œ

  1. http://nicovideo.jp/watch/sm5361236 ์™€ ๊ฐ™์ด ๋™์˜์ƒ ์ฃผ์†Œ๋กœ ์ ‘์†์„ ํ•œ๋‹ค.
  2. ์›น ํŽ˜์ด์ง€๊ฐ€ 1์ฐจ์ ์œผ๋กœ ๋กœ๋”ฉ์ด ๋˜๊ณ  ๋‹ค์‹œ ๋ธŒ๋ผ์šฐ์ €์—์„œ post ์š”์ฒญ์ด ์ฝ”๋ฉ˜ํŠธ ์„œ๋ฒ„์ธ nmsg.nicovideo.jp/api.json ์œผ๋กœ ๊ฐ„๋‹ค.
  3. ์ฝ”๋ฉ˜ํŠธ ์„œ๋ฒ„์—์„œ ํ•ด๋‹น ๋™์˜์ƒ์— ๋งž๋Š” ์ฝ”๋ฉ˜ํŠธ๋ฅผ json์œผ๋กœ ๋ฆฌํ„ดํ•œ๋‹ค.
  4. ๋ธŒ๋ผ์šฐ์ €๋Š” ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋ฐ›์•„์„œ ์›น๋ธŒ๋ผ์šฐ์ €์˜ ๋™์˜์ƒ ์œ„์— ๋ Œ๋”๋ง ํ•œ๋‹ค.

์ฝ”๋ฉ˜ํŠธ์˜ ๊ฒฝ์šฐ ์‹ค์ œ๋กœ ํ•˜๋‚˜ํ•˜๋‚˜๊ฐ€ ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ „์†ก๋˜๋Š” ๊ฒƒ์€ ์•„๋‹ˆ๊ณ  ์ „์ฒด ๋ฐ์ดํ„ฐ๊ฐ€ ํ•œ๊บผ๋ฒˆ์— ์˜จ๋‹ค. ๋™์˜์ƒ ์žฌ์ƒ ์ค‘ ์œ ์ €๊ฐ€ ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋‚จ๊ธฐ๋ฉด ๊ทธ ํƒ€์ด๋ฐ์ด ์ €์žฅ๋˜๊ณ  ๋‚˜์ค‘์— ๋‹ค๋ฅธ ์œ ์ €๊ฐ€ ํ•ด๋‹น ๋™์˜์ƒ์„ ์žฌ์ƒํ–ˆ์„๋•Œ ๊ฐ™์€ ํƒ€์ด๋ฐ์— ๋‹ค๋ฅธ ์œ ์ €๊ฐ€ ๋‚จ๊ธด ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

ํ”„๋กœ์ ํŠธ ์ž‘๋™ ์ˆœ์„œ

  1. http://nicovideo.jp/watch/sm5361236 ์™€ ๊ฐ™์ด ๋™์˜์ƒ ์ฃผ์†Œ๋กœ ์ ‘์†์„ ํ•œ๋‹ค.
  2. ์›น ํŽ˜์ด์ง€๊ฐ€ 1์ฐจ์ ์œผ๋กœ ๋กœ๋”ฉ์ด ๋˜๊ณ  ๋‹ค์‹œ ๋ธŒ๋ผ์šฐ์ €์—์„œ post ์š”์ฒญ์ด ์ฝ”๋ฉ˜ํŠธ ์„œ๋ฒ„์ธ nmsg.nicovideo.jp/api.json ์œผ๋กœ ๊ฐ„๋‹ค.
  3. nmsg.nicovideo.jp/Api.json ๋กœ์˜ ์š”์ฒญ์ด host ์„ค์ •์— ์˜ํ•ด localhost:80 ์œผ๋กœ ๊ฐ„๋‹ค.
  4. Localhost:80 ์œผ๋กœ ๊ฐ„ ์š”์ฒญ์ด nginx์— ์˜ํ•ด ๋‹ค์‹œ localhost:8080์œผ๋กœ ๊ฐ„๋‹ค.
  5. ์Šคํ”„๋ง๋ถ€ํŠธ ์„œ๋ฒ„๊ฐ€ 8080ํฌํŠธ๋กœ์˜ ์š”์ฒญ์„ ๋ฐ›๋Š”๋‹ค.
  6. ์š”์ฒญ์˜ ํ—ค๋”๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ปจํ…ํŠธ ํƒ€์ž…๊ณผ Origin ๋“ฑ์˜ ์ •๋ณด๊ฐ€ ๋‹ด๊ธด ์ผ์ข…์˜ ๋ณต์ œ๋œ ํ—ค๋” ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์›๋ž˜ ์š”์ฒญ์˜ ๋ฐ”๋””๋ฅผ ํ•ฉ์ณ HttpEntity ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑํ•œ๋‹ค.
  7. ์ƒ์„ฑํ•œ ์ธ์Šคํ„ด์Šค๋กœ http://pobi.god/api.json์— ์š”์ฒญ์„ ๋ณด๋‚ด์„œ json ๊ฐ์ฒด๋ฅผ ์Šคํ”„๋ง๋ถ€ํŠธ ์„œ๋ฒ„๋กœ ๋ฐ›์•„์˜จ๋‹ค. ( ์—ฌ๊ธฐ์„œ https ๋•Œ๋ฌธ์— ๋ฌธ์ œ ๋ฐœ์ƒ )
    • ์›๋ž˜ ์ฝ”๋ฉ˜ํŠธ ์„œ๋ฒ„์˜ url๋กœ ๋ณด๋‚ด๋Š”๊ฒŒ ์•„๋‹Œ http://pobi.god/api.json ๋กœ ๋ณด๋‚ด๋Š” ์ด์œ ๋Š” ์ด์ „์— host ์„ค์ •์— ์˜ํ•ด ๋‹ค์‹œ localhost:80์œผ๋กœ ์ด๋™ํ•˜๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค. host์„ค์ •์— ๋ณ„๋„๋กœ http://pobi.god/api.json ์„ 202.248.252.234 ์œผ๋กœ ๊ฐ€๋„๋ก ์„ค์ •ํ•ด ๋‘์—ˆ๋‹ค.
    • ๋ฐ›์•„์˜ฌ๋•Œ ์•„ํŒŒ์น˜์˜ http ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด์„œ gzip์œผ๋กœ ์••์ถ•๋œ json ํŒŒ์ผ์„ ๋ฐ›๋Š”๋‹ค.
  8. ๋ฐ›์€ json์„ List ํ˜•์œผ๋กœ ์—ญ ์ง๋ ฌํ™” ํ•œ๋‹ค. Item์€ HashMap<String, Contents>์„ ํ™•์žฅํ•œ ๊ฐ์ฒด์ด๋‹ค.
  9. List์—์„œ Item์˜ key๊ฐ€ โ€˜contentโ€™ ์ธ value์— ํ•ด๋‹นํ•˜๋Š” Content ์ธ์Šคํ„ด์Šค๋ฅผ ์ฐพ๋Š”๋‹ค. Contents๋Š” HashMap<String, Object>์„ ํ™•์žฅํ•œ ๊ฐ์ฒด์ด๋‹ค.
  10. ์ฐพ์€ Content ์•ˆ์—์„œ ๋‹ค์‹œ key๊ฐ€ โ€˜contentโ€™์ธ ์š”์†Œ๋ฅผ ์ฐพ์•„์„œ ํ•ด๋‹น ์š”์†Œ์˜ ๋ ˆํผ๋Ÿฐ์Šค์™€ value์ธ ๋ฒˆ์—ญํ•  ํ…์ŠคํŠธ๋ฅผ Pairํด๋ž˜์Šค์˜ ์ƒˆ๋กœ์šด ์ธ์Šคํ„ด์Šค๋กœ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  11. ๊ทธ๋ฆฌ๊ณ  ์ด๋ ‡๊ฒŒ ์ƒ์„ฑ๋œ Pair ์ธ์Šคํ„ด์Šค๋“ค์„ ๋ชจ์•„์„œ List๋กœ ๋‹ค์‹œ ๋ฐ˜ํ™˜ํ•œ๋‹ค.
  12. List์—์„œ ๋ฒˆ์—ญํ•  ํ…์ŠคํŠธ๋งŒ ๋”ฐ๋กœ ๋ฆฌ์ŠคํŠธ๋กœ ์ถ”์ถœํ•ด์„œ ๋ฒˆ์—ญํ•œ๋‹ค.
    • ์ด๋•Œ ๋ฒˆ์—ญ์„ ํ•œ๊บผ๋ฒˆ์— ํ•  ๊ฒฝ์šฐ ๋ฒˆ์—ญ์ด ๋˜์ง€ ์•Š๋Š”๋‹ค. ๋”ฐ๋ผ์„œ GUAVA๋ฅผ ํ™œ์šฉํ•ด 100๊ฐœ ๋‹จ์œ„์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๋‚˜๋ˆˆ ํ›„ ๋‚˜๋ˆ ์ง„ ๋ฆฌ์ŠคํŠธ๋ฅผ ์ŠคํŠธ๋ฆผ์œผ๋กœ ๊ฐ๊ฐ ๋ฒˆ์—ญํ›„ ๋‹ค์‹œ ํ•ฉ์ณ์„œ ํ•˜๋‚˜์˜ ๋ฆฌ์ŠคํŠธ๋กœ ๋ฆฌํ„ดํ•œ๋‹ค.
  13. List๋ฅผ ๋Œ๋ฉด์„œ Pair์—์„œ Content์˜ ๋ ˆํผ๋Ÿฐ์Šค๋ฅผ ์ด์šฉํ•ด์„œ ์›๋ž˜ Content์˜ ์ฝ”๋ฉ˜ํŠธ ๋ถ€๋ถ„์„ ๋ฒˆ์—ญํ•œ ์ฝ”๋ฉ˜ํŠธ๋กœ ๊ต์ฒดํ•œ๋‹ค.
  14. ๋ฒˆ์—ญ์ด ์™„๋ฃŒ๋œ List์„ json์œผ๋กœ ๋ณ€ํ™˜ํ•ด ๋ฆฌํ„ดํ•œ๋‹ค. ๋ฆฌํ„ด๋œ json์€ ๋ธŒ๋ผ์šฐ์ €๋กœ ๊ฐ„๋‹ค.
  15. ๋ธŒ๋ผ์šฐ์ €๋Š” ์ฝ”๋ฉ˜ํŠธ๋ฅผ ๋ฐ›์•„์„œ ์›น๋ธŒ๋ผ์šฐ์ €์˜ ๋™์˜์ƒ ์œ„์— ๋ Œ๋”๋ง ํ•œ๋‹ค.

Releases

No releases published

Packages

No packages published

Languages