Giter Club home page Giter Club logo

Comments (10)

kingslay avatar kingslay commented on June 16, 2024

字幕的下载你是用什么来下载的呢?f

from ksplayer.

FaiChou avatar FaiChou commented on June 16, 2024
dataSource.infos = thirdPartySubtitles.map({ s in
    let url = URL(string: s.url)!
    return URLSubtitleInfo(subtitleID: url.path, name: s.name, url: url)
})

我把字幕的下载连接传进来的。

from ksplayer.

kingslay avatar kingslay commented on June 16, 2024

URLSubtitleInfo 是用URLSession.shared.downloadTask来进行下载的,没有设置过ua。需要你自己设置UA

from ksplayer.

kingslay avatar kingslay commented on June 16, 2024

你也可以用自己的方法来下载字幕,然后把这个下载下来的文件传给URLSubtitleInfo。URLSubtitleInfo 也是支持本地文件的字幕。

from ksplayer.

FaiChou avatar FaiChou commented on June 16, 2024

下载比较麻烦。一个文件夹下可能有很多字幕,比如一季美剧下,每集都带着字幕,批量下载的话容易触发后台 qps。

我大致看了下源码,不能强制设置某个 UA,因为项目集成了很多不同的平台,每个平台需要有不同的 UA,是否能跟随视频下载连接一样的 UA?或者给一个可选的参数来设置 UA?

from ksplayer.

FaiChou avatar FaiChou commented on June 16, 2024

@kingslay 当设置名字的时候 URLSubtitleInfo(subtitleID: url.path, name: s.name, url: url, userAgent: "custom agent") 由于加了判断:

if !url.isFileURL, name.isEmpty {}

名字不为空,它就不会走 download 函数下载字幕文件。

如果名字设置为空,则字幕列表的字幕都是乱七八糟的名字。

是否能去掉 name.isEmpty 这个判断?

from ksplayer.

kingslay avatar kingslay commented on June 16, 2024

可以把name.isEmpty 去掉。但是这个字幕下载之后,会重新设置名字。这个名字会是对的吗?你可以现在设置把这个判断去掉下。看下是否可以

  url.download(userAgent: userAgent) { [weak self] filename, tmpUrl in
                guard let self else {
                    return
                }
                self.name = filename
                self.downloadURL = tmpUrl
                var fileURL = URL(fileURLWithPath: NSTemporaryDirectory())
                fileURL.appendPathComponent(filename)
                try? FileManager.default.moveItem(at: tmpUrl, to: fileURL)
                self.downloadURL = fileURL
            }

from ksplayer.

kingslay avatar kingslay commented on June 16, 2024

之前的逻辑就是因为字幕的名字都是乱七八糟的名字。所以才在init就去下载的。不然这个字幕应该是要等到用户选中的时候再去下载。提前下载字幕可能会浪费网络。

from ksplayer.

FaiChou avatar FaiChou commented on June 16, 2024

哦,明白了,如果传进去名字,那么它不会自动下载,只有当选中字幕时候再下载。但是 download 接口只有在 init 时候才会被调用。这样的话又不能满足设置 UA 了。能否再改一下源代码,适配一下。

from ksplayer.

FaiChou avatar FaiChou commented on June 16, 2024

逻辑是这样的,进入播放页面时候,会将播放列表的所有字幕文件也传进去,传进去的字幕加上视频内置的字幕。这样用户可以手动选择使用哪个字幕。
传进去的字幕文件不只有下载连接,还有名字。

from ksplayer.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.