37
37
from http .server import BaseHTTPRequestHandler , HTTPServer
38
38
from socketserver import ThreadingMixIn
39
39
40
- REGEX_THUMBNAIL_URL = re .compile (r"/thumbnails/(?P<file_id>.+?)/(?P<file_frame>\d+)(?P<only_path>/path/)?" )
40
+ # Regex for parsing URLs: (examples)
41
+ # http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path/no-cache/
42
+ # http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path/
43
+ # http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/path
44
+ # http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1/
45
+ # http://127.0.0.1:33723/thumbnails/9ATJTBQ71V/1
46
+ REGEX_THUMBNAIL_URL = re .compile (r"/thumbnails/(?P<file_id>.+?)/(?P<file_frame>\d+)/*(?P<only_path>path)?/*(?P<no_cache>no-cache)?" )
41
47
42
48
43
49
def GenerateThumbnail (file_path , thumb_path , thumbnail_frame , width , height , mask , overlay ):
@@ -124,10 +130,12 @@ def do_GET(self):
124
130
""" Process each GET request and return a value (image or file path)"""
125
131
# Parse URL
126
132
url_output = REGEX_THUMBNAIL_URL .match (self .path )
127
- if url_output and len (url_output .groups ()) == 3 :
133
+ if url_output and len (url_output .groups ()) == 4 :
128
134
# Path is expected to have 3 matched components (third is optional though)
129
135
# /thumbnails/FILE-ID/FRAME-NUMBER/ or
130
- # /thumbnails/FILE-ID/FRAME-NUMBER/path/
136
+ # /thumbnails/FILE-ID/FRAME-NUMBER/path/ or
137
+ # /thumbnails/FILE-ID/FRAME-NUMBER/no-cache/ or
138
+ # /thumbnails/FILE-ID/FRAME-NUMBER/path/no-cache/
131
139
self .send_response_only (200 )
132
140
else :
133
141
self .send_error (404 )
@@ -137,6 +145,7 @@ def do_GET(self):
137
145
file_id = url_output .group ('file_id' )
138
146
file_frame = int (url_output .group ('file_frame' ))
139
147
only_path = url_output .group ('only_path' )
148
+ no_cache = url_output .group ('no_cache' )
140
149
141
150
try :
142
151
# Look up file data
@@ -165,7 +174,7 @@ def do_GET(self):
165
174
# Try with ID and frame # in filename (for backwards compatibility)
166
175
thumb_path = os .path .join (info .THUMBNAIL_PATH , "%s-%s.png" % (file_id , file_frame ))
167
176
168
- if not os .path .exists (thumb_path ):
177
+ if not os .path .exists (thumb_path ) or no_cache :
169
178
# Generate thumbnail (since we can't find it)
170
179
171
180
# Determine if video overlay should be applied to thumbnail
0 commit comments