searches.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. const plist = require('../../../util/plist')
  2. const fs = require('fs')
  3. // Derive filenames based on domain + file path
  4. const fileHash = require('../../../util/backup_filehash')
  5. const database = fileHash('Library/Preferences/com.spotify.client.plist', 'AppDomain-com.spotify.client')
  6. module.exports = {
  7. version: 4,
  8. name: 'spotify.searches',
  9. description: `List associated Spotify account and its usage information`,
  10. requiresBackup: true,
  11. // Run on a v3 lib / backup object.
  12. run (lib, { backup }) {
  13. return spotifyReport(backup)
  14. },
  15. // Fields for apps report
  16. output: {
  17. 'Username': el => el.username,
  18. 'Type': el => el.placeholderIconIdentifier ? el.placeholderIconIdentifier.toLowerCase() : 'song',
  19. 'Title': el => el.title,
  20. 'Subtitle': el => el.subtitle
  21. }
  22. }
  23. const spotifyReport = (backup) => {
  24. return new Promise((resolve, reject) => {
  25. var filename = backup.getFileName(database)
  26. try {
  27. let spotifyData = plist.parseFile(filename)
  28. let spotifyResult = []
  29. console.log('spotifyData', spotifyData)
  30. // Get spotify username
  31. if (Object.keys(spotifyData).some((key) => ~key.indexOf('.com.spotify'))) {
  32. const keys = Object.keys(spotifyData).filter((key) => ~key.indexOf('.com.spotify'))
  33. const username = keys[0].split('.com.spotify')[0]
  34. // Get spotify search history
  35. const searchHistory = spotifyData[username + '.com.spotify.feature.search.com.spotify.search.fancyRecents']
  36. searchHistory.forEach(element => {
  37. element.username = username
  38. })
  39. spotifyResult = searchHistory
  40. }
  41. resolve(spotifyResult)
  42. } catch (e) {
  43. reject(e)
  44. }
  45. })
  46. }