Skip to content

Commit 8f22212

Browse files
committed
feat: dlna server support
1 parent e8a1ed6 commit 8f22212

22 files changed

+2400
-1
lines changed

cmd/server.go

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

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ require (
1414
github.com/ProtonMail/go-crypto v1.3.0
1515
github.com/SheltonZhu/115driver v1.1.0
1616
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
17+
github.com/anacrolix/dms v1.7.1
18+
github.com/anacrolix/log v0.16.0
1719
github.com/avast/retry-go v3.0.0+incompatible
1820
github.com/aws/aws-sdk-go v1.55.7
1921
github.com/blevesearch/bleve/v2 v2.5.2
@@ -82,6 +84,7 @@ require (
8284
cloud.google.com/go/compute/metadata v0.7.0 // indirect
8385
github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.1 // indirect
8486
github.com/RoaringBitmap/roaring/v2 v2.4.5 // indirect
87+
github.com/anacrolix/generics v0.0.3 // indirect
8588
github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect
8689
github.com/charmbracelet/x/cellbuf v0.0.13-0.20250311204145-2c3ea96c31dd // indirect
8790
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
@@ -92,9 +95,10 @@ require (
9295
github.com/minio/xxml v0.0.3 // indirect
9396
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
9497
github.com/otiai10/mint v1.6.3 // indirect
95-
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
9698
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
9799
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
100+
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 // indirect
101+
gopkg.in/go-jose/go-jose.v2 v2.6.3 // indirect
98102
)
99103

100104
require (

go.sum

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,14 @@ github.com/aead/ecdh v0.2.0 h1:pYop54xVaq/CEREFEcukHRZfTdjiWvYIsZDXXrBapQQ=
8282
github.com/aead/ecdh v0.2.0/go.mod h1:a9HHtXuSo8J1Js1MwLQx2mBhkXMT6YwUmVVEY4tTB8U=
8383
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
8484
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
85+
github.com/anacrolix/dms v1.7.1 h1:XVOpT3eoO5Ds34B1X+TE3R2ApfqGGeqotEoCVNP8BaI=
86+
github.com/anacrolix/dms v1.7.1/go.mod h1:excFJW5MKBhn5yt5ZMyeE9iFVqnO6tEGQl7YG/2tUoQ=
87+
github.com/anacrolix/generics v0.0.1 h1:4WVhK6iLb3UAAAQP6I3uYlMOHcp9FqJC9j4n81Wv9Ks=
88+
github.com/anacrolix/generics v0.0.1/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
89+
github.com/anacrolix/generics v0.0.3 h1:wMkQgQzq0obSy1tMkxDu7Ife7PsegOBWHDRaSW31EnM=
90+
github.com/anacrolix/generics v0.0.3/go.mod h1:MN3ve08Z3zSV/rTuX/ouI4lNdlfTxgdafQJiLzyNRB8=
91+
github.com/anacrolix/log v0.16.0 h1:DSuyb5kAJwl3Y0X1TRcStVrTS9ST9b0BHW+7neE4Xho=
92+
github.com/anacrolix/log v0.16.0/go.mod h1:m0poRtlr41mriZlXBQ9SOVZ8yZBkLjOkDhd5Li5pITA=
8593
github.com/andreburgaud/crypt2go v1.8.0 h1:J73vGTb1P6XL69SSuumbKs0DWn3ulbl9L92ZXBjw6pc=
8694
github.com/andreburgaud/crypt2go v1.8.0/go.mod h1:L5nfShQ91W78hOWhUH2tlGRPO+POAPJAF5fKOLB9SXg=
8795
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
@@ -310,6 +318,8 @@ github.com/foxxorcat/mopan-sdk-go v0.1.6 h1:6J37oI4wMZLj8EPgSCcSTTIbnI5D6RCNW/sr
310318
github.com/foxxorcat/mopan-sdk-go v0.1.6/go.mod h1:UaY6D88yBXWGrcu/PcyLWyL4lzrk5pSxSABPHftOvxs=
311319
github.com/foxxorcat/weiyun-sdk-go v0.1.3 h1:I5c5nfGErhq9DBumyjCVCggRA74jhgriMqRRFu5jeeY=
312320
github.com/foxxorcat/weiyun-sdk-go v0.1.3/go.mod h1:TPxzN0d2PahweUEHlOBWlwZSA+rELSUlGYMWgXRn9ps=
321+
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
322+
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
313323
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
314324
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
315325
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=
@@ -849,6 +859,8 @@ golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE
849859
golang.org/x/exp v0.0.0-20191129062945-2f5052295587/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
850860
golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
851861
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
862+
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476 h1:bsqhLWFR6G6xiQcb+JoGqdKdRU6WzPWmK8E0jxTjzo4=
863+
golang.org/x/exp v0.0.0-20250606033433-dcc06ee1d476/go.mod h1:3//PLf8L/X+8b4vuAfHzxeRUl04Adcb341+IGKfnqS8=
852864
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
853865
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
854866
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

internal/conf/config.go

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

122+
type DLNA struct {
123+
Enable bool `json:"enable" env:"ENABLE"`
124+
Listen string `json:"listen" env:"LISTEN"`
125+
FriendlyName string `json:"friendly_name" env:"FRIEDNLY_NAME"`
126+
InterfaceNames []string `json:"interface_names" env:"INTERFACE_NAMES"`
127+
AnnounceInterval int `json:"announce_interval" env:"ANNOUNCE_INTERVAL"`
128+
RootDir string `json:"root_dir" env:"ROOT_DIR"`
129+
}
130+
122131
type Config struct {
123132
Force bool `json:"force" env:"FORCE"`
124133
SiteURL string `json:"site_url" env:"SITE_URL"`
@@ -141,6 +150,7 @@ type Config struct {
141150
S3 S3 `json:"s3" envPrefix:"S3_"`
142151
FTP FTP `json:"ftp" envPrefix:"FTP_"`
143152
SFTP SFTP `json:"sftp" envPrefix:"SFTP_"`
153+
DLNA DLNA `json:"dlna" envPrefix:"DLNA_"`
144154
LastLaunchedVersion string `json:"last_launched_version"`
145155
}
146156

@@ -252,6 +262,14 @@ func DefaultConfig(dataDir string) *Config {
252262
Enable: false,
253263
Listen: ":5222",
254264
},
265+
DLNA: DLNA{
266+
Enable: false,
267+
Listen: ":5200",
268+
FriendlyName: "",
269+
InterfaceNames: []string{},
270+
AnnounceInterval: 12,
271+
RootDir: "/",
272+
},
255273
LastLaunchedVersion: "",
256274
}
257275
}

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/v4/internal/conf"
7+
"github.com/OpenListTeam/OpenList/v4/server/dlna"
8+
"github.com/OpenListTeam/OpenList/v4/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)