|
10 | 10 | import io
|
11 | 11 | import base64
|
12 | 12 | import slideshowBuilder
|
13 |
| - |
| 13 | +import html |
14 | 14 | app = Flask(__name__)
|
15 | 15 | CORS(app)
|
16 | 16 |
|
|
29 | 29 | "Mozilla/5.0 (compatible; January/1.0; +https://gitlab.insrt.uk/revolt/january)",
|
30 | 30 | "test"]
|
31 | 31 |
|
| 32 | +def message(text): |
| 33 | + return render_template( |
| 34 | + 'message.html', |
| 35 | + message = text, |
| 36 | + appname=config.currentConfig["MAIN"]["appName"]) |
| 37 | + |
32 | 38 | def findApiFormat(videoInfo):
|
33 | 39 | for format in videoInfo['formats']:
|
34 | 40 | if format['format_id'] == 'download_addr-0':
|
@@ -100,16 +106,22 @@ def build_stats_line(videoInfo):
|
100 | 106 | return ""
|
101 | 107 |
|
102 | 108 | def getVideoDataFromCacheOrDl(post_link):
|
103 |
| - cachedItem = cache.getFromCache(post_link) |
104 |
| - if cachedItem != None: |
105 |
| - videoInfo = cachedItem |
106 |
| - else: |
107 |
| - videoInfo = getVideoFromPostURL(post_link) |
108 |
| - cache.addToCache(post_link, videoInfo) |
109 |
| - return videoInfo |
| 109 | + try: |
| 110 | + cachedItem = cache.getFromCache(post_link) |
| 111 | + if cachedItem != None: |
| 112 | + videoInfo = cachedItem |
| 113 | + else: |
| 114 | + videoInfo = getVideoFromPostURL(post_link) |
| 115 | + cache.addToCache(post_link, videoInfo) |
| 116 | + return videoInfo |
| 117 | + except Exception as e: |
| 118 | + print(e) |
| 119 | + return None |
110 | 120 |
|
111 | 121 | def embed_tiktok(post_link):
|
112 | 122 | videoInfo = getVideoDataFromCacheOrDl(post_link)
|
| 123 | + if videoInfo == None: |
| 124 | + return message("Failed to get video data from TikTok") |
113 | 125 | if "slideshowData" not in videoInfo or videoInfo["slideshowData"] == None:
|
114 | 126 | vFormat = findApiFormat(videoInfo)
|
115 | 127 | directURL = vFormat['url']
|
@@ -168,7 +180,10 @@ def embedTiktok(sub_path):
|
168 | 180 | # subdomain can be "vm.vxtiktok.com", "id.vxtiktok.com", "en.vxtiktok.com", etc.
|
169 | 181 | # get main domain from subdomain
|
170 | 182 | subdomain = (request.headers['Host']).split(".")[0]
|
171 |
| - url = f"https://{subdomain}.tiktok.com{request.path}" |
| 183 | + if subdomain != "vxtiktok": |
| 184 | + url = f"https://{subdomain}.tiktok.com{request.path}" |
| 185 | + else: |
| 186 | + url = f"https://tiktok.com{request.path}" |
172 | 187 | # make a request and get the long URL for yt-dlp
|
173 | 188 | r = requests.get(url, allow_redirects=False)
|
174 | 189 | baseURL = r.headers['location']
|
|
0 commit comments