JXDramaContent.m 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //
  2. // JXDramaContent.m
  3. // AICity
  4. //
  5. // Created by TogetherWatch on 2025-10-20.
  6. // Feature: 010-ui-ios - iOS平台完整功能实现(对标Android)
  7. //
  8. #import "JXDramaContent.h"
  9. @implementation JXDramaContent
  10. #pragma mark - 初始化方法
  11. - (instancetype)init {
  12. self = [super init];
  13. if (self) {
  14. _dramaId = 0;
  15. _likeCount = 0;
  16. _isLiked = NO;
  17. _favoriteCount = 0;
  18. _isFavorited = NO;
  19. _commentCount = 0;
  20. }
  21. return self;
  22. }
  23. - (instancetype)initWithDictionary:(NSDictionary *)dict {
  24. self = [super init];
  25. if (self) {
  26. // URL播放方式
  27. _videoUrl = dict[@"video_url"];
  28. _drmToken = dict[@"drmToken"];
  29. // FileID播放方式(DRM推荐)
  30. _appId = dict[@"appId"];
  31. _fileId = dict[@"fileId"];
  32. _psign = dict[@"psign"];
  33. _episodeId = dict[@"episodeId"];
  34. // 短剧标识 - 优先使用 "jx_drama_id"(剧星平台ID),用于后端查询
  35. _dramaId = [dict[@"jx_drama_id"] longLongValue] ?: [dict[@"id"] longLongValue];
  36. // 用户交互数据
  37. _likeCount = [dict[@"like_count"] longLongValue];
  38. _isLiked = [dict[@"isLiked"] boolValue];
  39. _favoriteCount = [dict[@"favorite_count"] longLongValue];
  40. _isFavorited = [dict[@"isFavorited"] boolValue];
  41. _commentCount = [dict[@"comment_count"] longLongValue];
  42. // 播放信息 - 后端返回 "cover" 或 "vertical_cover"
  43. _title = dict[@"title"];
  44. _coverUrl = dict[@"vertical_cover"] ?: dict[@"cover"]; // 优先使用竖版封面
  45. // 注:description 字段已通过后端返回,但在这里暂时跳过以避免属性冲突
  46. // 如需要可在需要时单独处理
  47. _descriptions = dict[@"description"] ?: dict[@"description"]; // 优先使用竖版封面
  48. }
  49. return self;
  50. }
  51. + (instancetype)dramaContentWithDictionary:(NSDictionary *)dict {
  52. return [[self alloc] initWithDictionary:dict];
  53. }
  54. - (NSDictionary *)toDictionary {
  55. NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  56. // URL播放方式
  57. if (self.videoUrl) dict[@"video_url"] = self.videoUrl;
  58. if (self.drmToken) dict[@"drmToken"] = self.drmToken;
  59. // FileID播放方式
  60. if (self.appId) dict[@"appId"] = self.appId;
  61. if (self.fileId) dict[@"fileId"] = self.fileId;
  62. if (self.psign) dict[@"psign"] = self.psign;
  63. if (self.episodeId) dict[@"episodeId"] = self.episodeId;
  64. // 短剧标识
  65. dict[@"dramaId"] = @(self.dramaId);
  66. // 用户交互数据
  67. dict[@"like_count"] = @(self.likeCount);
  68. dict[@"isLiked"] = @(self.isLiked);
  69. dict[@"favorite_count"] = @(self.favoriteCount);
  70. dict[@"isFavorited"] = @(self.isFavorited);
  71. dict[@"comment_count"] = @(self.commentCount);
  72. // 播放信息
  73. if (self.title) dict[@"title"] = self.title;
  74. if (self.coverUrl) dict[@"coverUrl"] = self.coverUrl;
  75. if (self.description) dict[@"description"] = self.description;
  76. if (self.descriptions) dict[@"descriptions"] = self.descriptions;
  77. return [dict copy];
  78. }
  79. #pragma mark - 辅助方法
  80. - (BOOL)isFileIdMode {
  81. return (self.appId.length > 0 &&
  82. self.fileId.length > 0 &&
  83. self.psign.length > 0);
  84. }
  85. - (BOOL)isUrlMode {
  86. return self.videoUrl.length > 0;
  87. }
  88. #pragma mark - NSObject
  89. - (NSString *)description {
  90. return [NSString stringWithFormat:@"<JXDramaContent: dramaId=%lld, title=%@, isFileIdMode=%@, isUrlMode=%@>",
  91. self.dramaId,
  92. self.title ?: @"(null)",
  93. @(self.isFileIdMode),
  94. @(self.isUrlMode)];
  95. }
  96. @end