Skip to content

Commit be2ff79

Browse files
Base should override the output (GH-66)
The `PyAV` installation issue causing on Windows has been moved to #67
2 parents 427c952 + c373977 commit be2ff79

File tree

8 files changed

+112
-15
lines changed

8 files changed

+112
-15
lines changed

setup.cfg

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ url = https://github.com/pysnippet/thumbnails
1010
keywords =
1111
vtt
1212
json
13+
thumbnail
14+
generator
1315
thumbnails
1416
thumbnail-generator
1517
license = Apache 2.0
@@ -29,8 +31,8 @@ classifiers =
2931
packages =
3032
thumbnails
3133
install_requires =
32-
av==8.0.0;python_version=='3.7'
33-
av==9.2.0;python_version>'3.7'
34+
av==8.0.0;sys_platform=='win32'
35+
av==9.2.0;sys_platform!='win32'
3436
click>=8.0.3
3537
imageio-ffmpeg>=0.4.7
3638
imageio>=2.23.0

src/thumbnails/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from .thumbnail import ThumbnailVTT
2323
from .thumbnail import register_thumbnail
2424

25-
__version__ = "0.1.9"
25+
__version__ = "0.1.10"
2626
__all__ = (
2727
"Generator",
2828
"Thumbnail",

src/thumbnails/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
DEFAULT_BASE = ""
1+
DEFAULT_BASE = None
22
DEFAULT_SKIP = False
33
DEFAULT_OUTPUT = None
44
DEFAULT_FORMAT = "vtt"

src/thumbnails/thumbnail.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def format_time(secs):
119119
return ("0%s.000" % delta)[:12]
120120

121121
metadata = ["WEBVTT\n\n"]
122-
prefix = self.base or os.path.relpath(self.thumbnail_dir)
122+
prefix = self.base if self.base is not None else os.path.relpath(self.thumbnail_dir)
123123
route = os.path.join(prefix, extract_name(self.filepath) + ".png")
124124
route = pathlib.Path(route).as_posix()
125125

@@ -157,8 +157,8 @@ def generate(self):
157157
with Progress("Saving thumbnail metadata at '%s'" % self.metadata_path):
158158
for frame, start, *_ in self.thumbnails():
159159
frame = os.path.join(self.thumbnail_dir, os.path.basename(frame))
160-
base = os.path.join(self.base, os.path.basename(self.thumbnail_dir))
161-
prefix = base if self.base else os.path.relpath(self.thumbnail_dir)
160+
base = os.path.join(self.base or "", os.path.basename(self.thumbnail_dir))
161+
prefix = base if self.base is not None else os.path.relpath(self.thumbnail_dir)
162162
route = os.path.join(prefix, os.path.basename(frame))
163163
route = pathlib.Path(route).as_posix()
164164
thumbnail_data = {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
{
2+
"0": {
3+
"src": "video/0-00-00.png",
4+
"width": "1280px"
5+
},
6+
"8": {
7+
"src": "video/0-00-08.200000.png",
8+
"width": "1280px"
9+
},
10+
"16": {
11+
"src": "video/0-00-16.400000.png",
12+
"width": "1280px"
13+
},
14+
"24": {
15+
"src": "video/0-00-24.600000.png",
16+
"width": "1280px"
17+
},
18+
"32": {
19+
"src": "video/0-00-32.800000.png",
20+
"width": "1280px"
21+
},
22+
"41": {
23+
"src": "video/0-00-41.png",
24+
"width": "1280px"
25+
},
26+
"49": {
27+
"src": "video/0-00-49.200000.png",
28+
"width": "1280px"
29+
},
30+
"57": {
31+
"src": "video/0-00-57.400000.png",
32+
"width": "1280px"
33+
},
34+
"65": {
35+
"src": "video/0-01-05.600000.png",
36+
"width": "1280px"
37+
},
38+
"73": {
39+
"src": "video/0-01-13.800000.png",
40+
"width": "1280px"
41+
},
42+
"82": {
43+
"src": "video/0-01-22.png",
44+
"width": "1280px"
45+
},
46+
"90": {
47+
"src": "video/0-01-30.200000.png",
48+
"width": "1280px"
49+
},
50+
"98": {
51+
"src": "video/0-01-38.400000.png",
52+
"width": "1280px"
53+
}
54+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
WEBVTT
2+
3+
00:00:00.000 --> 00:00:08.200
4+
video.png#xywh=0,0,1280,536
5+
6+
00:00:08.200 --> 00:00:16.400
7+
video.png#xywh=1280,0,1280,536
8+
9+
00:00:16.400 --> 00:00:24.600
10+
video.png#xywh=2560,0,1280,536
11+
12+
00:00:24.600 --> 00:00:32.800
13+
video.png#xywh=0,536,1280,536
14+
15+
00:00:32.800 --> 00:00:41.000
16+
video.png#xywh=1280,536,1280,536
17+
18+
00:00:41.000 --> 00:00:49.200
19+
video.png#xywh=2560,536,1280,536
20+
21+
00:00:49.200 --> 00:00:57.400
22+
video.png#xywh=0,1072,1280,536
23+
24+
00:00:57.400 --> 00:01:05.600
25+
video.png#xywh=1280,1072,1280,536
26+
27+
00:01:05.600 --> 00:01:13.800
28+
video.png#xywh=2560,1072,1280,536
29+
30+
00:01:13.800 --> 00:01:22.000
31+
video.png#xywh=0,1608,1280,536
32+
33+
00:01:22.000 --> 00:01:30.200
34+
video.png#xywh=1280,1608,1280,536
35+
36+
00:01:30.200 --> 00:01:38.400
37+
video.png#xywh=2560,1608,1280,536
38+
39+
00:01:38.400 --> 00:01:46.600
40+
video.png#xywh=0,2144,1280,536
41+

tests/test_api.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,16 @@ def thumbnail_generation_with_default_output(tmp_media, inputs, fmt):
3232
ogv_result.close()
3333

3434

35-
def thumbnail_generation_with_with_extras(tmp_media, inputs, fmt):
35+
def thumbnail_generation_with_with_extras(tmp_media, inputs, fmt, base, snapshot_file):
3636
generator = Generator(inputs)
37-
generator.base = "/media/thumbnails/"
37+
generator.base = base
3838
generator.output = os.path.join(tmp_media, "thumbnails")
3939
generator.format = fmt
4040
generator.compress = 0.5
4141
generator.interval = 8.2
4242
generator.generate()
4343

44-
snapshot = open(os.path.join(tmp_media, "snapshots", "specified-base-%s" % fmt))
44+
snapshot = open(os.path.join(tmp_media, "snapshots", snapshot_file + fmt))
4545
result = open(os.path.join(tmp_media, "thumbnails", "video.%s" % fmt))
4646

4747
if fmt == "json":
@@ -64,7 +64,8 @@ def test_api_vtt_generation_file_inputs_default_output(tmp_media):
6464

6565
def test_api_vtt_generation_with_extras(tmp_media):
6666
inputs = (os.path.join(tmp_media, "avi"), os.path.join(tmp_media, "ogv"))
67-
thumbnail_generation_with_with_extras(tmp_media, inputs, "vtt")
67+
thumbnail_generation_with_with_extras(tmp_media, inputs, "vtt", "", "specified-empty-base-")
68+
thumbnail_generation_with_with_extras(tmp_media, inputs, "vtt", "/media/thumbnails/", "specified-base-")
6869

6970

7071
def test_api_json_generation_directory_inputs_default_output(tmp_media):
@@ -79,4 +80,5 @@ def test_api_json_generation_file_inputs_default_output(tmp_media):
7980

8081
def test_api_json_generation_with_extras(tmp_media):
8182
inputs = (os.path.join(tmp_media, "avi"), os.path.join(tmp_media, "ogv"))
82-
thumbnail_generation_with_with_extras(tmp_media, inputs, "json")
83+
thumbnail_generation_with_with_extras(tmp_media, inputs, "json", "", "specified-empty-base-")
84+
thumbnail_generation_with_with_extras(tmp_media, inputs, "json", "/media/thumbnails/", "specified-base-")

tests/test_cli.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44

55
def execute_cli(*args, must_fail=False):
6-
stdout = subprocess.run(("thumbnails", *args), capture_output=True)
7-
assert stdout.returncode == must_fail
8-
return stdout.stdout.decode()
6+
assert subprocess.call(("thumbnails", *args)) == must_fail
97

108

119
def test_cli_help():

0 commit comments

Comments
 (0)