@@ -219,45 +219,9 @@ func (handler *EmbyHandler) VideosHandler(ctx *gin.Context) {
219219 // EmbyServer >= 4.9 ====> mediaSourceID = mediasource_31
220220 mediaSourceID := ctx .Query ("mediasourceid" )
221221
222- // // 从 URL 中提取 item ID(例如:/emby/videos/43609/stream 中的 43609)
223- // var itemID string
224- // if matches := constants.EmbyRegexp.Router.VideosHandler.FindStringSubmatch(orginalPath); len(matches) > 0 {
225- // parts := strings.Split(orginalPath, "/")
226- // for i, part := range parts {
227- // if part == "videos" && i+1 < len(parts) {
228- // itemID = parts[i+1]
229- // break
230- // }
231- // }
232- // }
233-
234- // // 并发控制:确保同一个 item ID 只有一个任务在运行
235- // // 将整个处理流程放在锁内,避免重复查询和重复获取重定向 URL
236- // var muWrapper *mutexWithRefCount
237- // if itemID != "" {
238- // // 加载或创建 mutex wrapper
239- // value, _ := embyServerHandler.playbackInfoMutex.LoadOrStore(itemID, &mutexWithRefCount{})
240- // muWrapper = value.(*mutexWithRefCount)
241-
242- // // 增加引用计数
243- // atomic.AddInt32(&muWrapper.refCount, 1)
244-
245- // // 锁定并处理
246- // muWrapper.mu.Lock()
247- // defer func() {
248- // muWrapper.mu.Unlock()
249- // // 减少引用计数
250- // refCount := atomic.AddInt32(&muWrapper.refCount, -1)
251- // // 如果没有其他 goroutine 在使用,删除这个 mutex 以避免内存泄漏
252- // if refCount == 0 {
253- // embyServerHandler.playbackInfoMutex.Delete(itemID)
254- // }
255- // }()
256- // logging.Debugf("开始处理 item %s 的 VideosHandler 请求", itemID)
257- // }
258-
259222 logging .Debugf ("请求 ItemsServiceQueryItem:%s" , mediaSourceID )
260- itemResponse , err := handler .client .ItemsServiceQueryItem (strings .Replace (mediaSourceID , "mediasource_" , "" , 1 ), 1 , "Path,MediaSources" ) // 查询 item 需要去除前缀仅保留数字部分
223+ mediaSourceID_without_prefix := strings .Replace (mediaSourceID , "mediasource_" , "" , 1 )
224+ itemResponse , err := handler .client .ItemsServiceQueryItem (mediaSourceID_without_prefix , 1 , "Path,MediaSources" ) // 查询 item 需要去除前缀仅保留数字部分
261225 if err != nil {
262226 logging .Warning ("请求 ItemsServiceQueryItem 失败:" , err )
263227 handler .ReverseProxy (ctx .Writer , ctx .Request )
@@ -273,12 +237,14 @@ func (handler *EmbyHandler) VideosHandler(ctx *gin.Context) {
273237 }
274238
275239 strmFileType , opt := recgonizeStrmFileType (* item .Path )
240+
276241 for _ , mediasource := range item .MediaSources {
277- if * mediasource .ID == mediaSourceID { // EmbyServer >= 4.9 返回的ID带有前缀mediasource_
242+ logging .Debugf ("mediasource.ID: %s ; mediaSourceID: %s ; mediaSourceID_without_prefix: %s" , * mediasource .ID , mediaSourceID , mediaSourceID_without_prefix )
243+ // EmbyServer >= 4.9 返回的ID带有前缀mediasource_
244+ if strings .Replace (* mediasource .ID , "mediasource_" , "" , 1 ) == mediaSourceID_without_prefix {
278245 switch strmFileType {
279246 case constants .HTTPStrm :
280247 if * mediasource .Protocol == emby .HTTP {
281- // httpStrmHandler 内部有缓存机制,锁确保串行化访问
282248 ctx .Redirect (http .StatusFound , handler .httpStrmHandler (* mediasource .Path , ctx .Request .UserAgent ()))
283249 return
284250 }
0 commit comments