##// END OF EJS Templates
Video formats are not limited to webm
neko259 -
r1307:ba607abe default
parent child Browse files
Show More
@@ -1,67 +1,70 b''
1 from django.template.defaultfilters import filesizeformat
1 from django.template.defaultfilters import filesizeformat
2 from django.contrib.staticfiles.templatetags.staticfiles import static
2 from django.contrib.staticfiles.templatetags.staticfiles import static
3
3
4 FILE_STUB_IMAGE = 'images/file.png'
4 FILE_STUB_IMAGE = 'images/file.png'
5
5
6 FILE_TYPE_WEBM = 'webm'
6 FILE_TYPES_VIDEO = (
7 'webm',
8 'mp4',
9 )
7 FILE_TYPE_SVG = 'svg'
10 FILE_TYPE_SVG = 'svg'
8 FILE_TYPES_AUDIO = (
11 FILE_TYPES_AUDIO = (
9 'ogg',
12 'ogg',
10 'mp3',
13 'mp3',
11 )
14 )
12
15
13
16
14 def get_viewers():
17 def get_viewers():
15 return AbstractViewer.__subclasses__()
18 return AbstractViewer.__subclasses__()
16
19
17
20
18 class AbstractViewer:
21 class AbstractViewer:
19 def __init__(self, file, file_type):
22 def __init__(self, file, file_type):
20 self.file = file
23 self.file = file
21 self.file_type = file_type
24 self.file_type = file_type
22
25
23 @staticmethod
26 @staticmethod
24 def supports(file_type):
27 def supports(file_type):
25 return True
28 return True
26
29
27 def get_view(self):
30 def get_view(self):
28 return '<div class="image">'\
31 return '<div class="image">'\
29 '{}'\
32 '{}'\
30 '<div class="image-metadata">{}, {}</div>'\
33 '<div class="image-metadata">{}, {}</div>'\
31 '</div>'.format(self.get_format_view(),
34 '</div>'.format(self.get_format_view(),
32 self.file_type, filesizeformat(self.file.size))
35 self.file_type, filesizeformat(self.file.size))
33
36
34 def get_format_view(self):
37 def get_format_view(self):
35 return '<a href="{}">'\
38 return '<a href="{}">'\
36 '<img src="{}" width="200" height="150"/>'\
39 '<img src="{}" width="200" height="150"/>'\
37 '</a>'.format(self.file.url,static(FILE_STUB_IMAGE))
40 '</a>'.format(self.file.url,static(FILE_STUB_IMAGE))
38
41
39
42
40 class WebmViewer(AbstractViewer):
43 class VideoViewer(AbstractViewer):
41 @staticmethod
44 @staticmethod
42 def supports(file_type):
45 def supports(file_type):
43 return file_type == FILE_TYPE_WEBM
46 return file_type in FILE_TYPES_VIDEO
44
47
45 def get_format_view(self):
48 def get_format_view(self):
46 return '<video width="200" height="150" controls src="{}"></video>'\
49 return '<video width="200" height="150" controls src="{}"></video>'\
47 .format(self.file.url)
50 .format(self.file.url)
48
51
49
52
50 class AudioViewer(AbstractViewer):
53 class AudioViewer(AbstractViewer):
51 @staticmethod
54 @staticmethod
52 def supports(file_type):
55 def supports(file_type):
53 return file_type in FILE_TYPES_AUDIO
56 return file_type in FILE_TYPES_AUDIO
54
57
55 def get_format_view(self):
58 def get_format_view(self):
56 return '<audio controls src="{}"></audio>'.format(self.file.url)
59 return '<audio controls src="{}"></audio>'.format(self.file.url)
57
60
58
61
59 class SvgViewer(AbstractViewer):
62 class SvgViewer(AbstractViewer):
60 @staticmethod
63 @staticmethod
61 def supports(file_type):
64 def supports(file_type):
62 return file_type == FILE_TYPE_SVG
65 return file_type == FILE_TYPE_SVG
63
66
64 def get_format_view(self):
67 def get_format_view(self):
65 return '<a class="thumb" href="{}">'\
68 return '<a class="thumb" href="{}">'\
66 '<img class="post-image-preview" width="200" height="150" src="{}" />'\
69 '<img class="post-image-preview" width="200" height="150" src="{}" />'\
67 '</a>'.format(self.file.url, self.file.url)
70 '</a>'.format(self.file.url, self.file.url)
General Comments 0
You need to be logged in to leave comments. Login now