Skip to content

Commit

Permalink
Updated README and FAQ
Browse files Browse the repository at this point in the history
  • Loading branch information
midstar committed Jan 7, 2020
1 parent 815c480 commit e6699ce
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 41 deletions.
2 changes: 1 addition & 1 deletion FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ This can be fixed by automatically resizing the images on the server side by ena

enablepreview = on

It will take some time for the server to resize the image, but once the image has been resized, it will be cached in the same location as the thumbnails. Next time the image is viewed it will be blazing fast.
It will take some time for the server to resize the image, but once the image has been resized, it will be cached in the same location as the thumbnails. Next time the image is viewed it will be blazing fast. You can also configure MediaWEB to resize the images on startup with *genpreviewonstartup* configuration parameter.

The size of the preview images is set with the previewmaxside configuration parameter. To limit the height and width to 1000 pixels, set:

Expand Down
53 changes: 51 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ No additional stuff, such as dockers and similar is required.

MediaWEB is well suited to run on small platforms such as Raspberry Pi, Banana Pi, ROCK64 and similar. It is still very fast and can be used with advantage on PC:s running Windows, Linux or Mac OS.

## Content

- [Screenshots](#screenshots)
- [Features](#features)
- [Download and install Linux](#download-and-install-linux)
- [Download and install on Windows (64bit)](#download-and-install-on-windows-(64bit))
- [Build from source (any platform)](#build-from-source-(any-platform))
- [Configuration guide](#configuration-guide)
- [Future improvements](#future-improvements)
- [Author and license](#author-and-license)
- [FAQ](FAQ.md)

## Screenshots

Browse your media:
Expand Down Expand Up @@ -90,7 +102,7 @@ To uninstall MediaWEB run:
cd ~/mediaweb
sudo sh service.sh uninstall

Also, checkout the [FAQ](FAQ.md).
Also, checkout the [Configuration guide](#configuration-guide) and [FAQ](FAQ.md).

## Download and install on Windows (64bit)

Expand All @@ -103,7 +115,7 @@ service in task manager.

You need to install [ffmpeg](https://www.ffmpeg.org/) separately and put ffmpeg into your PATH to get video thumbnail support.

Also, checkout the [FAQ](FAQ.md).
Also, checkout the [Configuration guide](#configuration-guide) and [FAQ](FAQ.md).

## Build from source (any platform)

Expand Down Expand Up @@ -139,6 +151,43 @@ On Linux platforms execute following to install MediaWEB as a service:
sudo sh scripts/service.sh install


## Configuration guide

See [mediaweb.conf](mediaweb.conf) for the available configuration parameters.

The most important configuration parameter is *mediapath* which points out the
directory of your media.

Your might also want to change the *port* configuration parameter.

### Increase performance with preview / resized images

By default the server will provide the full images to the client (WEB browser).
This is generally not an issue if you view your images over your home network, but
over Internet or a mobile network it might take very long time to load the images.
Also, since the images are large, the user interface might feel slow and unresponsive
particulary in mobile web browsers.

To fix these issues, at the cost of more caching storage space, MediaWEB can reduce the
size / resolution and put the resized images in cache. The resizing procedure will
take quite much time, especially for SBCs. Therefore you should configure MediaWEB
to generate the previews at startup and when new files are added to your media
directory:

enablethumbcache = on
genthumbsonstartup = on
genthumbsonadd = on
enablepreview = on
genpreviewonstartup = on
genpreviewonadd = on

Count with ~300 - 800 KB per image, so you need to secure that the cache folder pointed
out with the *cachepath* has enough disk space.

Also, if you have many images and are running on an SBC it might take very, very long
time the first time the images are resized. Count with several days.


## Future improvements

* Add support for TLS/SSL
Expand Down
2 changes: 1 addition & 1 deletion main_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func mainCommon() *WebAPI {
llog.Info("Build time: %s", applicationBuildTime)
llog.Info("Git hash: %s", applicationGitHash)
box := rice.MustFindBox("templates")
media := createMedia(box, s.mediaPath, s.thumbPath,
media := createMedia(box, s.mediaPath, s.cachePath,
s.enableThumbCache, s.genThumbsOnStartup,
s.genThumbsOnAdd, s.autoRotate, s.enablePreview, s.previewMaxSide,
s.genPreviewOnStartup, s.genPreviewOnAdd)
Expand Down
25 changes: 13 additions & 12 deletions media.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ var vidExtensions = [...]string{".avi", ".mov", ".vid", ".mkv", ".mp4"}
// Media represents the media including its base path
type Media struct {
mediaPath string // Top level path for media files
thumbPath string // Top level path for thumbnails
cachepath string // Top level path for thumbnails
enableThumbCache bool // Generate thumbnails
autoRotate bool // Rotate JPEG files when needed
enablePreview bool // Resize images before provide to client
Expand All @@ -43,27 +43,28 @@ type File struct {

// createMedia creates a new media. If thumb cache is enabled the path is
// created when needed.
func createMedia(box *rice.Box, mediaPath string, thumbPath string, enableThumbCache,
func createMedia(box *rice.Box, mediaPath string, cachepath string, enableThumbCache,
genThumbsOnStartup, genThumbsOnAdd, autoRotate, enablePreview bool,
previewMaxSide int, genPreviewOnStartup, genPreviewOnAdd bool) *Media {
llog.Info("Media path: %s", mediaPath)
if enableThumbCache {
directory := filepath.Dir(thumbPath)
if enableThumbCache || enablePreview{
directory := filepath.Dir(cachepath)
err := os.MkdirAll(directory, os.ModePerm)
if err != nil {
llog.Warn("Unable to create thumbnail cache path %s. Reason: %s", thumbPath, err)
llog.Info("Thumbnail cache will be disabled")
llog.Warn("Unable to create cache path %s. Reason: %s", cachepath, err)
llog.Info("Thumbnail and preview cache will be disabled")
enableThumbCache = false
enablePreview = false
} else {
llog.Info("Thumbnail cache path: %s", thumbPath)
llog.Info("Cache path: %s", cachepath)
}
} else {
llog.Info("Thumbnail cache disabled")
llog.Info("Cache disabled")
}
llog.Info("JPEG auto rotate: %t", autoRotate)
llog.Info("Image preview: %t (max width/height %d px)", enablePreview, previewMaxSide)
media := &Media{mediaPath: filepath.ToSlash(filepath.Clean(mediaPath)),
thumbPath: filepath.ToSlash(filepath.Clean(thumbPath)),
cachepath: filepath.ToSlash(filepath.Clean(cachepath)),
enableThumbCache: enableThumbCache,
autoRotate: autoRotate,
enablePreview: enablePreview,
Expand Down Expand Up @@ -106,14 +107,14 @@ func (m *Media) getFullMediaPath(relativePath string) (string, error) {
// getFullThumbPath returns the full path of the provided path, i.e:
// thumb path + relative path.
func (m *Media) getFullThumbPath(relativePath string) (string, error) {
return m.getFullPath(m.thumbPath, relativePath)
return m.getFullPath(m.cachepath, relativePath)
}

// getFullPreviewPath returns the full path of the provided path, i.e:
// preview path + relative path.
// The preview files shares the same path (cache location) as thumbnails.
func (m *Media) getFullPreviewPath(relativePath string) (string, error) {
return m.getFullPath(m.thumbPath, relativePath)
return m.getFullPath(m.cachepath, relativePath)
}

// getRelativePath returns the relative path from an absolute base
Expand Down Expand Up @@ -466,7 +467,7 @@ func (m *Media) generateThumbnail(relativeFilePath string) (string, error) {
//
// It has following sequence/priority:
// 1. Write embedded EXIF thumbnail if it exist (only JPEG)
// 2. Write a cached thumbnail file exist in thumbPath
// 2. Write a cached thumbnail file exist in cachepath
// 3. Generate a thumbnail to cache and write
// 4. If all above fails return error
func (m *Media) writeThumbnail(w io.Writer, relativeFilePath string) error {
Expand Down
8 changes: 4 additions & 4 deletions mediaweb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ port = 9834
# This parameter is MANADTORY
mediapath = testmedia

# Thumb cache path is by default your operating systems
# temp folder + mediaweb. Uncomment below to set to
# another location. Not used if enablethumbcache = off.
thumbpath = tmpcache
# Cache path is by default your operating systems
# temp folder + mediaweb. Cache path is where
# thumbnails and preview images are stored.
cachepath = tmpcache

# Thumb cache is by default on. Uncomment below to
# disable thumb cache
Expand Down
12 changes: 8 additions & 4 deletions scripts/service.sh
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,18 @@ install_service() {
exit 1
}
echo >> $CONFIG
echo "# Server network port." >> $CONFIG
echo "# This parameter is MANDATORY" >> $CONFIG
echo "port = $PORT" >> $CONFIG
echo >> $CONFIG
echo "# Media path, i.e. where is your media located" >> $CONFIG
echo "# This parameter is MANADTORY" >> $CONFIG
echo "mediapath = $MEDIAPATH" >> $CONFIG
echo >> $CONFIG
echo "# Thumb cache path is by default your operating systems" >> $CONFIG
echo "# temp folder + mediaweb. Uncomment below to set to" >> $CONFIG
echo "# another location. Not used if enablethumbcache = off." >> $CONFIG
echo "#thumbpath =" >> $CONFIG
echo "# Cache path is by default your operating systems" >> $CONFIG
echo "# temp folder + mediaweb. Cache path is where" >> $CONFIG
echo "# thumbnails and preview images are stored." >> $CONFIG
echo "cachepath = tmpcache" >> $CONFIG
echo >> $CONFIG
echo "# Thumbnail cache is on by default" >> $CONFIG
echo "#enablethumbcache = off" >> $CONFIG
Expand Down
12 changes: 8 additions & 4 deletions scripts/windows_installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -171,14 +171,18 @@ Section "${APPLICATION_NAME}" SectionMain
; Create configuration file
FileOpen $4 "$INSTDIR\mediaweb.conf" w

FileWrite $4 "# Server network port.$\r$\n"
FileWrite $4 "# This parameter is MANDATORY$\r$\n"
FileWrite $4 "port = 9834$\r$\n"
FileWrite $4 "$\r$\n"
FileWrite $4 "# Media path, i.e. where is your media located$\r$\n"
FileWrite $4 "# This parameter is MANADTORY$\r$\n"
FileWrite $4 "mediapath = $0$\r$\n"
FileWrite $4 "$\r$\n"
FileWrite $4 "# Thumb cache path is by default your operating systems$\r$\n"
FileWrite $4 "# temp folder + mediaweb. Uncomment below to set to$\r$\n"
FileWrite $4 "# another location. Not used if enablethumbcache = off.$\r$\n"
FileWrite $4 "#thumbpath =$\r$\n"
FileWrite $4 "# Cache path is by default your operating systems$\r$\n"
FileWrite $4 "# temp folder + mediaweb. Cache path is where$\r$\n"
FileWrite $4 "# thumbnails and preview images are stored.$\r$\n"
FileWrite $4 "#cachepath =$\r$\n"
FileWrite $4 "$\r$\n"
FileWrite $4 "# Thumbnail cache is on by default$\r$\n"
FileWrite $4 "#enablethumbcache = off$\r$\n"
Expand Down
22 changes: 14 additions & 8 deletions settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type settings struct {
port int // Network port
mediaPath string // Top level path for media files
thumbPath string // Top level path for thumbnails
cachePath string // Top level path for cache (thumbs and preview)
enableThumbCache bool // Generate thumbnails
genThumbsOnStartup bool // Generate all thumbnails on startup
genThumbsOnAdd bool // Generate thumbnails when file added (start watcher)
Expand Down Expand Up @@ -76,15 +76,21 @@ func loadSettings(fileName string) settings {
mediaPath := config.GetString("mediapath", "")
result.mediaPath = mediaPath

// Load thumbPath (OPTIONAL)
// Load cachePath (OPTIONAL)
// Default: OS temp directory
if config.HasKey("thumbpath") {
thumbPath := config.GetString("thumbpath", "")
result.thumbPath = thumbPath
if config.HasKey("cachepath") {
cachePath := config.GetString("cachepath", "")
result.cachePath = cachePath
} else {
// Use default temporary directory + mediaweb
tempDir := os.TempDir()
result.thumbPath = filepath.Join(tempDir, "mediaweb")
// For backwards compatibility with old versions
if config.HasKey("thumbpath") {
cachePath := config.GetString("thumbpath", "")
result.cachePath = cachePath
} else {
// Use default temporary directory + mediaweb
tempDir := os.TempDir()
result.cachePath = filepath.Join(tempDir, "mediaweb")
}
}

// Load enableThumbCache (OPTIONAL)
Expand Down
32 changes: 27 additions & 5 deletions settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mediapath = Y:\pictures`
assertEqualsStr(t, "mediaPath", "Y:\\pictures", s.mediaPath)

// All default on optional
assertEqualsStr(t, "thumbPath", filepath.Join(os.TempDir(), "mediaweb"), s.thumbPath)
assertEqualsStr(t, "cachePath", filepath.Join(os.TempDir(), "mediaweb"), s.cachePath)
assertEqualsBool(t, "enablethumbCache", true, s.enableThumbCache)
assertEqualsBool(t, "genthumbsonstartup", false, s.genThumbsOnStartup)
assertEqualsBool(t, "genthumbsonadd", true, s.genThumbsOnAdd)
Expand All @@ -43,7 +43,7 @@ func TestSettings(t *testing.T) {
`
port = 80
mediapath = /media/usb/pictures
thumbpath = /tmp/thumb
cachepath = /tmp/thumb
enablethumbcache = off
genthumbsonstartup = on
genthumbsonadd = off
Expand All @@ -65,7 +65,7 @@ password = A!#_q7*+
assertEqualsStr(t, "mediaPath", "/media/usb/pictures", s.mediaPath)

// Check set values on optional
assertEqualsStr(t, "thumbPath", "/tmp/thumb", s.thumbPath)
assertEqualsStr(t, "cachePath", "/tmp/thumb", s.cachePath)
assertEqualsBool(t, "enableThumbCache", false, s.enableThumbCache)
assertEqualsBool(t, "genthumbsonstartup", true, s.genThumbsOnStartup)
assertEqualsBool(t, "genthumbsonadd", false, s.genThumbsOnAdd)
Expand All @@ -86,7 +86,7 @@ func TestSettingsInvalidOptional(t *testing.T) {
`
port = 80
mediapath = /media/usb/pictures
thumbpath = /tmp/thumb
cachepath = /tmp/thumb
enablethumbcache = 33
genthumbsonstartup = -1
genthumbsonadd = 5.5
Expand All @@ -106,7 +106,7 @@ logfile = /tmp/log/mediaweb.log
assertEqualsStr(t, "mediaPath", "/media/usb/pictures", s.mediaPath)

// Check set values on optional
assertEqualsStr(t, "thumbPath", "/tmp/thumb", s.thumbPath)
assertEqualsStr(t, "cachePath", "/tmp/thumb", s.cachePath)
assertEqualsInt(t, "previewmaxside", 1280, s.previewMaxSide)
assertEqualsInt(t, "logLevel", int(llog.LvlDebug), int(s.logLevel))
assertEqualsStr(t, "logFile", "/tmp/log/mediaweb.log", s.logFile)
Expand All @@ -122,6 +122,28 @@ logfile = /tmp/log/mediaweb.log

}


func TestSettingsBackwardsCompatibility(t *testing.T) {
contents :=
`
port = 80
mediapath = /media/usb/pictures
thumbpath = /tmp/thumb
loglevel = debug
logfile = /tmp/log/mediaweb.log
`
fullPath := createConfigFile(t, "TestSettings.conf", contents)
s := loadSettings(fullPath)

// Mandatory values
assertEqualsInt(t, "port", 80, s.port)
assertEqualsStr(t, "mediaPath", "/media/usb/pictures", s.mediaPath)

// Check that cachepath is working with thumbpath
assertEqualsStr(t, "cachePath", "/tmp/thumb", s.cachePath)

}

func expectPanic(t *testing.T) {
// Panic handler (panic is expected)
recover()
Expand Down

0 comments on commit e6699ce

Please sign in to comment.