Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion gallery/file_modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def generate_thumbnail(self):
from gallery.file_modules.ogg import OggFile
from gallery.file_modules.pdf import PDFFile
from gallery.file_modules.txt import TXTFile
from gallery.file_modules.mp3 import MP3File
from gallery.file_modules.wav import WAVFile

file_mimetype_relation = {
"image/jpeg": JPEGFile,
Expand All @@ -77,7 +79,9 @@ def generate_thumbnail(self):
"video/webm": WebMFile,
"video/ogg": OggFile,
"application/pdf": PDFFile,
"text/plain": TXTFile
"text/plain": TXTFile,
"audio/mpeg": MP3File,
"audio/x-wav": WAVFile
}


Expand Down
18 changes: 18 additions & 0 deletions gallery/file_modules/mp3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from wand.image import Image

from gallery.file_modules import FileModule
from gallery.util import hash_file

class MP3File(FileModule):
def __init__(self, file_path, dir_path):
FileModule.__init__(self, file_path, dir_path)
self.mime_type = "audio/mpeg"

self.generate_thumbnail()

def generate_thumbnail(self):
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"

with Image(filename="thumbnails/reedphoto.jpg") as bg:
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))
18 changes: 18 additions & 0 deletions gallery/file_modules/wav.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from wand.image import Image

from gallery.file_modules import FileModule
from gallery.util import hash_file

class WAVFile(FileModule):
def __init__(self, file_path, dir_path):
FileModule.__init__(self, file_path, dir_path)
self.mime_type = "audio/x-wav"

self.generate_thumbnail()

def generate_thumbnail(self):
self.thumbnail_uuid = hash_file(self.file_path) + ".jpg"

with Image(filename="thumbnails/reedphoto.jpg") as bg:
bg.save(filename=os.path.join(self.dir_path, self.thumbnail_uuid))
6 changes: 6 additions & 0 deletions gallery/templates/view_file.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@

{% elif file.mimetype == "application/pdf" or file.mimetype == "text/plain" %}
<embed id="file-content" src="/api/file/get/{{file.id}}">

{% elif file.mimetype.split('/')[0] == "audio" %}
<audio controls>
<source src="/api/file/get/{{file.id}}">
</audio>

{% else %}
Text Data
{% endif %}
Expand Down