mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-09-19 04:59:01 +00:00
minidlna: Add media directory selection form
The form provides an option to select default directory, user specified directory or samba shares if enabled. The form also checks that the directory exists and is readable by the minidlna user. Tested that changing media directory to a samba share location works. Closes #2084. Signed-off-by: Veiko Aasa <veiko17@disroot.org> Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
parent
430f9c6737
commit
552fabed15
@ -29,6 +29,8 @@ _description = [
|
|||||||
'such as PS3 and Xbox 360) or applications such as totem and Kodi.')
|
'such as PS3 and Xbox 360) or applications such as totem and Kodi.')
|
||||||
]
|
]
|
||||||
|
|
||||||
|
SYSTEM_USER = 'minidlna'
|
||||||
|
|
||||||
|
|
||||||
class MiniDLNAApp(app_module.App):
|
class MiniDLNAApp(app_module.App):
|
||||||
"""Freedombox app managing miniDlna."""
|
"""Freedombox app managing miniDlna."""
|
||||||
|
|||||||
@ -3,20 +3,21 @@
|
|||||||
FreedomBox configuration form for MiniDLNA server.
|
FreedomBox configuration form for MiniDLNA server.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from django import forms
|
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
from plinth.modules.storage.forms import (DirectorySelectForm,
|
||||||
|
DirectoryValidator)
|
||||||
|
|
||||||
class MiniDLNAServerForm(forms.Form):
|
from . import SYSTEM_USER
|
||||||
|
|
||||||
|
|
||||||
|
class MiniDLNAServerForm(DirectorySelectForm):
|
||||||
"""MiniDLNA server configuration form."""
|
"""MiniDLNA server configuration form."""
|
||||||
media_dir = forms.CharField(
|
|
||||||
label=_('Media Files Directory'),
|
def __init__(self, *args, **kw):
|
||||||
help_text=_('Directory that MiniDLNA Server will read for content. All'
|
validator = DirectoryValidator(username=SYSTEM_USER)
|
||||||
' sub-directories of this will be also scanned for media '
|
super().__init__(
|
||||||
'files. '
|
title=_('Media Files Directory'), help_text=_(
|
||||||
'If you change the default ensure that the new directory '
|
'Directory that MiniDLNA Server will read for content. All '
|
||||||
'exists and that is readable from the "minidlna" user. '
|
'sub-directories of this will be also scanned for media files.'
|
||||||
'Any user media directories ("/home/username/") will '
|
), default='/var/lib/minidlna', validator=validator, *args, **kw)
|
||||||
'usually work.'),
|
|
||||||
required=False,
|
|
||||||
)
|
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-or-later
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
||||||
"""Views for the minidlna module."""
|
"""Views for the minidlna module."""
|
||||||
|
|
||||||
import os
|
|
||||||
|
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
@ -21,7 +19,8 @@ class MiniDLNAAppView(AppView):
|
|||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
"""Return initial values of the form."""
|
"""Return initial values of the form."""
|
||||||
initial = super().get_initial()
|
initial = super().get_initial()
|
||||||
initial.update({'media_dir': privileged.get_media_dir()})
|
initial.update({'storage_path': privileged.get_media_dir()})
|
||||||
|
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
@ -29,12 +28,8 @@ class MiniDLNAAppView(AppView):
|
|||||||
old_config = form.initial
|
old_config = form.initial
|
||||||
new_config = form.cleaned_data
|
new_config = form.cleaned_data
|
||||||
|
|
||||||
if old_config['media_dir'].strip() != new_config['media_dir']:
|
if old_config['storage_path'] != new_config['storage_path']:
|
||||||
if os.path.isdir(new_config['media_dir']) is False:
|
privileged.set_media_dir(new_config['storage_path'])
|
||||||
messages.error(self.request,
|
messages.success(self.request, _('Updated media directory'))
|
||||||
_('Specified directory does not exist.'))
|
|
||||||
else:
|
|
||||||
privileged.set_media_dir(new_config['media_dir'])
|
|
||||||
messages.success(self.request, _('Updated media directory'))
|
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user