diff --git a/DarockBili.xcodeproj/project.pbxproj b/DarockBili.xcodeproj/project.pbxproj index 45f427f97..6b84d22db 100644 --- a/DarockBili.xcodeproj/project.pbxproj +++ b/DarockBili.xcodeproj/project.pbxproj @@ -211,8 +211,6 @@ B2B813972CC3D22800C69D17 /* BiliBiliAPIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B813962CC3D22800C69D17 /* BiliBiliAPIService.swift */; }; B2B813982CC3D22800C69D17 /* BiliBiliAPIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B813962CC3D22800C69D17 /* BiliBiliAPIService.swift */; }; B2B813992CC3D22800C69D17 /* BiliBiliAPIService.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B813962CC3D22800C69D17 /* BiliBiliAPIService.swift */; }; - B2B8139B2CC3D37500C69D17 /* TrendingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B8139A2CC3D37500C69D17 /* TrendingView.swift */; }; - B2B8139C2CC3D37500C69D17 /* TrendingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B8139A2CC3D37500C69D17 /* TrendingView.swift */; }; B2B8139D2CC3D37500C69D17 /* TrendingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B2B8139A2CC3D37500C69D17 /* TrendingView.swift */; }; B4DAF0DD2B80725800755F0C /* LinkDetectText.swift in Sources */ = {isa = PBXBuildFile; fileRef = B4DAF0DB2B80725800755F0C /* LinkDetectText.swift */; }; /* End PBXBuildFile section */ @@ -1251,7 +1249,6 @@ 8CA7CCA32B77B2F3008E587F /* NoticeView.swift in Sources */, B2B813972CC3D22800C69D17 /* BiliBiliAPIService.swift in Sources */, 8CA7CC952B77B0FB008E587F /* SkinChooserView.swift in Sources */, - B2B8139B2CC3D37500C69D17 /* TrendingView.swift in Sources */, 8CA7CCA62B77B315008E587F /* CommentsView.swift in Sources */, 8CA7CC6F2B77AEB4008E587F /* SearchView.swift in Sources */, 8C2DFCB02C4AA15C003AEC67 /* NewFeaturesView.swift in Sources */, @@ -1320,7 +1317,6 @@ 8CBFF0C02B85E55F00350E0F /* SkinDownloadView.swift in Sources */, B2B813982CC3D22800C69D17 /* BiliBiliAPIService.swift in Sources */, 8CBFF0C82B85E55F00350E0F /* BangumiPlayerView.swift in Sources */, - B2B8139C2CC3D37500C69D17 /* TrendingView.swift in Sources */, 8CBFF0C72B85E55F00350E0F /* VideoDownloadView.swift in Sources */, 03B2F8102C45AED7007EB850 /* PhoneFormatterExt.swift in Sources */, 8CBFF0E32B85E55F00350E0F /* AboutView.swift in Sources */, diff --git a/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme b/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme index 8e551bb00..8245c0519 100644 --- a/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme +++ b/DarockBili.xcodeproj/xcshareddata/xcschemes/Alternative Destribution.xcscheme @@ -1,7 +1,7 @@ + version = "1.8"> + allowLocationSimulation = "YES"> MeowWidgetEntry { - MeowWidgetEntry(date: Date(), videoTitle: "视频名称", videoDescription: "描述", videoAuthor: "作者", videoViews: "播放量") + MeowWidgetEntry(date: Date(), videoTitle: "miku miku oo ee oo", videoDescription: "https://twitter.com/i/status/1697029186777706544 channel(twi:_CASTSTATION)", videoAuthor: "未来de残像", videoViews: "365.4万") } func getSnapshot(in context: Context, completion: @escaping (MeowWidgetEntry) -> ()) { @@ -80,16 +80,13 @@ struct Provider: TimelineProvider { } } -struct MeowWidgetEntryView : View { +struct MeowWidgetEntryView: View { var entry: Provider.Entry @Environment(\.widgetFamily) var family var body: some View { VStack(alignment: .leading) { HStack { - Image("MeowBili") - .resizable() - .frame(width: 24, height: 24) Text("喵哩喵哩") .font(.headline) .foregroundColor(Color("WidgetTitleColor")) @@ -99,7 +96,7 @@ struct MeowWidgetEntryView : View { switch family { case .systemSmall: - Text(entry.videoTitle) + Text("在喵哩喵哩查看视频") .font(.headline) case .systemMedium: @@ -107,22 +104,20 @@ struct MeowWidgetEntryView : View { .font(.headline) Text(entry.videoDescription) .font(.subheadline) - Spacer() - Text("在喵哩喵哩查看更多内容") - .font(.footnote) - .foregroundColor(.gray) case .systemLarge: Text(entry.videoTitle) .font(.headline) Text(entry.videoDescription) .font(.subheadline) - Text("作者: \(entry.videoAuthor)") - .font(.footnote) - Text("播放量: \(entry.videoViews)") - .font(.footnote) + VStack(alignment: .leading) { + Text("作者: \(entry.videoAuthor)") + .font(.footnote) + Text("播放量: \(entry.videoViews)") + .font(.footnote) + } Spacer() - Text("在喵哩喵哩查看更多内容") + Text("在喵哩喵哩查看视频") .font(.footnote) .foregroundColor(.gray) @@ -143,7 +138,6 @@ struct MeowWidgetEntryView : View { } } .padding() - .background(Color("WidgetBackgroundColor")) .widgetURL(URL(string: "meowbili://")!) } } @@ -156,7 +150,7 @@ struct MeowWidget: Widget { StaticConfiguration(kind: kind, provider: Provider()) { entry in MeowWidgetEntryView(entry: entry) } - .configurationDisplayName("喵哩喵哩Widget") + .configurationDisplayName("喵哩喵哩小组件") .description("热门或推荐的视频内容") .supportedFamilies(families) } diff --git a/SharedCode/BiliBiliAPIService.swift b/SharedCode/BiliBiliAPIService.swift index 69e496c12..9dcfd85f7 100644 --- a/SharedCode/BiliBiliAPIService.swift +++ b/SharedCode/BiliBiliAPIService.swift @@ -34,10 +34,8 @@ class BiliBiliAPIService { switch type { case .trending: urlString = "https://api.bilibili.com/x/web-interface/popular?ps=\(limit)" - //这里ps=几就会让返回数据有几条 case .recommendations: urlString = "https://api.bilibili.com/x/web-interface/index/top/rcmd?ps=1" - //这里ps=任何数字都不影响返回值 所以不更改\(limit) } guard let url = URL(string: urlString) else { @@ -45,19 +43,19 @@ class BiliBiliAPIService { } let (data, _) = try await URLSession.shared.data(from: url) - + if let json = try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], let dataDict = json["data"] as? [String: Any], - let list = dataDict["list"] as? [[String: Any]] { + let itemList = dataDict["item"] as? [[String: Any]] { - let videos = list.prefix(limit).map { video -> (String, String, String, String) in + let videos = itemList.prefix(limit).map { video -> (String, String, String, String) in let videoTitle = video["title"] as? String ?? "无标题" let videoDesc = video["desc"] as? String ?? "无描述" - let videoAuthor = video["author"] as? String ?? "未知作者" - let videoViews = video["view"] as? String ?? "未知播放量" - return (title: videoTitle, description: videoDesc, author: videoAuthor, views: videoViews) + let videoAuthor = (video["owner"] as? [String: Any])?["name"] as? String ?? "未知作者" + let videoViews = (video["stat"] as? [String: Any])?["view"] as? Int ?? 0 + return (title: videoTitle, description: videoDesc, author: videoAuthor, views: "\(videoViews)") } - + return .success(videos) } else { return .failure(NSError(domain: "BiliBiliAPIService", code: -1, userInfo: [NSLocalizedDescriptionKey: "数据格式错误"])) @@ -67,4 +65,5 @@ class BiliBiliAPIService { return .failure(error) } } + }