Skip to content

Commit b859f9b

Browse files
committed
feat: dlna server support
1 parent 9612d61 commit b859f9b

22 files changed

+2394
-0
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
@@ -14,6 +14,8 @@ require (
1414
github.com/ProtonMail/go-crypto v1.0.0
1515
github.com/SheltonZhu/115driver v1.0.34
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.4.2
@@ -81,6 +83,7 @@ require (
8183
require (
8284
cloud.google.com/go/compute/metadata v0.7.0 // indirect
8385
github.com/Azure/azure-sdk-for-go/sdk/internal v1.10.0 // indirect
86+
github.com/anacrolix/generics v0.0.1 // indirect
8487
github.com/google/go-cmp v0.7.0 // indirect
8588
github.com/mikelolasagasti/xz v1.0.1 // indirect
8689
github.com/minio/minlz v1.0.0 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ github.com/aead/ecdh v0.2.0 h1:pYop54xVaq/CEREFEcukHRZfTdjiWvYIsZDXXrBapQQ=
6666
github.com/aead/ecdh v0.2.0/go.mod h1:a9HHtXuSo8J1Js1MwLQx2mBhkXMT6YwUmVVEY4tTB8U=
6767
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
6868
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
69+
github.com/anacrolix/dms v1.7.1 h1:XVOpT3eoO5Ds34B1X+TE3R2ApfqGGeqotEoCVNP8BaI=
70+
github.com/anacrolix/dms v1.7.1/go.mod h1:excFJW5MKBhn5yt5ZMyeE9iFVqnO6tEGQl7YG/2tUoQ=
71+
github.com/anacrolix/generics v0.0.1 h1:4WVhK6iLb3UAAAQP6I3uYlMOHcp9FqJC9j4n81Wv9Ks=
72+
github.com/anacrolix/generics v0.0.1/go.mod h1:ff2rHB/joTV03aMSSn/AZNnaIpUw0h3njetGsaXcMy8=
73+
github.com/anacrolix/log v0.16.0 h1:DSuyb5kAJwl3Y0X1TRcStVrTS9ST9b0BHW+7neE4Xho=
74+
github.com/anacrolix/log v0.16.0/go.mod h1:m0poRtlr41mriZlXBQ9SOVZ8yZBkLjOkDhd5Li5pITA=
6975
github.com/andreburgaud/crypt2go v1.8.0 h1:J73vGTb1P6XL69SSuumbKs0DWn3ulbl9L92ZXBjw6pc=
7076
github.com/andreburgaud/crypt2go v1.8.0/go.mod h1:L5nfShQ91W78hOWhUH2tlGRPO+POAPJAF5fKOLB9SXg=
7177
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig=
@@ -255,6 +261,8 @@ github.com/foxxorcat/mopan-sdk-go v0.1.6 h1:6J37oI4wMZLj8EPgSCcSTTIbnI5D6RCNW/sr
255261
github.com/foxxorcat/mopan-sdk-go v0.1.6/go.mod h1:UaY6D88yBXWGrcu/PcyLWyL4lzrk5pSxSABPHftOvxs=
256262
github.com/foxxorcat/weiyun-sdk-go v0.1.3 h1:I5c5nfGErhq9DBumyjCVCggRA74jhgriMqRRFu5jeeY=
257263
github.com/foxxorcat/weiyun-sdk-go v0.1.3/go.mod h1:TPxzN0d2PahweUEHlOBWlwZSA+rELSUlGYMWgXRn9ps=
264+
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
265+
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
258266
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
259267
github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E=
260268
github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ=

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)