Skip to content

Commit 3bcdc0d

Browse files
authored
Merge pull request #236 from ShaneIsrael/configure-thumbnail-generation-location
Configure thumbnail generation location
2 parents 16ed9ea + 62fe187 commit 3bcdc0d

File tree

7 files changed

+32
-9
lines changed

7 files changed

+32
-9
lines changed

.env.dev

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export FLASK_APP="app/server/fireshare:create_app()"
22
export FLASK_DEBUG=1
33
export ENVIRONMENT=dev
4+
export THUMBNAIL_VIDEO_LOCATION=50
45
export SECRET_KEY=dev-test-key
56
export DATA_DIRECTORY=$(pwd)/dev_root/dev_data/
67
export VIDEO_DIRECTORY=$(pwd)/dev_root/dev_videos/

.env.prod

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export VIDEO_DIRECTORY=/videos/
44
export PROCESSED_DIRECTORY=/processed/
55
export TEMPLATE_PATH=/app/server/fireshare/templates
66
export ENVIRONMENT=production
7+
export THUMBNAIL_VIDEO_LOCATION=0
78
export ADMIN_PASSWORD=admin
89
export ADMIN_USERNAME=admin

app/client/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fireshare",
3-
"version": "1.2.16",
3+
"version": "1.2.17",
44
"private": true,
55
"dependencies": {
66
"@emotion/react": "^11.9.0",

app/client/src/components/admin/UploadCard.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ const UploadCard = ({ authenticated, feedView = false, publicUpload = false, fet
4646
}
4747
handleAlert({
4848
type: 'success',
49-
message: 'Your upload will be available shortly',
50-
autohideDuration: 2500,
49+
message: 'Your upload will be in a few seconds.',
50+
autohideDuration: 3500,
5151
open: true,
5252
onClose: () => fetchVideos(),
5353
})

app/server/fireshare/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def create_app(init_schedule=False):
6262
raise Exception("DATA_DIRECTORY not found in environment")
6363

6464
app.config['ENVIRONMENT'] = os.getenv('ENVIRONMENT')
65+
app.config['THUMBNAIL_VIDEO_LOCATION'] = int(os.getenv('THUMBNAIL_VIDEO_LOCATION'))
6566
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY', secrets.token_hex(32))
6667
app.config['DATA_DIRECTORY'] = os.getenv('DATA_DIRECTORY')
6768
app.config['VIDEO_DIRECTORY'] = os.getenv('VIDEO_DIRECTORY')

app/server/fireshare/cli.py

+24-6
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,18 @@ def scan_videos(root):
114114
db.session.commit()
115115

116116
@cli.command()
117+
@click.pass_context
117118
@click.option("--path", "-p", help="path to video to scan", required=False)
118-
def scan_video(path):
119+
def scan_video(ctx, path):
119120
with create_app().app_context():
120121
paths = current_app.config['PATHS']
121122
videos_path = paths["video"]
122123
video_links = paths["processed"] / "video_links"
124+
thumbnail_skip = current_app.config['THUMBNAIL_VIDEO_LOCATION'] or 0
125+
if thumbnail_skip > 0 and thumbnail_skip <= 100:
126+
thumbnail_skip = thumbnail_skip / 100
127+
else:
128+
thumbnail_skip = 0
123129

124130
config_file = open(paths["data"] / "config.json")
125131
video_config = json.load(config_file)["app_config"]["video_defaults"]
@@ -169,7 +175,12 @@ def scan_video(path):
169175
logger.info(f"{dst} exists already")
170176
info = VideoInfo(video_id=v.video_id, title=Path(v.path).stem, private=video_config["private"])
171177
db.session.add(info)
172-
178+
db.session.commit()
179+
180+
logger.info("Syncing metadata")
181+
ctx.invoke(sync_metadata, video=video_id)
182+
info = VideoInfo.query.filter(VideoInfo.video_id==video_id).one()
183+
173184
processed_root = Path(current_app.config['PROCESSED_DIRECTORY'])
174185
logger.info(f"Checking for videos with missing posters...")
175186
derived_path = Path(processed_root, "derived", info.video_id)
@@ -180,7 +191,7 @@ def scan_video(path):
180191
if should_create_poster:
181192
if not derived_path.exists():
182193
derived_path.mkdir(parents=True)
183-
poster_time = 0
194+
poster_time = int(info.duration * thumbnail_skip)
184195
util.create_poster(video_path, derived_path / "poster.jpg", poster_time)
185196
else:
186197
logger.debug(f"Skipping creation of poster for video {info.video_id} because it exists at {str(poster_path)}")
@@ -216,10 +227,11 @@ def repair_symlinks():
216227
logger.info(f"{dst} exists already")
217228

218229
@cli.command()
219-
def sync_metadata():
230+
@click.option("--video", "-v", help="The video to sync metadata from", default=None)
231+
def sync_metadata(video):
220232
with create_app().app_context():
221233
paths = current_app.config['PATHS']
222-
videos = VideoInfo.query.filter(VideoInfo.info==None).all()
234+
videos = VideoInfo.query.filter(VideoInfo.video_id==video).all() if video else VideoInfo.query.filter(VideoInfo.info==None).all()
223235
logger.info(f'Found {len(videos):,} videos without metadata')
224236
for v in videos:
225237
vpath = paths["processed"] / "video_links" / str(v.video_id + v.video.extension)
@@ -352,6 +364,12 @@ def bulk_import(ctx, root):
352364
return
353365
util.create_lock(paths["data"])
354366

367+
thumbnail_skip = current_app.config['THUMBNAIL_VIDEO_LOCATION'] or 0
368+
if thumbnail_skip > 0 and thumbnail_skip <= 100:
369+
thumbnail_skip = thumbnail_skip / 100
370+
else:
371+
thumbnail_skip = 0
372+
355373
timing = {}
356374
s = time.time()
357375
ctx.invoke(scan_videos, root=root)
@@ -360,7 +378,7 @@ def bulk_import(ctx, root):
360378
ctx.invoke(sync_metadata)
361379
timing['sync_metadata'] = time.time() - s
362380
s = time.time()
363-
ctx.invoke(create_posters)
381+
ctx.invoke(create_posters, skip=thumbnail_skip)
364382
timing['create_posters'] = time.time() - s
365383

366384
logger.info(f"Finished bulk import. Timing info: {json.dumps(timing)}")

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@ services:
1414
- ADMIN_PASSWORD=admin
1515
- SECRET_KEY=replace_this_with_some_random_string
1616
- MINUTES_BETWEEN_VIDEO_SCANS=5
17+
# The location video thumbnails are generated. A value between 0-100 where 50 would be the frame in the middle of the video file and 0 would be the first frame of the video.
18+
- THUMBNAIL_VIDEO_LOCATION=0
1719
- PUID=1000
1820
- PGID=1000

0 commit comments

Comments
 (0)