### Go: Install openhongguo SDK Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Install the Go SDK package using go get. Requires Go 1.22 or later. ```bash go get github.com/beilunyang/openhongguo@latest ``` -------------------------------- ### Go: Quick start - search and playback Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Creates a client, searches for a query, lists episodes, and resolves playback streams. On first request, registers an anonymous device and saves its profile to anonymous.json. ```go package main import ( "context" "fmt" "log" "github.com/beilunyang/openhongguo/adapters" "github.com/beilunyang/openhongguo/sdk" ) func main() { ctx := context.Background() client, err := adapters.NewClient("anonymous.json", sdk.Options{}) if err != nil { log.Fatal(err) } page, err := client.Search(ctx, "全球死考", sdk.SearchOptions{}) if err != nil { log.Fatal(err) } episodes, err := client.ListEpisodes(ctx, page.Items[0].ID, sdk.EpisodeOptions{}) if err != nil { log.Fatal(err) } pb, err := client.ResolvePlayback(ctx, episodes.Items[0].ID, sdk.PlaybackOptions{}) if pb == nil { log.Fatal(err) } for _, s := range pb.Streams { fmt.Println(s.Definition, s.URL) } } ``` -------------------------------- ### Package and install from source Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/react-native/README.md Installs dependencies, packs the package, and installs the generated tarball in the app. ```Shell npm install npm pack npm install /path/to/react-native-openhongguo-0.1.0.tgz ``` -------------------------------- ### Start fixtureserver for Android device tests Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md Start the sample service on 127.0.0.1:8790 from the repository root before running Android device tests. Requires an Android emulator to be running. ```sh go run ./bindings/mobile/fixtureserver -addr 127.0.0.1:8790 ``` -------------------------------- ### Quick Start: Search and Resolve Playback Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Creates a client, searches for a series, lists episodes, and resolves playback for the first episode. On the first request, the SDK registers an anonymous device and saves its profile; subsequent requests reuse it. ```javascript import { createClient } from 'openhongguo'; const client = await createClient(); const page = await client.search('全球死考'); const episodes = await client.listEpisodes(page.items[0].id); const { playback } = await client.resolvePlayback(episodes.items[0].id); console.log(playback.streams.map((s) => `${s.definition} ${s.url}`)); ``` -------------------------------- ### Node.js: Install openhongguo npm package Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Install the Node.js SDK via npm. Requires Node.js 20 or later. ```bash npm install openhongguo ``` -------------------------------- ### React Native: Install openhongguo via Expo Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Install the React Native SDK using Expo. Requires React Native 15.1 or later. ```bash npx expo install react-native-openhongguo ``` -------------------------------- ### Run Android device tests with connectedDebugAndroidTest Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md Run the Android device tests after starting the fixtureserver and an emulator. Executes from the android directory. ```sh (cd android && ./gradlew connectedDebugAndroidTest) ``` -------------------------------- ### Build and run ohg CLI Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Builds the ohg command-line tool and runs search and play commands. Playback requires mpv, ffplay, or vlc; downloading requires ffmpeg. ```sh go build -o bin/ohg ./cmd/ohg bin/ohg search 全球死考 bin/ohg play 全球死考第一季 ``` -------------------------------- ### 创建客户端:adapters.NewClient 与 sdk.Options Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 使用默认实现创建客户端,sdk.Options 字段均可选。RetryAttempts 默认 1(不重试),Logger 默认不记录。 ```go client, err := adapters.NewClient("anonymous.json", sdk.Options{ RetryAttempts: 5, Logger: log.Default(), }) ``` -------------------------------- ### Node.js: Create client and search Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Creates a client and performs a search in Node.js. Requires Node.js 20 or later. ```javascript const client = await createClient(); const page = await client.search('全球死考'); ``` -------------------------------- ### adapters.NewClient Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 创建客户端并指定设备档案存储路径。 ```APIDOC ## [CONSTRUCTOR] adapters.NewClient ### Description 创建客户端并指定设备档案存储路径。 ### Method NewClient ### Endpoint adapters.NewClient(path, opts) ### Parameters #### Path Parameters - **path** (string) - Required - 设备档案存储路径。 #### Request Body - **opts** - 客户端选项。 ### Request Example ```go client := adapters.NewClient(path, opts) ``` ``` -------------------------------- ### createClient(options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md 创建客户端实例,用于访问 openhongguo API。所有选项都是可选的,支持自定义设备档案、传输层、超时和重试等设置。 ```APIDOC ## createClient(options) ### Description 创建客户端实例,用于访问 openhongguo API。所有选项都是可选的,支持自定义设备档案、传输层、超时和重试等设置。 ### Method createClient ### Parameters #### Options - **profile** (string | object) - Optional - 设备档案的位置:文件路径,或自定义的存储对象。 - **transport** (function) - Optional - 自定义的请求发送函数。 - **timeoutMs** (number) - Optional - 默认发送函数的超时,单位是毫秒。默认值是 30000。 - **retryAttempts** (number) - Optional - 可重试的失败的最多尝试次数。默认值是 3。 - **device** (object) - Optional - 新匿名设备的机型。空字段使用默认值(小米 14)。 - **log** (function) - Optional - 接收诊断日志的函数。日志中的 URL 已经脱敏。 - **apiOrigin** (string) - Optional - 接口地址。默认值与 App 相同。 - **registerOrigin** (string) - Optional - 接口地址。默认值与 App 相同。 - **distributionOrigin** (string) - Optional - 接口地址。默认值与 App 相同。 ### Request Example ```js import { createClient, memoryProfileStore } from 'openhongguo'; const client = await createClient({ profile: memoryProfileStore() }); ``` ### Response 返回一个 Promise,解析为客户端实例。 ``` -------------------------------- ### ProfileStore 接口 Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 自定义设备档案存储。实现 Load、Save 和 Reset 方法。 ```APIDOC ## [INTERFACE] sdk.ProfileStore ### Description 自定义设备档案存储。实现 Load、Save 和 Reset 方法。 ### Method ProfileStore ### Endpoint sdk.ProfileStore ### Parameters #### Methods - **Load** - 加载设备档案。 - **Save** - 保存设备档案。 - **Reset** - 重置设备档案。 ### Request Example ```go type MyStore struct {} func (s *MyStore) Load() (*sdk.Profile, error) { ... } func (s *MyStore) Save(profile *sdk.Profile) error { ... } func (s *MyStore) Reset() error { ... } ``` ``` -------------------------------- ### discover(options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads a channel from the book city, defaulting to 'Recommended'. Returns a page of series. ```APIDOC ## discover(options) ### Description Loads a channel from the book city, defaulting to 'Recommended'. Returns a page of series. ### Method Function ### Parameters - `options` (DiscoverOptions) - Optional - Query parameters for the discovery request. ### Returns - `Future>` - A page of series. ### Example ```dart final page = await client.discover(); ``` ``` -------------------------------- ### filestore.New Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 创建基于文件的设备档案存储。 ```APIDOC ## [CONSTRUCTOR] filestore.New ### Description 创建基于文件的设备档案存储。 ### Method New ### Endpoint filestore.New(path) ### Parameters #### Path Parameters - **path** (string) - Required - 文件路径。 ### Request Example ```go store := filestore.New(path) ``` ``` -------------------------------- ### Makefile commands for build and test Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Lists the Makefile targets for testing, generating types and docs, and building CLI, Node.js, and mobile packages. The test target does not access the network. ```makefile make test ``` ```makefile make test-mobile ``` ```makefile make gen ``` ```makefile make build ``` -------------------------------- ### Swift: Create client and search Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Creates a client and performs a search in Swift (iOS/macOS). Requires iOS 13 or macOS 11 or later. ```swift let client = try OpenhongguoClient.create() let page = try await client.search("全球死考") ``` -------------------------------- ### memstore.New Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 创建仅内存的设备档案存储。进程退出后数据丢失。 ```APIDOC ## [CONSTRUCTOR] memstore.New ### Description 创建仅内存的设备档案存储。进程退出后数据丢失。 ### Method New ### Endpoint memstore.New() ### Request Example ```go store := memstore.New() ``` ``` -------------------------------- ### Kotlin: Create client and search Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Creates a client and performs a search in Kotlin (Android). Requires Android 5.0 (API 21) or later. ```kotlin val client = OpenhongguoClient.create(context) val page = client.search("全球死考") ``` -------------------------------- ### 遍历所有页:client.SearchPager 与 pager.Next Source: https://github.com/beilunyang/openhongguo/blob/main/README.md SearchPager 返回分页器,Next 返回当前页条目和是否还有更多。服务端可能返回重复短剧,Pager 会自动去重。 ```go pager := client.SearchPager("末世", sdk.SearchOptions{}) for { items, more, err := pager.Next(ctx) if err != nil { log.Fatal(err) } for _, s := range items { fmt.Println(s.ID, s.Title) } if !more { break } } ``` -------------------------------- ### createClient() Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Creates a new client instance for the openhongguo SDK. The client is used to make all API calls. ```APIDOC ## createClient() ### Description Creates a new client instance for the openhongguo SDK. The client is used to make all API calls. ### Method createClient ### Endpoint N/A (SDK method) ### Parameters None ### Request Example ```js const client = await createClient(); ``` ### Response #### Success Response - **client** (Client) - The client instance for making API calls. #### Response Example ```js const client = await createClient(); ``` ``` -------------------------------- ### Discover Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads a channel from the book city, defaulting to 'Recommended'. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## Discover ### Description Loads a channel from the book city, defaulting to 'Recommended'. ### Method SDK Method ### Signature - Go: `Discover(options)` - Other languages: `discover(options)` ### Parameters - **options** (object) - Required - Options for the discovery request. ### Returns - Returns the channel data. ``` -------------------------------- ### 运行测试 (make test test-mobile) Source: https://github.com/beilunyang/openhongguo/blob/main/docs/release.md 在写入校验和和 URL 到 Package.swift 后,运行此命令执行测试。 ```sh make test test-mobile ``` -------------------------------- ### Suggest Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Returns search suggestions for a given prefix. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## Suggest ### Description Returns search suggestions for a given prefix. ### Method SDK Method ### Signature - Go: `Suggest(prefix)` - Other languages: `suggest(prefix)` ### Parameters - **prefix** (string) - Required - The prefix to get suggestions for. ### Returns - Returns a list of suggestion strings. ``` -------------------------------- ### 运行接口契约检查:go test -tags live -run TestLiveContract Source: https://github.com/beilunyang/openhongguo/blob/main/docs/development.md 运行实时接口契约检查,比较真实接口响应与 testdata/protocol 中的样本。需要 -tags live 才能访问网络;不带该标签时 go test ./... 不访问网络。 ```sh go test -tags live -run TestLiveContract -v ./internal/contract ``` -------------------------------- ### 使用 memoryProfileStore 创建客户端 Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md 将设备档案仅保存在内存中,进程退出后档案丢失。createClient 的所有设置均为可选,profile 可指定文件路径或自定义存储对象。 ```javascript import { createClient, memoryProfileStore } from 'openhongguo'; const client = await createClient({ profile: memoryProfileStore() }); ``` -------------------------------- ### OpenhongguoClient.create() Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Creates a new Openhongguo client instance. This initializes the SDK and registers an anonymous device on first use. ```APIDOC ## OpenhongguoClient.create() ### Description Creates a new Openhongguo client instance. This initializes the SDK and registers an anonymous device on first use. ### Method Constructor ### Returns - `Future` - A Future that resolves to the client instance. ### Example ```dart final client = await OpenhongguoClient.create(); ``` ``` -------------------------------- ### 让 proxy.golang.org 收录新版本 Source: https://github.com/beilunyang/openhongguo/blob/main/docs/release.md 使用 GOPROXY 环境变量和 go list 命令触发 proxy.golang.org 收录新版本。 ```sh GOPROXY=https://proxy.golang.org go list -m github.com/beilunyang/openhongguo@vX.Y.Z ``` -------------------------------- ### 翻页遍历搜索结果(searchAll) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md 使用 searchAll 逐页遍历搜索结果,自动去除跨页重复的短剧。返回 Stream,可异步迭代。 ```dart await for (final series in client.searchAll('末世', const SearchOptions(), 3)) { print('${series.id} ${series.title}'); } ``` -------------------------------- ### OpenhongguoClient.create Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md 创建 Openhongguo 客户端实例。所有设置都是可选的,通过 ClientOptions 配置。 ```APIDOC ## OpenhongguoClient.create ### Description 创建 Openhongguo 客户端实例。所有设置都是可选的,通过 ClientOptions 配置。 ### Method create ### Parameters #### ClientOptions - **profilePath** (string) - Optional - 设备档案的路径。默认目录不参加系统备份:Android 是 `noBackupFilesDir`,iOS 是标记为不备份的 Application Support - **apiOrigin** (string) - Optional - 接口地址。默认值与 App 相同 - **registerOrigin** (string) - Optional - 接口地址。默认值与 App 相同 - **distributionOrigin** (string) - Optional - 接口地址。默认值与 App 相同 - **retryAttempts** (integer) - Optional - 可重试的失败的最多尝试次数。默认值是 3 - **device** (object) - Optional - 新匿名设备的机型。空字段使用默认值(小米 14) - **log** (function) - Optional - 接收诊断日志的函数。日志中的 URL 已经脱敏 ### Response 返回 OpenhongguoClient 实例。 ``` -------------------------------- ### discoverAll(options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Iterates through all pages of a channel, removing duplicate series across pages. Returns an async iterable of series. ```APIDOC ## discoverAll(options) ### Description Iterates through all pages of a channel, removing duplicate series across pages. Returns an async iterable of series. ### Method discoverAll ### Endpoint N/A (SDK method) ### Parameters #### Query Parameters - **options** (object) - Optional - Options for the request, e.g., pagination. ### Request Example ```js for await (const series of client.discoverAll()) { console.log(series.id, series.title); } ``` ### Response #### Success Response - **async iterable** (AsyncIterable) - An async iterable of series. #### Response Example ```js for await (const series of client.discoverAll()) { console.log(series.id, series.title); } ``` ``` -------------------------------- ### categoryLanding(categoryId, options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads a page of the category list and its filter panel. ```APIDOC ## categoryLanding(categoryId, options) ### Description Loads a page of the category list and its filter panel. ### Method Function ### Parameters - `categoryId` (String) - Required - The ID of the category. - `options` (CategoryLandingOptions) - Optional - Query parameters for pagination and filtering. ### Returns - `Future` - The category landing data. ### Example ```dart final landing = await client.categoryLanding('cat1'); ``` ``` -------------------------------- ### 处理加密分集并获取内容密钥 Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 当 ResolvePlayback 返回 ErrDRMProtected 时,将播放模型传给 sdk.ContentKey 获取内容密钥。密钥的 Hex 值用于 ffmpeg 的 -decryption_key。加密方式为 cenc-aes-ctr,一个分集的所有清晰度使用同一个内容密钥,计算只在本地进行。 ```go pb, err := client.ResolvePlayback(ctx, episodeID, sdk.PlaybackOptions{}) if errors.Is(err, sdk.ErrDRMProtected) { key, err := sdk.ContentKey(pb) // 把 key.Hex 传给 ffmpeg 的 -decryption_key ... } ``` -------------------------------- ### CategoryLanding Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads a page of the list under a book category, along with its filter panel. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## CategoryLanding ### Description Loads a page of the list under a book category, along with its filter panel. ### Method SDK Method ### Signature - Go: `CategoryLanding(categoryId, options)` - Other languages: `categoryLanding(categoryId, options)` ### Parameters - **categoryId** (string) - Required - The ID of the category. - **options** (object) - Required - Options for pagination or filtering. ### Returns - Returns a page of category items and filter panel data. ``` -------------------------------- ### Search Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 执行搜索请求,返回搜索结果页面。支持通过 context 设置超时。 ```APIDOC ## [SEARCH] client.Search ### Description 执行搜索请求,返回搜索结果页面。支持通过 context 设置超时。 ### Method Search ### Endpoint client.Search(ctx, query, options) ### Parameters #### Context - **ctx** (context.Context) - Required - 用于取消或设置超时。 #### Query Parameters - **query** (string) - Required - 搜索关键词。 #### Request Body - **options** (sdk.SearchOptions) - Required - 搜索选项。 ### Request Example ```go ctx, cancel := context.WithTimeout(ctx, 20*time.Second) defer cancel() page, err := client.Search(ctx, "全球死考", sdk.SearchOptions{}) ``` ### Response #### Success Response - **page** - 搜索结果页面。 #### Error Response - **err** - 错误信息。 ``` -------------------------------- ### newReleases(query) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads a page from the new releases calendar. ```APIDOC ## newReleases(query) ### Description Loads a page from the new releases calendar. ### Method Function ### Parameters - `query` (NewReleasesQuery) - Required - Query parameters for the new releases request. ### Returns - `Future>` - A page of new releases. ### Example ```dart final page = await client.newReleases(query); ``` ``` -------------------------------- ### 打包 xcframework 并计算校验和 Source: https://github.com/beilunyang/openhongguo/blob/main/docs/release.md 创建 dist/vX.Y.Z 目录,使用 ditto 打包 xcframework 为 zip,然后用 swift package compute-checksum 计算校验和。发布时必须上传此 zip,重新打包会得到不同的校验和,SPM 会拒绝下载。 ```sh mkdir -p dist/vX.Y.Z (cd bindings/mobile/ios && ditto -c -k --sequesterRsrc --keepParent \ OpenhongguoCore.xcframework ../../../dist/vX.Y.Z/OpenhongguoCore.xcframework.zip) swift package compute-checksum dist/vX.Y.Z/OpenhongguoCore.xcframework.zip ``` -------------------------------- ### ResetDevice Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 重置匿名设备。当设备被拒绝或需要更换机型时调用。 ```APIDOC ## [RESET] client.ResetDevice ### Description 重置匿名设备。当设备被拒绝或需要更换机型时调用。 ### Method ResetDevice ### Endpoint client.ResetDevice(ctx) ### Parameters #### Context - **ctx** (context.Context) - Required - 用于取消或设置超时。 ### Request Example ```go client.ResetDevice(ctx) ``` ### Response #### Success Response 无返回值。 #### Error Response - **err** - 错误信息。 ``` -------------------------------- ### RetryAfter Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 返回建议的等待时间。用于手动重试逻辑。 ```APIDOC ## [RETRY] sdk.RetryAfter ### Description 返回建议的等待时间。用于手动重试逻辑。 ### Method RetryAfter ### Endpoint sdk.RetryAfter(err, fallback) ### Parameters #### Request Body - **err** (error) - Required - 错误对象。 - **fallback** (duration) - Required - 默认等待时间。 ### Request Example ```go wait := sdk.RetryAfter(err, 5*time.Second) ``` ### Response #### Success Response - **duration** - 建议的等待时间。 ``` -------------------------------- ### Dart: Create client and search Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Creates a client and performs a search in Dart (Flutter). Requires Flutter 7.0 (API 24) or later. ```dart final client = await OpenhongguoClient.create(); final page = await client.search('全球死考'); ``` -------------------------------- ### Build Go core for React Native Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/react-native/README.md Compiles the Go core and copies it to the android/ and ios/ directories. Requires Go 1.26+ and gomobile. ```Shell ../mobile/build.sh react-native ``` -------------------------------- ### 使用 context.WithTimeout 设置请求超时 Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 限制一次调用的总时间。使用 20 秒超时,调用 client.Search 搜索“全球死考”。httptransport 对每个请求另有 30 秒超时。 ```go ctx, cancel := context.WithTimeout(ctx, 20*time.Second) defer cancel() page, err := client.Search(ctx, "全球死考", sdk.SearchOptions{}) ``` -------------------------------- ### 发布到 Maven Central (gradlew publishToMavenCentral) Source: https://github.com/beilunyang/openhongguo/blob/main/docs/release.md 在 bindings/mobile/android 目录下运行 Gradle 发布到 Maven Central。需要 ~/.gradle/gradle.properties 中有 mavenCentralUsername、mavenCentralPassword、signingInMemoryKey 和 signingInMemoryKeyPassword。必须使用 JDK 17 或 21,因为 AGP 内置的 Dokka 不能识别 JDK 25 的版本号,生成 javadoc 时失败。发布后需在 Central Portal 确认并发布部署。 ```sh (cd bindings/mobile/android && ./gradlew publishToMavenCentral) ``` -------------------------------- ### Kotlin 翻页示例:searchAll Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md 使用 Kotlin 的 Flow 逐页遍历搜索结果,并去掉跨页重复的短剧。 ```kotlin client.searchAll("末世", maxPages = 3).collect { println("${it.id} ${it.title}") } ``` -------------------------------- ### discoverAll(options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Iterates through all pages of a channel, removing duplicate series across pages. Returns a stream of series. ```APIDOC ## discoverAll(options) ### Description Iterates through all pages of a channel, removing duplicate series across pages. Returns a stream of series. ### Method Function ### Parameters - `options` (DiscoverOptions) - Optional - Query parameters for the discovery request. ### Returns - `Stream` - A stream of series. ### Example ```dart await for (final series in client.discoverAll()) { print(series.title); } ``` ``` -------------------------------- ### discoverAll(options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md Iterates through a channel page by page, removing duplicate short plays across pages. ```APIDOC ## discoverAll(options) ### Description Iterates through a channel page by page, removing duplicate short plays across pages. ### Method Function call ### Parameters - **options** (object) - Optional - Channel options ### Returns - **Stream of series** - A stream of series (Flow in Kotlin, AsyncThrowingStream in Swift) ``` -------------------------------- ### NewReleases Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads a page from the new releases calendar. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## NewReleases ### Description Loads a page from the new releases calendar. ### Method SDK Method ### Signature - Go: `NewReleases(query)` - Other languages: `newReleases(query)` ### Parameters - **query** (object) - Required - Query parameters for the new releases page. ### Returns - Returns a page of new releases. ``` -------------------------------- ### Debian/Ubuntu 安装外部程序(mpv、ffmpeg、ca-certificates) Source: https://github.com/beilunyang/openhongguo/blob/main/docs/cli.md 在 Debian 和 Ubuntu 上使用 apt 安装播放、解密和 HTTPS 所需的程序。 ```sh apt install mpv ffmpeg ca-certificates ``` -------------------------------- ### Android 添加依赖 (Gradle Kotlin DSL) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md 在 App 模块的构建文件中加入 Maven Central 依赖。kotlinx-coroutines 会随依赖引入,最低系统版本为 Android 5.0(API 21),aar 已声明网络权限并包含混淆规则。 ```kotlin dependencies { implementation("io.github.beilunyang:openhongguo:0.1.0") } ``` -------------------------------- ### 错误处理:errors.Is 与 sdk 哨兵错误 Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 所有错误可用 errors.Is 与 sdk 包中的哨兵错误比较。示例处理 ErrContentUnavailable 和 ErrRateLimited,后者可用 sdk.RetryAfter 获取建议等待时间。 ```go _, err := client.GetSeries(ctx, seriesID) switch { case errors.Is(err, sdk.ErrContentUnavailable): fmt.Println("这部短剧已下架") case errors.Is(err, sdk.ErrRateLimited): time.Sleep(sdk.RetryAfter(err, 10*time.Second)) case err != nil: log.Fatal(err) } ``` -------------------------------- ### ContentKey Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 从播放模型获取内容密钥。用于解密受 DRM 保护的分集。 ```APIDOC ## [KEY] sdk.ContentKey ### Description 从播放模型获取内容密钥。用于解密受 DRM 保护的分集。 ### Method ContentKey ### Endpoint sdk.ContentKey(pb) ### Parameters #### Request Body - **pb** (播放模型) - Required - 从 ResolvePlayback 返回的播放模型。 ### Request Example ```go key, err := sdk.ContentKey(pb) ``` ### Response #### Success Response - **key** - 内容密钥,包含 Hex 字段,可传给 ffmpeg 的 -decryption_key。 #### Error Response - **err** - 错误信息。 ``` -------------------------------- ### memoryProfileStore() Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md 创建一个内存设备档案存储对象,用于将设备档案仅保存在内存中,进程退出后丢失。 ```APIDOC ## memoryProfileStore() ### Description 创建一个内存设备档案存储对象,用于将设备档案仅保存在内存中,进程退出后丢失。 ### Method memoryProfileStore ### Parameters 无 ### Request Example ```js import { createClient, memoryProfileStore } from 'openhongguo'; const client = await createClient({ profile: memoryProfileStore() }); ``` ### Response 返回一个存储对象,包含 `load()`、`save(json)`、`reset()` 三个异步方法。 ``` -------------------------------- ### SetLogger Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 设置日志记录器,记录每个请求的方法、脱敏后的 URL 和状态码。 ```APIDOC ## [LOGGER] SetLogger ### Description 设置日志记录器,记录每个请求的方法、脱敏后的 URL 和状态码。 ### Method SetLogger ### Endpoint SetLogger(logger) ### Parameters #### Request Body - **logger** - 日志记录器。 ### Request Example ```go httptransport.SetLogger(logger) ``` ``` -------------------------------- ### hotSearch() Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads the 'Guess You Want to Search' and various hot search rankings from the search page. ```APIDOC ## hotSearch() ### Description Loads the 'Guess You Want to Search' and various hot search rankings from the search page. ### Method Function ### Returns - `Future` - The hot search data. ### Example ```dart final result = await client.hotSearch(); ``` ``` -------------------------------- ### Build Go core for Flutter Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Compiles the Go core and copies it to the android/ and ios/ directories. Requires Go 1.26 or higher and gomobile. ```sh ../mobile/build.sh flutter ``` -------------------------------- ### shortRank(query) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads a page of the short drama ranking, including actor rankings. ```APIDOC ## shortRank(query) ### Description Loads a page of the short drama ranking, including actor rankings. ### Method Function ### Parameters - `query` (ShortRankQuery) - Required - Query parameters for the ranking request. ### Returns - `Future>` - A page of ranking items. ### Example ```dart final page = await client.shortRank(query); ``` ``` -------------------------------- ### Search and resolve playback in React Native Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/react-native/README.md Creates a client, searches for a drama, lists episodes, and resolves playback for the first episode. The first request registers an anonymous device and saves its profile for subsequent requests. ```TypeScript import { createClient } from 'react-native-openhongguo'; const client = await createClient(); const page = await client.search('全球死考'); const episodes = await client.listEpisodes(page.items[0].id); const { playback } = await client.resolvePlayback(episodes.items[0].id); console.log(playback.streams.map((s) => `${s.definition} ${s.url}`)); ``` -------------------------------- ### SeriesRecommend Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads related recommendations for a short drama. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## SeriesRecommend ### Description Loads related recommendations for a short drama. ### Method SDK Method ### Signature - Go: `SeriesRecommend(seriesId)` - Other languages: `seriesRecommend(seriesId)` ### Parameters - **seriesId** (string) - Required - The ID of the series. ### Returns - Returns a list of recommended series. ``` -------------------------------- ### 自定义存储对象方法 Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md 自定义存储对象必须实现三个异步方法:load、save、reset,用于管理设备档案。 ```APIDOC ## 自定义存储对象方法 ### Description 自定义存储对象必须实现三个异步方法,用于管理设备档案。 ### Methods #### load() - **Description**: 读取设备档案。如果没有设备档案,返回 `null`。 - **Returns**: Promise #### save(json) - **Description**: 保存设备档案。 - **Parameters**: - **json** (object) - Required - 设备档案数据。 - **Returns**: Promise #### reset() - **Description**: 删除设备档案。 - **Returns**: Promise ``` -------------------------------- ### release() Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Releases the native client. After calling release(), all other methods will fail. ```APIDOC ## release() ### Description Releases the native client. After calling release(), all other methods will fail. ### Method Function ### Returns - `void` - No return value. ### Example ```dart client.release(); ``` ``` -------------------------------- ### listEpisodes(seriesId, options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Loads the episode list for a series. ```APIDOC ## listEpisodes(seriesId, options) ### Description Loads the episode list for a series. ### Method listEpisodes ### Endpoint N/A (SDK method) ### Parameters #### Path Parameters - **seriesId** (string) - Required - The ID of the series. #### Query Parameters - **options** (object) - Optional - Options for the request, e.g., pagination. ### Request Example ```js const episodes = await client.listEpisodes('12345'); ``` ### Response #### Success Response - **episodes** (Page) - A page of episodes. #### Response Example ```js const episodes = await client.listEpisodes('12345'); ``` ``` -------------------------------- ### 自定义 sdk.Transport 接口 Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 实现 sdk.Transport 接口以使用代理、记录请求或模拟服务端。注意:只在没有收到响应时返回错误,HTTP 错误状态码作为 Response 正常返回;Response.Body 必须是原始字节,不要解压;请求 URL 的查询参数包含设备 ID,记录日志前先脱敏。 ```go type Transport interface { Do(ctx context.Context, req *sdk.Request) (*sdk.Response, error) } ``` -------------------------------- ### Swift 翻页示例:searchAll Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md 使用 Swift 的 AsyncThrowingStream 逐页遍历搜索结果,并去掉跨页重复的短剧。 ```swift for try await series in client.searchAll("末世", maxPages: 3) { print(series.id, series.title) } ``` -------------------------------- ### searchAll(query, options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Iterates through all pages of search results, removing duplicate series across pages. Returns an async iterable of series. ```APIDOC ## searchAll(query, options) ### Description Iterates through all pages of search results, removing duplicate series across pages. Returns an async iterable of series. ### Method searchAll ### Endpoint N/A (SDK method) ### Parameters #### Query Parameters - **query** (string) - Required - The search query string. - **options** (object) - Optional - Options for the request, e.g., filters. ### Request Example ```js for await (const series of client.searchAll('末世', {}, { maxPages: 3 })) { console.log(series.id, series.title); } ``` ### Response #### Success Response - **async iterable** (AsyncIterable) - An async iterable of series. #### Response Example ```js for await (const series of client.searchAll('末世', {}, { maxPages: 3 })) { console.log(series.id, series.title); } ``` ``` -------------------------------- ### Retryable Source: https://github.com/beilunyang/openhongguo/blob/main/README.md 判断错误是否可重试。用于手动重试逻辑。 ```APIDOC ## [RETRY] sdk.Retryable ### Description 判断错误是否可重试。用于手动重试逻辑。 ### Method Retryable ### Endpoint sdk.Retryable(err) ### Parameters #### Request Body - **err** (error) - Required - 错误对象。 ### Request Example ```go if sdk.Retryable(err) { ... } ``` ### Response #### Success Response - **bool** - 如果错误可重试,返回 true。 ``` -------------------------------- ### ranking(activityId, rankListId) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads an activity ranking. ```APIDOC ## ranking(activityId, rankListId) ### Description Loads an activity ranking. ### Method Function ### Parameters - `activityId` (String) - Required - The ID of the activity. - `rankListId` (String) - Required - The ID of the ranking list. ### Returns - `Future` - The ranking data. ### Example ```dart final ranking = await client.ranking('activity1', 'list1'); ``` ``` -------------------------------- ### Categories Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads the tabs for book categories: All, Male, Female, and default tabs. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## Categories ### Description Loads the tabs for book categories: All, Male, Female, and default tabs. ### Method SDK Method ### Signature - Go: `Categories(categoryId)` - Other languages: `categories(categoryId)` ### Parameters - **categoryId** (string) - Required - The ID of the category. ### Returns - Returns category tab data. ``` -------------------------------- ### 发布到 npm (node 和 react-native) Source: https://github.com/beilunyang/openhongguo/blob/main/docs/release.md 分别发布 Node.js 和 React Native 包到 npm。先构建 Node 包再发布,React Native 包直接发布。 ```sh (cd bindings/node && npm run build && npm publish) (cd bindings/react-native && npm publish) ``` -------------------------------- ### newReleases(query) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/mobile/README.md Loads a page of the new release calendar. ```APIDOC ## newReleases(query) ### Description Loads a page of the new release calendar. ### Method Function call ### Parameters - **query** (object) - Required - Query parameters for the new releases ### Returns - **New releases** - The new releases page ``` -------------------------------- ### Ranking Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Loads an activity ranking. This method is available in all supported languages with corresponding naming conventions. ```APIDOC ## Ranking ### Description Loads an activity ranking. ### Method SDK Method ### Signature - Go: `Ranking(activityId, rankListId)` - Other languages: `ranking(activityId, rankListId)` ### Parameters - **activityId** (string) - Required - The ID of the activity. - **rankListId** (string) - Required - The ID of the ranking list. ### Returns - Returns the ranking data. ``` -------------------------------- ### listEpisodes(seriesId, options) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads the episode list for a series. ```APIDOC ## listEpisodes(seriesId, options) ### Description Loads the episode list for a series. ### Method Function ### Parameters - `seriesId` (String) - Required - The ID of the series. - `options` (ListEpisodesOptions) - Optional - Query parameters for pagination. ### Returns - `Future>` - A page of episodes. ### Example ```dart final episodes = await client.listEpisodes('123'); ``` ``` -------------------------------- ### seriesRecommend(seriesId) Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md Loads related recommendations for a series. ```APIDOC ## seriesRecommend(seriesId) ### Description Loads related recommendations for a series. ### Method Function ### Parameters - `seriesId` (String) - Required - The ID of the series. ### Returns - `Future>` - A list of recommended series. ### Example ```dart final recommendations = await client.seriesRecommend('123'); ``` ``` -------------------------------- ### OpenhongguoException Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/flutter/README.md 所有错误都是 OpenhongguoException。包含错误码、是否可重试和建议等待时间。 ```APIDOC ## OpenhongguoException ### Description 所有错误都是 OpenhongguoException。包含错误码、是否可重试和建议等待时间。 ### Properties - **code** (ErrorCode) - 错误码,例如 `ErrorCode.rateLimited` - **retryable** (boolean) - 重试同一请求能否成功 - **retryAfterMs** (integer) - 服务端建议的等待时间,单位是毫秒。0 表示没有建议 ### Error Codes | 错误码 | 含义 | 可重试 | |---|---|---| | `INVALID_OPTIONS` | 客户端的设置或调用参数无效 | 否 | | `PROFILE_NOT_FOUND` | 还没有保存过设备档案 | 否 | | `SIGNER_UNAVAILABLE` | 请求需要签名,而客户端没有可用的签名器 | 否 | | `AUTHENTICATION_REQUIRED` | 内容需要登录才能访问,匿名客户端无法继续 | 否 | | `NOT_PROTECTED` | 为未加密的播放模型请求了内容密钥 | 否 | | `DRM_PROTECTED` | 分集是加密的,需要内容密钥才能解密 | 否 | | `ANONYMOUS_LIMITED` | 服务端给匿名设备返回了空结果 | 否 | | `RATE_LIMITED` | 请求太频繁,被服务端限流 | 是 | | `TRANSPORT` | 网络请求失败 | 是 | | `SIGNATURE_REJECTED` | 服务端拒绝了请求的签名 | 否 | | `CONTENT_UNAVAILABLE` | 内容已下架、不存在,或当前调用方无权访问 | 否 | | `PARAM_INVALID` | 服务端认为请求参数无效 | 否 | | `CHALLENGE_REQUIRED` | 服务端要求验证码或其他验证,匿名客户端无法继续 | 否 | | `DEVICE_REJECTED` | 匿名设备被拒绝,需要重置设备后重新注册 | 否 | | `END_OF_LIST` | 列表已经没有更多内容 | 否 | | `ALBUM_UNAVAILABLE` | 匿名读取不到这个合集,或者这部短剧没有其他季 | 否 | | `CANCELLED` | 调用被取消 | 否 | ``` -------------------------------- ### Flutter: Add openhongguo package Source: https://github.com/beilunyang/openhongguo/blob/main/README.md Add the Flutter SDK package using flutter pub. Requires Flutter 7.0 (API 24) or later. ```bash flutter pub add openhongguo ``` -------------------------------- ### Handle Encrypted Episodes with contentKey Source: https://github.com/beilunyang/openhongguo/blob/main/bindings/node/README.md Checks if an episode is protected and logs the content key. If the SDK cannot derive the key, contentKey is absent and contentKeyError provides the reason; the playback model is still returned normally. ```javascript const { playback, contentKey } = await client.resolvePlayback(episodeId); if (playback.protected) { // 例如:ffmpeg -decryption_key -i -c copy out.mp4 console.log(contentKey.key); } ```