Skip to content

Commit 0b5b354

Browse files
committed
feat: dlna server support
1 parent 3d13d52 commit 0b5b354

22 files changed

+2394
-6
lines changed

cmd/server.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ the address is defined in config file`,
157157
}()
158158
}
159159
}
160+
if conf.Conf.DLNA.Listen != "" && conf.Conf.DLNA.Enable {
161+
go func() {
162+
err := server.StartDlnaServer()
163+
if err != nil {
164+
utils.Log.Fatalf("failed to start dlna server: %s", err.Error())
165+
}
166+
}()
167+
}
160168
// Wait for interrupt signal to gracefully shutdown the server with
161169
// a timeout of 1 second.
162170
quit := make(chan os.Signal, 1)

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ require (
1212
github.com/Xhofe/go-cache v0.0.0-20240804043513-b1a71927bc21
1313
github.com/Xhofe/rateg v0.0.0-20230728072201-251a4e1adad4
1414
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
15+
github.com/anacrolix/dms v1.7.1
16+
github.com/anacrolix/log v0.16.0
1517
github.com/avast/retry-go v3.0.0+incompatible
1618
github.com/aws/aws-sdk-go v1.55.5
1719
github.com/blevesearch/bleve/v2 v2.4.2
@@ -82,6 +84,7 @@ require (
8284
require (
8385
cloud.google.com/go/compute/metadata v0.7.0 // indirect
8486
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
87+
github.com/anacrolix/generics v0.0.1 // indirect
8588
github.com/google/go-cmp v0.7.0 // indirect
8689
github.com/minio/xxml v0.0.3 // indirect
8790
)

go.sum

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ github.com/aead/ecdh v0.2.0 h1:pYop54xVaq/CEREFEcukHRZfTdjiWvYIsZDXXrBapQQ=
5858
github.com/aead/ecdh v0.2.0/go.mod h1:a9HHtXuSo8J1Js1MwLQx2mBhkXMT6YwUmVVEY4tTB8U=
5959
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
6060
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
61+
github.com/anacrolix/dms v1.7.1 h1:XVOpT3eoO5Ds34B1X+TE3R2ApfqGGeqotEoCVNP8BaI=
62+
github.com/anacrolix/dms v1.7.1/go.mod h1:excFJW5MKBhn5yt5ZMyeE9iFVqnO6tEGQl7YG/2tUoQ=
63+
github.com/anacrolix/generics v0.0.1 h1:4WVhK6iLb3UAAAQP6I3uYlMOHcp9FqJC9j4n81Wv9Ks=
64+
github.com/anacrolix/generics v0.0.1/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
65+
github.com/anacrolix/log v0.16.0 h1:DSuyb5kAJwl3Y0X1TRcStVrTS9ST9b0BHW+7neE4Xho=
66+
github.com/anacrolix/log v0.16.0/go.mod h1:m0poRtlr41mriZlXBQ9SOVZ8yZBkLjOkDhd5Li5pITA=
6167
github.com/andreburgaud/crypt2go v1.8.0 h1:J73vGTb1P6XL69SSuumbKs0DWn3ulbl9L92ZXBjw6pc=
6268
github.com/andreburgaud/crypt2go v1.8.0/go.mod h1:L5nfShQ91W78hOWhUH2tlGRPO+POAPJAF5fKOLB9SXg=
6369
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
@@ -223,8 +229,6 @@ github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.m
223229
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
224230
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
225231
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
226-
github.com/fclairamb/ftpserverlib v0.26.1-0.20250611192536-99cb646d0bbe h1:7hWzlndXJKF95RsWQ80bZmdPiBhoTIzedrp/VDGons8=
227-
github.com/fclairamb/ftpserverlib v0.26.1-0.20250611192536-99cb646d0bbe/go.mod h1:xaDvN9bHSdKbmM1oXkqpyyYM39S89uR2blbq571Zb00=
228232
github.com/fclairamb/ftpserverlib v0.26.1-0.20250615212502-7accbe1c7aad h1:nX84X0BDMl4qHx03uSdaVN/9mpHMc7f2jODjPLgDkAA=
229233
github.com/fclairamb/ftpserverlib v0.26.1-0.20250615212502-7accbe1c7aad/go.mod h1:xaDvN9bHSdKbmM1oXkqpyyYM39S89uR2blbq571Zb00=
230234
github.com/fclairamb/go-log v0.6.0 h1:1V7BJ75P2PvanLHRyGBBFjncB6d4AgEmu+BPWKbMkaU=
@@ -235,6 +239,8 @@ github.com/foxxorcat/mopan-sdk-go v0.1.6 h1:6J37oI4wMZLj8EPgSCcSTTIbnI5D6RCNW/sr
235239
github.com/foxxorcat/mopan-sdk-go v0.1.6/go.mod h1:UaY6D88yBXWGrcu/PcyLWyL4lzrk5pSxSABPHftOvxs=
236240
github.com/foxxorcat/weiyun-sdk-go v0.1.3 h1:I5c5nfGErhq9DBumyjCVCggRA74jhgriMqRRFu5jeeY=
237241
github.com/foxxorcat/weiyun-sdk-go v0.1.3/go.mod h1:TPxzN0d2PahweUEHlOBWlwZSA+rELSUlGYMWgXRn9ps=
242+
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
243+
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
238244
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
239245
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
240246
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
@@ -608,8 +614,6 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
608614
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
609615
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
610616
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
611-
github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7 h1:Jtcrb09q0AVWe3BGe8qtuuGxNSHWGkTWr43kHTJ+CpA=
612-
github.com/t3rm1n4l/go-mega v0.0.0-20240219080617-d494b6a8ace7/go.mod h1:suDIky6yrK07NnaBadCB4sS0CqFOvUK91lH7CR+JlDA=
613617
github.com/t3rm1n4l/go-mega v0.0.0-20241213151442-a19cff0ec7b5 h1:Sa+sR8aaAMFwxhXWENEnE6ZpqhZ9d7u1RT2722Rw6hc=
614618
github.com/t3rm1n4l/go-mega v0.0.0-20241213151442-a19cff0ec7b5/go.mod h1:UdZiFUFu6e2WjjtjxivwXWcwc1N/8zgbkBR9QNucUOY=
615619
github.com/taruti/bytepool v0.0.0-20160310082835-5e3a9ea56543 h1:6Y51mutOvRGRx6KqyMNo//xk8B8o6zW9/RVmy1VamOs=
@@ -661,8 +665,6 @@ github.com/yuin/goldmark v1.7.8 h1:iERMLn0/QJeHFhxSt3p6PeN9mGnvIKSpG9YYorDMnic=
661665
github.com/yuin/goldmark v1.7.8/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
662666
github.com/yusufpapurcu/wmi v1.2.4 h1:zFUKzehAFReQwLys1b/iSMl+JQGSCSjtVqQn9bBrPo0=
663667
github.com/yusufpapurcu/wmi v1.2.4/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
664-
github.com/zzzhr1990/go-common-entity v0.0.0-20221216044934-fd1c571e3a22 h1:X+lHsNTlbatQ1cErXIbtyrh+3MTWxqQFS+sBP/wpFXo=
665-
github.com/zzzhr1990/go-common-entity v0.0.0-20221216044934-fd1c571e3a22/go.mod h1:1zGRDJd8zlG6P8azG96+uywfh6udYWwhOmUivw+xsuM=
666668
github.com/zzzhr1990/go-common-entity v0.0.0-20250202070650-1a200048f0d3 h1:PSRwrE5QBufPnOjdgIkRs5KBV1Avq3SY8oksj2Z+k3o=
667669
github.com/zzzhr1990/go-common-entity v0.0.0-20250202070650-1a200048f0d3/go.mod h1:CKriYB8bkNgSbYUQF1khSpejKb5IsV6cR7MdaAR7Fc0=
668670
go.etcd.io/bbolt v1.3.8 h1:xs88BrvEv273UsB79e0hcVrlUWmS0a8upikMFhSyAtA=

internal/conf/config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ type SFTP struct {
9494
Listen string `json:"listen" env:"LISTEN"`
9595
}
9696

97+
type DLNA struct {
98+
Enable bool `json:"enable" env:"ENABLE"`
99+
Listen string `json:"listen" env:"LISTEN"`
100+
FriendlyName string `json:"friendly_name" env:"FRIEDNLY_NAME"`
101+
InterfaceNames []string `json:"interface_names" env:"INTERFACE_NAMES"`
102+
AnnounceInterval int `json:"announce_interval" env:"ANNOUNCE_INTERVAL"`
103+
RootDir string `json:"root_dir" env:"ROOT_DIR"`
104+
}
105+
97106
type Config struct {
98107
Force bool `json:"force" env:"FORCE"`
99108
SiteURL string `json:"site_url" env:"SITE_URL"`
@@ -116,6 +125,7 @@ type Config struct {
116125
S3 S3 `json:"s3" envPrefix:"S3_"`
117126
FTP FTP `json:"ftp" envPrefix:"FTP_"`
118127
SFTP SFTP `json:"sftp" envPrefix:"SFTP_"`
128+
DLNA DLNA `json:"dlna" envPrefix:"DLNA_"`
119129
LastLaunchedVersion string `json:"last_launched_version"`
120130
}
121131

@@ -218,6 +228,14 @@ func DefaultConfig() *Config {
218228
Enable: false,
219229
Listen: ":5222",
220230
},
231+
DLNA: DLNA{
232+
Enable: false,
233+
Listen: ":5200",
234+
FriendlyName: "",
235+
InterfaceNames: []string{},
236+
AnnounceInterval: 12,
237+
RootDir: "/",
238+
},
221239
LastLaunchedVersion: "",
222240
}
223241
}

server/dlna.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package server
2+
3+
import (
4+
"time"
5+
6+
"github.com/OpenListTeam/OpenList/internal/conf"
7+
"github.com/OpenListTeam/OpenList/server/dlna"
8+
"github.com/OpenListTeam/OpenList/server/dlna/dlnaflags"
9+
)
10+
11+
func StartDlnaServer() error {
12+
err := dlna.Run(&dlnaflags.Options{
13+
ListenAddr: conf.Conf.DLNA.Listen,
14+
FriendlyName: conf.Conf.DLNA.FriendlyName,
15+
LogTrace: false,
16+
InterfaceNames: conf.Conf.DLNA.InterfaceNames,
17+
AnnounceInterval: time.Duration(conf.Conf.DLNA.AnnounceInterval) * time.Minute,
18+
RootDir: conf.Conf.DLNA.RootDir,
19+
})
20+
if err != nil {
21+
return err
22+
}
23+
return nil
24+
}

server/dlna/LICENSE.anacrolix

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This directory contains code derived from https://github.com/anacrolix/dms
2+
which is under the following license.
3+
4+
Copyright (c) 2012, Matt Joiner <[email protected]>.
5+
All rights reserved.
6+
7+
Redistribution and use in source and binary forms, with or without
8+
modification, are permitted provided that the following conditions are met:
9+
* Redistributions of source code must retain the above copyright
10+
notice, this list of conditions and the following disclaimer.
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in the
13+
documentation and/or other materials provided with the distribution.
14+
* Neither the name of the <organization> nor the
15+
names of its contributors may be used to endorse or promote products
16+
derived from this software without specific prior written permission.
17+
18+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21+
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
22+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

0 commit comments

Comments
 (0)