Skip to content

Commit 6afabca

Browse files
committed
refactor: 优化日志输出格式,统一使用 Infof 和 Debugf 方法
1 parent 16a07c9 commit 6afabca

File tree

3 files changed

+17
-17
lines changed

3 files changed

+17
-17
lines changed

internal/handler/emby.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (embyServerHandler *EmbyServerHandler) ModifyPlaybackInfo(rw *http.Response
140140
}
141141
directStreamURL := fmt.Sprintf("/videos/%s/stream?MediaSourceId=%s&Static=true&%s", *mediasource.ItemID, *mediasource.ID, apikeypair)
142142
playbackInfoResponse.MediaSources[index].DirectStreamURL = &directStreamURL
143-
logging.Info(*mediasource.Name, "强制禁止转码,直链播放链接为:", directStreamURL)
143+
logging.Infof("%s 强制禁止转码,直链播放链接为:%s", *mediasource.Name, directStreamURL)
144144
}
145145
}
146146

@@ -161,9 +161,9 @@ func (embyServerHandler *EmbyServerHandler) ModifyPlaybackInfo(rw *http.Response
161161
playbackInfoResponse.MediaSources[index].DirectStreamURL = &directStreamURL
162162
container := strings.TrimPrefix(path.Ext(*mediasource.Path), ".")
163163
playbackInfoResponse.MediaSources[index].Container = &container
164-
logging.Info(*mediasource.Name, "强制禁止转码,直链播放链接为:", directStreamURL, ",容器为: %s", container)
164+
logging.Infof("%s 强制禁止转码,直链播放链接为:%s,容器为%s", *mediasource.Name, directStreamURL, container)
165165
} else {
166-
logging.Info(*mediasource.Name, "保持原有转码设置")
166+
logging.Infof("%s 保持原有转码设置", *mediasource.Name)
167167
}
168168

