aboutsummaryrefslogtreecommitdiffstats
path: root/core/entrypoint.sh
blob: 47c4dd1143f214beec62bb78518785483a2699d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env sh

## Config
if [ ! -d "/root/.youtube-local" ]; then
    # make dir
    install -d /root/.youtube-local

    # generate config
    cat > /root/.youtube-local/settings.txt <<- EOF
# 0 - Off
# 1 - On, except video
# 2 - On, including video (see warnings)
route_tor = $ROUTE_TOR

tor_port = $TOR_PORT

tor_control_port = TOR_CONTROL_PORT

port_number = 8080

# This will allow others to connect to your Youtube Local instance as a website.
# For security reasons, enabling this is not recommended.
allow_foreign_addresses = $ALLOW_FOREIGN_ADDRESSES

# 0 - off by default
# 1 - only manually created subtitles on by default
# 2 - enable even if automatically generated is all that's available
subtitles_mode = $SUBTITLES_MODE

# ISO 639 language code: https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
subtitles_language = $SUBTITLES_LANG

# 0 - Related videos disabled
# 1 - Related videos always shown
# 2 - Related videos hidden; shown by clicking a button
related_videos_mode = $RELATED_VIDEOS_MODE

# 0 - Video comments disabled
# 1 - Video comments always shown
# 2 - Video comments hidden; shown by clicking a button
comments_mode = $COMMENTS_MODE

enable_comment_avatars = $ENABLE_COMMENTS_AVATARS

# 0 to sort by top
# 1 to sort by newest
default_comment_sorting = $DEFAULT_COMMENT_SORTING

theater_mode = $THEATER_MODE

default_resolution = $DEFAULT_RESOLUTION

use_video_player = $USE_VIDEO_PLAYER

proxy_images = $PROXY_IMAGES

use_comments_js = $USE_COMMENTS_JS

use_sponsorblock_js = $USE_SPONSORBLOCK_JS

theme = $THEME

font = $FONT

embed_page_mode = $EMBED_PAGE_MODE

autocheck_subscriptions = $AUTOCHECK_SUBSCRIPTIONS

# Developer use to debug 403s
gather_googlevideo_domains = $GATHER_GOOGLEVIDEO_DOMAINS

# Save all responses from youtube for debugging
debugging_save_responses = $DEBUGGING_SAVE_RESPONSES

# Do not change, remove, or comment out this value, or else your settings may be lost or corrupted
settings_version = 3
EOF
fi

if [ "$ROUTE_TOR" = 1 ] || [ "$ROUTE_TOR" = 2 ]; then
  cat > /etc/tor/torrc <<- EOF
Log notice stdout
SocksPort ${TOR_PORT:-9050} # Default: Bind to localhost:9050 for local connections.
MaxCircuitDirtiness ${MAX_CIRCUIT:-300}
CircuitBuildTimeout ${CIRCUIT_TIMEOUT:-300}
ExcludeExitNodes {US}
StrictNodes 1
EOF
  tor -f /etc/tor/torrc --runasdaemon 1

  # check health tor
  while :; do
      checkurl=$(curl --socks5 localhost:9050 -o /dev/null -s -w "%{http_code}\n" "${URL_CHECK:-https://www.youtube.com/results?search_query=rms}")
      if [ "$checkurl" = '502' ] || [ "$checkurl" = '302' ]; then
          pkill tor && tor -f /etc/tor/torrc --runasdaemon 0 2>&1
          pkill python3 && /usr/bin/python3 /srv/app/server.py
      else
          pgrep python3 > /dev/null || exec /usr/bin/python3 /srv/app/server.py
      fi
      sleep 5
  done

else
    exec /usr/bin/python3 /srv/app/server.py
fi