MediaTable.ets 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. import relationalStore from '@ohos.data.relationalStore';
  2. import { LogUtil, StrUtil } from '@pura/harmony-utils';
  3. import { VideoItem } from '../../viewmodel/VideoItem';
  4. import Logger from './Logger';
  5. import RdbUtils from './RdbUtils';
  6. import { Utility } from './Utility';
  7. /**
  8. * 数据库字段常量接口定义
  9. */
  10. interface DBColumnsInterface {
  11. ID: string;
  12. NAME: string;
  13. FILE_PATH: string;
  14. TYPE: string;
  15. VIDEO_SIZE: string;
  16. C_TIME: string;
  17. PARENT_PATH: string;
  18. IS_FAV: string;
  19. PIXEL_MAP_PATH: string;
  20. ARTIST: string;
  21. ALBUM: string;
  22. FILE_NAME: string;
  23. SIZE: string;
  24. DURATION: string;
  25. MIME_TYPE: string;
  26. TRACK_COUNT: string;
  27. SAMPLE_RATE: string;
  28. LAST_PLAYED_STR: string;
  29. PLAY_COUNT: string;
  30. LYRIC_CONTENT: string;
  31. }
  32. /**
  33. * 数据库字段常量,避免硬编码
  34. */
  35. const DB_COLUMNS: DBColumnsInterface = {
  36. ID: 'id',
  37. NAME: 'name',
  38. FILE_PATH: 'filePath',
  39. TYPE: 'mtype',
  40. VIDEO_SIZE: 'videoSize',
  41. C_TIME: 'cTime',
  42. PARENT_PATH: 'parentPath',
  43. IS_FAV: 'isFav',
  44. PIXEL_MAP_PATH: 'pixelMapPath',
  45. ARTIST: 'artist',
  46. ALBUM: 'album',
  47. FILE_NAME: 'fileName',
  48. SIZE: 'size',
  49. DURATION: 'duration',
  50. MIME_TYPE: 'mimeType',
  51. TRACK_COUNT: 'trackCount',
  52. SAMPLE_RATE: 'sampleRate',
  53. LAST_PLAYED_STR: 'lastPlayedStr',
  54. PLAY_COUNT: 'playCount',
  55. LYRIC_CONTENT: 'lyricContent'
  56. };
  57. export default class MediaTable {
  58. private accountTable = new RdbUtils(RdbUtils.MEDIA_TABLE.tableName, RdbUtils.MEDIA_TABLE.sqlCreate,
  59. RdbUtils.MEDIA_TABLE.columns);
  60. constructor(context:Context,callback: Function = () => {
  61. }) {
  62. this.accountTable.getRdbStore(context,callback);
  63. }
  64. getRdbStore(context:Context,callback: Function = () => {
  65. }) {
  66. this.accountTable.getRdbStore(context,callback);
  67. }
  68. insert(item: VideoItem, callback: Function,cover_api?:string) {
  69. const valueBucket: relationalStore.ValuesBucket = generateBucket(item);
  70. this.accountTable.insertData(valueBucket, callback,cover_api);
  71. }
  72. deleteData(item: VideoItem, callback: Function) {
  73. let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  74. predicates.equalTo('id', item.id);
  75. this.accountTable.deleteData(predicates, callback);
  76. }
  77. deleteDataForParentPath(parentPath:string, callback: Function) {
  78. let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  79. predicates.equalTo('parentPath', parentPath);
  80. this.accountTable.deleteData(predicates, callback);
  81. }
  82. public updatePixelMapPath(filePath: string, newPixelMapPath: string, callback: Function) {
  83. // Step 1: 构建查询条件验证文件存在性
  84. const queryPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  85. queryPredicates.equalTo('filePath', filePath);
  86. // Step 2: 执行存在性验证
  87. this.accountTable.query(queryPredicates, (resultSet: relationalStore.ResultSet) => {
  88. if (resultSet.rowCount === 0) {
  89. callback(false, 'Error: Target file not found in database');
  90. resultSet.close();
  91. return;
  92. }
  93. resultSet.close();
  94. // Step 3: 构建更新条件与数据
  95. const updatePredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  96. updatePredicates.equalTo('filePath', filePath);
  97. const valueBucket: relationalStore.ValuesBucket = {
  98. pixelMapPath: newPixelMapPath
  99. };
  100. // Step 4: 执行原子化更新操作
  101. this.accountTable.updateData(updatePredicates, valueBucket, (success: boolean) => {
  102. callback(success, success ? null : 'Database update operation failed');
  103. });
  104. });
  105. }
  106. updateData(item: VideoItem, callback: Function) {
  107. const valueBucket: relationalStore.ValuesBucket = generateBucket(item);
  108. let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  109. predicates.equalTo('id', item.id);
  110. this.accountTable.updateData(predicates, valueBucket, callback);
  111. }
  112. //编辑歌曲的信息更新数据库
  113. public updateMediaInfo(filePath: string, title: string, artist: string, album: string, callback: Function) {
  114. if (!callback || typeof callback !== 'function') {
  115. Logger.info(RdbUtils.RDB_TAG, 'updateMediaInfo() has no valid callback!');
  116. return;
  117. }
  118. if (!this.accountTable) {
  119. Logger.error(RdbUtils.RDB_TAG, 'RdbStore is not initialized.');
  120. callback(false);
  121. return;
  122. }
  123. // Step 1: Create a predicate to find the record by filePath
  124. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  125. predicates.equalTo('filePath', filePath);
  126. // Step 2: Query the database to check if the record exists
  127. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  128. if (resultSet.rowCount === 0) {
  129. Logger.info(RdbUtils.RDB_TAG, `No record found with filePath ${filePath}.`);
  130. callback(false);
  131. resultSet.close();
  132. return;
  133. }
  134. // Step 3: Prepare the values to update
  135. const valuesToUpdate: relationalStore.ValuesBucket = {};
  136. if (title !== '') {
  137. valuesToUpdate.name = title;
  138. }
  139. if (artist !== '') {
  140. valuesToUpdate.artist = artist;
  141. }
  142. if (album !== '') {
  143. valuesToUpdate.album = album;
  144. }
  145. resultSet.close();
  146. // Step 4: Update the record if there are values to update
  147. if (Object.keys(valuesToUpdate).length > 0) {
  148. this.accountTable.updateData(predicates, valuesToUpdate, (success: boolean) => {
  149. callback(success, success ? null : 'Database update operation failed');
  150. });
  151. } else {
  152. Logger.info(RdbUtils.RDB_TAG, 'No fields to update.');
  153. callback(false);
  154. }
  155. });
  156. }
  157. //更新重命名数据操作
  158. public updateRename(newName: string, oldPath: string, newPath: string, callback: Function) {
  159. // Step 1: 查询原始记录
  160. const queryPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  161. queryPredicates.equalTo('filePath', oldPath);
  162. this.accountTable.query(queryPredicates, (resultSet: relationalStore.ResultSet) => {
  163. if (resultSet.rowCount === 0) {
  164. callback(false, 'Error: File not found');
  165. return;
  166. }
  167. resultSet.goToFirstRow();
  168. // Step 3: 构建更新数据
  169. const currentName = resultSet.getString(resultSet.getColumnIndex('name'));
  170. const currentFileName = resultSet.getString(resultSet.getColumnIndex('fileName'));
  171. let obj: relationalStore.ValuesBucket = {};
  172. obj.id = newPath
  173. obj.filePath = newPath;
  174. if (currentName === currentFileName) {
  175. obj.name = newName;
  176. obj.fileName = newName;
  177. } else {
  178. obj.fileName = newName;
  179. }
  180. obj.mtype = resultSet.getDouble(resultSet.getColumnIndex('mtype'));
  181. obj.videoSize = resultSet.getDouble(resultSet.getColumnIndex('videoSize'));
  182. obj.cTime = resultSet.getString(resultSet.getColumnIndex('cTime'));
  183. obj.parentPath = resultSet.getString(resultSet.getColumnIndex('parentPath'));
  184. // obj.pixelMapToString = resultSet.getString(resultSet.getColumnIndex('pixelMapToString'));
  185. obj.artist = resultSet.getString(resultSet.getColumnIndex('artist'));
  186. obj.album = resultSet.getString(resultSet.getColumnIndex('album'));
  187. obj.isFav = resultSet.getDouble(resultSet.getColumnIndex('isFav'));
  188. obj.pixelMapPath = resultSet.getString(resultSet.getColumnIndex('pixelMapPath'));
  189. obj.duration = resultSet.getString(resultSet.getColumnIndex('duration'));
  190. obj.mimeType = resultSet.getString(resultSet.getColumnIndex('mimeType'));
  191. obj.trackCount = resultSet.getString(resultSet.getColumnIndex('trackCount'));
  192. obj.sampleRate = resultSet.getString(resultSet.getColumnIndex('sampleRate'));
  193. obj.lastPlayedStr = resultSet.getString(resultSet.getColumnIndex('lastPlayedStr'));
  194. obj.playCount = resultSet.getDouble(resultSet.getColumnIndex('playCount'));
  195. obj.lyricContent = resultSet.getString(resultSet.getColumnIndex('lyricContent'));
  196. obj.md5Str = resultSet.getString(resultSet.getColumnIndex('md5Str'));
  197. obj.extra_json = resultSet.getString(resultSet.getColumnIndex('extra_json'));
  198. obj.pyStr = resultSet.getString(resultSet.getColumnIndex('pyStr'));
  199. const valueBucket: relationalStore.ValuesBucket = obj
  200. // Step 4: 执行更新
  201. const updatePredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  202. updatePredicates.equalTo('filePath', oldPath);
  203. this.accountTable.updateData(updatePredicates, valueBucket, (success: boolean) => {
  204. callback(success, success ? null : 'Update failed');
  205. });
  206. resultSet.close()
  207. });
  208. }
  209. // 根据isFav查询数据
  210. public queryByisFav(isFav: number, callback: (result: VideoItem[]) => void) {
  211. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  212. predicates.equalTo('isFav', isFav);
  213. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  214. const result = this.parseResultSetToVideoItems(resultSet);
  215. callback(result);
  216. });
  217. }
  218. // 根据filePath更新isFav的值
  219. public updateIsFavByFilePath(filePath: string, isFav: number, callback: (success: boolean, error?: string) => void) {
  220. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  221. predicates.equalTo('filePath', filePath);
  222. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  223. if (resultSet.rowCount === 0) {
  224. callback(false, 'Error: File not found');
  225. resultSet.close();
  226. return;
  227. }
  228. resultSet.close();
  229. const valueBucket: relationalStore.ValuesBucket = { isFav: isFav };
  230. this.accountTable.updateData(predicates, valueBucket, (success: boolean) => {
  231. callback(success, success ? '' : 'Update failed');
  232. });
  233. });
  234. }
  235. // 查询全部,或者某个id(查询的字段,回调,是否查询全部)
  236. query(id: number, callback: Function, isAll: boolean = true) {
  237. let predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  238. if (!isAll) {
  239. predicates.equalTo('id', id);
  240. }
  241. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  242. let count: number = resultSet.rowCount;
  243. if (count === 0 || typeof count === 'string') {
  244. console.log(`${RdbUtils.RDB_TAG}` + 'Query no results!');
  245. callback([]);
  246. } else {
  247. const result = this.parseResultSetToVideoItems(resultSet);
  248. callback(result);
  249. }
  250. });
  251. }
  252. // 新增方法:根据parentPath查询数据
  253. public queryByParentPath(path: string, callback: (result: VideoItem[]) => void) {
  254. try {
  255. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  256. predicates.equalTo('parentPath', path);
  257. LogUtil.info('onecold parentPath = '+path)
  258. // 2. 执行查询并处理结果
  259. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  260. // 3. 复用已有的解析逻辑
  261. const result = this.parseResultSetToVideoItems(resultSet);
  262. callback(result);
  263. });
  264. }catch (err) {
  265. Logger.error(` onecold testtag queryByParentPath: ${err.code} - ${err.message}`);
  266. }
  267. // 1. 构建查询条件
  268. }
  269. // 查询所有艺术家及其歌曲(返回Map结构:artist -> VideoItem[])
  270. public queryArtistsWithSongs(callback: (result: Map<string, VideoItem[]>) => void) {
  271. // 1. 查询去重的艺术家列表(非空)
  272. const artistPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  273. artistPredicates.isNotNull('artist').distinct();
  274. this.accountTable.query(artistPredicates, (resultSet: relationalStore.ResultSet) => {
  275. const artists: string[] = this.parseDistinctColumn(resultSet, 'artist');
  276. // 2. 遍历每个艺术家,查询其歌曲
  277. const resultMap = new Map<string, VideoItem[]>();
  278. let processedCount = 0;
  279. if (artists.length === 0) {
  280. callback(resultMap);
  281. return;
  282. }
  283. artists.forEach(artist => {
  284. const songPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  285. songPredicates.equalTo('artist', artist);
  286. this.accountTable.query(songPredicates, (songResultSet: relationalStore.ResultSet) => {
  287. const songs = this.parseResultSetToVideoItems(songResultSet);
  288. resultMap.set(artist, songs);
  289. processedCount++;
  290. // 3. 全部查询完成后回调
  291. if (processedCount === artists.length) {
  292. callback(resultMap);
  293. }
  294. });
  295. });
  296. });
  297. }
  298. // 查询所有专辑及其歌曲(返回Map结构:album -> VideoItem[])
  299. public queryAlbumsWithSongs(callback: (result: Map<string, VideoItem[]>) => void) {
  300. // 1. 查询去重的专辑列表(非空)
  301. const albumPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  302. albumPredicates.isNotNull('album').distinct();
  303. this.accountTable.query(albumPredicates, (resultSet: relationalStore.ResultSet) => {
  304. const albums: string[] = this.parseDistinctColumn(resultSet, 'album');
  305. // 2. 遍历每个专辑,查询其歌曲
  306. const resultMap = new Map<string, VideoItem[]>();
  307. let processedCount = 0;
  308. if (albums.length === 0) {
  309. callback(resultMap);
  310. return;
  311. }
  312. albums.forEach(album => {
  313. const songPredicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  314. songPredicates.equalTo('album', album);
  315. this.accountTable.query(songPredicates, (songResultSet: relationalStore.ResultSet) => {
  316. const songs = this.parseResultSetToVideoItems(songResultSet);
  317. resultMap.set(album, songs);
  318. processedCount++;
  319. // 3. 全部查询完成后回调
  320. if (processedCount === albums.length) {
  321. callback(resultMap);
  322. }
  323. });
  324. });
  325. });
  326. }
  327. // 解析去重列数据(如artist/album)
  328. private parseDistinctColumn(resultSet: relationalStore.ResultSet, columnName: string): string[] {
  329. const uniqueValues = new Set<string>(); // 使用Set特性自动去重
  330. if (resultSet.rowCount > 0) {
  331. resultSet.goToFirstRow();
  332. for (let i = 0; i < resultSet.rowCount; i++) {
  333. const value = resultSet.getString(resultSet.getColumnIndex(columnName))?.trim(); // 处理空格
  334. if (value) { // 过滤空值
  335. uniqueValues.add(value);
  336. }
  337. if (i < resultSet.rowCount - 1) { // 避免最后一行越界
  338. resultSet.goToNextRow();
  339. }
  340. }
  341. }
  342. resultSet.close();
  343. return Array.from(uniqueValues); // Set转数组
  344. }
  345. // 将ResultSet解析为VideoItem数组(复用原有逻辑)
  346. private parseResultSetToVideoItems(resultSet: relationalStore.ResultSet): VideoItem[] {
  347. const items: VideoItem[] = [];
  348. try {
  349. // 检查结果集是否有效
  350. if (resultSet && resultSet.rowCount > 0) {
  351. while (resultSet.goToNextRow()) {
  352. const item = this.buildVideoItem(resultSet);
  353. items.push(item);
  354. }
  355. }
  356. } catch (err) {
  357. Logger.error(`解析结果集出错: ${err.message}`);
  358. } finally {
  359. // 确保结果集被关闭
  360. if (resultSet) {
  361. resultSet.close();
  362. }
  363. }
  364. return items;
  365. }
  366. // 根据filePath更新lastPlayedStr的值同时playCount值加1
  367. public updateLastPlayedStrByFilePath(filePath: string, lastPlayedStr: string, callback: (success: boolean, error?: string) => void) {
  368. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  369. predicates.equalTo('filePath', filePath);
  370. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  371. if (resultSet.rowCount === 0) {
  372. callback(false, 'Error: File not found');
  373. resultSet.close();
  374. return;
  375. }
  376. // 获取当前的 playCount 值
  377. let currentPlayCount = 0;
  378. if (resultSet.goToFirstRow()) {
  379. currentPlayCount = resultSet.getLong(resultSet.getColumnIndex('playCount'));
  380. }
  381. resultSet.close();
  382. // 计算新的 playCount 值
  383. const newPlayCount = currentPlayCount + 1;
  384. // 准备要更新的值
  385. const valueBucket: relationalStore.ValuesBucket = {
  386. lastPlayedStr: lastPlayedStr,
  387. playCount: newPlayCount
  388. };
  389. // 更新数据
  390. this.accountTable.updateData(predicates, valueBucket, (success: boolean) => {
  391. callback(success, success ? '' : 'Update failed');
  392. });
  393. });
  394. }
  395. // 根据最近播放时间查询指定数量的记录
  396. public queryRecentPlayedRecords(count: number, callback: (result: VideoItem[]) => void) {
  397. try {
  398. // 1. 构建查询条件:按lastPlayedStr降序排列,限制返回条数,且lastPlayedStr不为空
  399. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  400. // 添加筛选条件,确保lastPlayedStr不为空
  401. predicates.isNotNull('lastPlayedStr');
  402. predicates.notEqualTo('lastPlayedStr', ''); // 排除空字符串
  403. // 使用 orderByDesc 方法进行降序排序
  404. predicates.orderByDesc('lastPlayedStr');
  405. // 使用 limit 方法限制返回的记录数量
  406. predicates.limitAs(count);
  407. // 2. 执行查询并处理结果
  408. this.accountTable.query(predicates, (resultSet: relationalStore.ResultSet) => {
  409. // 3. 复用已有的解析逻辑
  410. const result = this.parseResultSetToVideoItems(resultSet);
  411. callback(result);
  412. });
  413. } catch (err) {
  414. Logger.error(`queryRecentPlayedRecords error: ${err.code} - ${err.message}`);
  415. callback([]);
  416. }
  417. }
  418. // 清空播放历史记录
  419. public clearPlayHistory(callback: (success: boolean, error?: string) => void) {
  420. // 1. 构建查询条件:筛选lastPlayedStr非空的记录
  421. const predicates = new relationalStore.RdbPredicates(RdbUtils.MEDIA_TABLE.tableName);
  422. predicates.isNotNull('lastPlayedStr');
  423. // 2. 准备更新数据:将lastPlayedStr设为空字符串
  424. const valueBucket: relationalStore.ValuesBucket = {
  425. lastPlayedStr: ''
  426. };
  427. // 3. 执行批量更新操作
  428. this.accountTable.updateData(predicates, valueBucket, (success: boolean) => {
  429. // 将 null 替换为 undefined
  430. callback(success, success ? 'Clear play history success' : 'Clear play history operation failed');
  431. });
  432. }
  433. private buildVideoItem(rs: relationalStore.ResultSet): VideoItem {
  434. // 添加空值保护
  435. const safeGet = (col: string) => {
  436. const index = rs.getColumnIndex(col);
  437. return index >= 0 ? rs.getString(index) || '' : '';
  438. };
  439. const safeGetNumber = (col: string) => {
  440. const index = rs.getColumnIndex(col);
  441. return index >= 0 ? rs.getDouble(index) || 0 : 0;
  442. };
  443. let item = new VideoItem(
  444. safeGet(DB_COLUMNS.NAME),
  445. safeGet(DB_COLUMNS.ID),
  446. safeGet(DB_COLUMNS.FILE_PATH),
  447. safeGetNumber(DB_COLUMNS.TYPE),
  448. safeGetNumber(DB_COLUMNS.VIDEO_SIZE),
  449. safeGet(DB_COLUMNS.C_TIME),
  450. undefined,
  451. safeGet(DB_COLUMNS.SIZE),
  452. safeGet(DB_COLUMNS.PIXEL_MAP_PATH),
  453. safeGet(DB_COLUMNS.ARTIST),
  454. safeGet(DB_COLUMNS.ALBUM),
  455. safeGet(DB_COLUMNS.FILE_NAME)
  456. );
  457. // 设置额外属性,添加安全检查
  458. item.isFav = safeGetNumber(DB_COLUMNS.IS_FAV);
  459. item.duration = safeGet(DB_COLUMNS.DURATION);
  460. item.mimeType = safeGet(DB_COLUMNS.MIME_TYPE);
  461. item.trackCount = safeGet(DB_COLUMNS.TRACK_COUNT);
  462. item.sampleRate = safeGet(DB_COLUMNS.SAMPLE_RATE);
  463. item.lastPlayedStr = safeGet(DB_COLUMNS.LAST_PLAYED_STR);
  464. item.playCount = safeGetNumber(DB_COLUMNS.PLAY_COUNT);
  465. item.lyricContent = safeGet(DB_COLUMNS.LYRIC_CONTENT);
  466. item.md5Str = safeGet('md5Str');
  467. item.extra_json = safeGet('extra_json');
  468. item.pyStr = safeGet('pyStr');
  469. return item;
  470. }
  471. }
  472. function generateBucket(item: VideoItem): relationalStore.ValuesBucket {
  473. let obj: relationalStore.ValuesBucket = {};
  474. obj.id = item.id
  475. obj.name = item.name;
  476. obj.filePath = item.filePath;
  477. obj.mtype = item.type;
  478. obj.videoSize = item.videoSize;
  479. obj.cTime = item.cTime;
  480. obj.parentPath = item.parentPath;
  481. obj.isFav = item.isFav;
  482. // if(item.pixelMapToString){
  483. // obj.pixelMapToString = item.pixelMapToString;
  484. // }
  485. if(item.artist){
  486. obj.artist = item.artist;
  487. }
  488. if(item.album){
  489. obj.album = item.album;
  490. }
  491. if(item.fileName){
  492. obj.fileName = item.fileName;
  493. }
  494. if(item.size){
  495. obj.size = item.size;
  496. }
  497. if(item.pixelMapPath){
  498. obj.pixelMapPath = item.pixelMapPath;
  499. }
  500. if(item.duration){
  501. obj.duration = item.duration;
  502. }
  503. if(item.mimeType){
  504. obj.mimeType = item.mimeType;
  505. }
  506. if(item.trackCount){
  507. obj.trackCount = item.trackCount;
  508. }
  509. if(item.sampleRate){
  510. obj.sampleRate = item.sampleRate;
  511. }
  512. if(item.lastPlayedStr){
  513. obj.lastPlayedStr = item.lastPlayedStr;
  514. }
  515. if(item.playCount){
  516. obj.playCount = item.playCount;
  517. }
  518. if(item.lyricContent){
  519. obj.lyricContent = item.lyricContent;
  520. }
  521. if(item.md5Str){
  522. obj.md5Str = item.md5Str;
  523. }
  524. if(item.extra_json){
  525. obj.extra_json = item.extra_json;
  526. }
  527. if(item.pyStr){
  528. obj.pyStr = item.pyStr;
  529. }
  530. return obj;
  531. }