169169
if playbackInfoResponse.MediaSources[index].Size == nil {
@@ -178,7 +178,7 @@ func (embyServerHandler *EmbyServerHandler) ModifyPlaybackInfo(rw *http.Response
178178
continue
179179
}
180180
playbackInfoResponse.MediaSources[index].Size = &fsGetData.Size
181-
logging.Info(*mediasource.Name, "设置文件大小为:", fsGetData.Size)
181+
logging.Infof("%s 设置文件大小为:%d", *mediasource.Name, fsGetData.Size)
182182
}
183183
}
184184
}
@@ -207,7 +207,7 @@ func (embyServerHandler *EmbyServerHandler) VideosHandler(ctx *gin.Context) {
207207
matches := constants.EmbyRegexp.Others.VideoRedirectReg.FindStringSubmatch(orginalPath)
208208
if len(matches) == 2 {
209209
redirectPath := fmt.Sprintf("/videos/%s/stream", matches[0])
210-
logging.Debug(orginalPath + " 重定向至:" + redirectPath)
210+
logging.Debugf("%s 重定向至:%s", orginalPath, redirectPath)
211211
ctx.Redirect(http.StatusFound, redirectPath)
212212
return
213213
}
@@ -216,7 +216,7 @@ func (embyServerHandler *EmbyServerHandler) VideosHandler(ctx *gin.Context) {
216216
// EmbyServer >= 4.9 ====> mediaSourceID = mediasource_31
217217
mediaSourceID := ctx.Query("mediasourceid")
218218

219-
logging.Debug("请求 ItemsServiceQueryItem:", mediaSourceID)
219+
logging.Debugf("请求 ItemsServiceQueryItem:%s", mediaSourceID)
220220
itemResponse, err := embyServerHandler.server.ItemsServiceQueryItem(strings.Replace(mediaSourceID, "mediasource_", "", 1), 1, "Path,MediaSources") // 查询 item 需要去除前缀仅保留数字部分
221221
if err != nil {
222222
logging.Warning("请求 ItemsServiceQueryItem 失败:", err)

internal/handler/jellyfin.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func (jellyfinHandler *JellyfinHandler) ModifyPlaybackInfo(rw *http.Response) er
135135
playbackInfoResponse.MediaSources[index].TranscodingContainer = nil
136136
directStreamURL := fmt.Sprintf("/Videos/%s/stream?MediaSourceId=%s&Static=true", *mediasource.ID, *mediasource.ID)
137137
if mediasource.DirectStreamURL != nil {
138-
logging.Debugf("%s 原直链播放链接: %s", *mediasource.Name, *mediasource.DirectStreamURL)
138+
logging.Debugf("%s 原直链播放链接 %s", *mediasource.Name, *mediasource.DirectStreamURL)
139139
apikeypair, err := utils.ResolveEmbyAPIKVPairs(*mediasource.DirectStreamURL)
140140
if err != nil {
141141
logging.Warning("解析API键值对失败:", err)
@@ -146,9 +146,9 @@ func (jellyfinHandler *JellyfinHandler) ModifyPlaybackInfo(rw *http.Response) er
146146
playbackInfoResponse.MediaSources[index].DirectStreamURL = &directStreamURL
147147
container := strings.TrimPrefix(path.Ext(*mediasource.Path), ".")
148148
playbackInfoResponse.MediaSources[index].Container = &container
149-
logging.Info(*mediasource.Name, " 强制禁止转码,直链播放链接为: ", directStreamURL, ",容器为: ", container)
149+
logging.Infof("%s 强制禁止转码,直链播放链接为:%s,容器为: %s", *mediasource.Name, directStreamURL, container)
150150
} else {
151-
logging.Info(*mediasource.Name, " 保持原有转码设置")
151+
logging.Infof("%s 保持原有转码设置", *mediasource.Name)
152152
}
153153

154154
if playbackInfoResponse.MediaSources[index].Size == nil {
@@ -163,7 +163,7 @@ func (jellyfinHandler *JellyfinHandler) ModifyPlaybackInfo(rw *http.Response) er
163163
continue
164164
}
165165
playbackInfoResponse.MediaSources[index].Size = &fsGetData.Size
166-
logging.Info(*mediasource.Name, "设置文件大小为:", fsGetData.Size)
166+
logging.Infof("%s 设置文件大小为:%d", *mediasource.Name, fsGetData.Size)
167167
}
168168
}
169169
}
@@ -188,7 +188,7 @@ func (jellyfinHandler *JellyfinHandler) VideosHandler(ctx *gin.Context) {
188188
}
189189

190190
mediaSourceID := ctx.Query("mediasourceid")
191-
logging.Debug("请求 ItemsServiceQueryItem:", mediaSourceID)
191+
logging.Debugf("请求 ItemsServiceQueryItem:%s", mediaSourceID)
192192
itemResponse, err := jellyfinHandler.server.ItemsServiceQueryItem(mediaSourceID, 1, "Path,MediaSources") // 查询 item 需要去除前缀仅保留数字部分
193193
if err != nil {
194194
logging.Warning("请求 ItemsServiceQueryItem 失败:", err)
@@ -199,7 +199,7 @@ func (jellyfinHandler *JellyfinHandler) VideosHandler(ctx *gin.Context) {
199199
item := itemResponse.Items[0]
200200

201201
if !strings.HasSuffix(strings.ToLower(*item.Path), ".strm") { // 不是 Strm 文件
202-
logging.Debug("播放本地视频:" + *item.Path + ",不进行处理")
202+
logging.Debugf("播放本地视频:%s,不进行处理", *item.Path)
203203
jellyfinHandler.proxy.ServeHTTP(ctx.Writer, ctx.Request)
204204
return
205205
}
@@ -210,7 +210,7 @@ func (jellyfinHandler *JellyfinHandler) VideosHandler(ctx *gin.Context) {
210210
switch strmFileType {
211211
case constants.HTTPStrm:
212212
if *mediasource.Protocol == jellyfin.HTTP {
213-
logging.Info("HTTPStrm 重定向至:", *mediasource.Path)
213+
logging.Infof("HTTPStrm 重定向至:%s", *mediasource.Path)
214214
ctx.Redirect(http.StatusFound, *mediasource.Path)
215215
}
216216
return
@@ -235,7 +235,7 @@ func (jellyfinHandler *JellyfinHandler) VideosHandler(ctx *gin.Context) {
235235
redirectURL += "?sign=" + fsGetData.Sign
236236
}
237237
}
238-
logging.Info("AlistStrm 重定向至:", redirectURL)
238+
logging.Infof("AlistStrm 重定向至:%s", redirectURL)
239239
ctx.Redirect(http.StatusFound, redirectURL)
240240
return
241241
case constants.UnknownStrm:

internal/handler/utils.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func recgonizeStrmFileType(strmFilePath string) (constants.StrmFileType, any) {
3434
if config.HTTPStrm.Enable {
3535
for _, prefix := range config.HTTPStrm.PrefixList {
3636
if strings.HasPrefix(strmFilePath, prefix) {
37-
logging.Debug(strmFilePath + " 成功匹配路径:" + prefix + ",Strm 类型:" + string(constants.HTTPStrm))
37+
logging.Debugf("%s 成功匹配路径:%s,Strm 类型:%s", strmFilePath, prefix, constants.HTTPStrm)
3838
return constants.HTTPStrm, nil
3939
}
4040
}
@@ -43,13 +43,13 @@ func recgonizeStrmFileType(strmFilePath string) (constants.StrmFileType, any) {
4343
for _, alistStrmConfig := range config.AlistStrm.List {
4444
for _, prefix := range alistStrmConfig.PrefixList {
4545
if strings.HasPrefix(strmFilePath, prefix) {
46-
logging.Debug(strmFilePath + " 成功匹配路径:" + prefix + ",Strm 类型:" + string(constants.AlistStrm) + ",AlistServer 地址:" + alistStrmConfig.ADDR)
46+
logging.Debugf("%s 成功匹配路径:%s,Strm 类型:%s,AlistServer 地址:%s", strmFilePath, prefix, constants.AlistStrm, alistStrmConfig.ADDR)
4747
return constants.AlistStrm, alistStrmConfig.ADDR
4848
}
4949
}
5050
}
5151
}
52-
logging.Debug(strmFilePath + " 未匹配任何路径,Strm 类型:" + string(constants.UnknownStrm))
52+
logging.Debugf("%s 未匹配任何路径,Strm 类型:%s", strmFilePath, constants.UnknownStrm)
5353
return constants.UnknownStrm, nil
5454
}
5555

0 commit comments

Comments
 (0)