spotify.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. const log = require('../util/log')
  2. const path = require('path')
  3. const sqlite3 = require('sqlite3')
  4. const bplist = require('bplist-parser')
  5. const fs = require('fs')
  6. const plist = require('plist')
  7. // Derive filenames based on domain + file path
  8. const fileHash = require('../util/backup_filehash')
  9. const database = fileHash('Library/Preferences/com.spotify.client.plist', 'AppDomain-com.spotify.client')
  10. module.exports.name = 'spotify'
  11. module.exports.description = 'List associated Spotify account and its usage information'
  12. // Specify this reporter requires a backup.
  13. // The second parameter to func() is now a backup instead of the path to one.
  14. module.exports.requiresBackup = true
  15. // Specify this reporter supports the promises API for allowing chaining of reports.
  16. module.exports.usesPromises = true
  17. module.exports.func = function (program, backup, resolve, reject) {
  18. spotifyReport(backup)
  19. .then((items) => {
  20. var result = program.formatter.format(items, {
  21. program: program,
  22. columns: {
  23. 'Username': el => el.username,
  24. 'Type': el => el.placeholderIconIdentifier ? el.placeholderIconIdentifier.toLowerCase() : 'song',
  25. 'Title': el => el.title,
  26. 'Subtitle': el => el.subtitle
  27. }
  28. })
  29. resolve(result)
  30. })
  31. .catch(reject)
  32. }
  33. const spotifyReport = (backup) => {
  34. return new Promise((resolve, reject) => {
  35. var filename = backup.getFileName(database)
  36. try {
  37. let spotifyData = bplist.parseBuffer(fs.readFileSync(filename))[0]
  38. let spotifyResult = []
  39. /*
  40. wifiList['List of known networks'] = wifiList['List of known networks']
  41. .map(el => {
  42. if (el.BSSID) {
  43. el.BSSID = macParse.pad_zeros(el.BSSID) + ''
  44. }
  45. return el
  46. })*/
  47. //console.log('spotifyData', spotifyData)
  48. //Get spotify username
  49. if (Object.keys(spotifyData).some((key) => ~key.indexOf(".com.spotify"))) {
  50. const keys = Object.keys(spotifyData).filter((key) => ~key.indexOf(".com.spotify"))
  51. const username = keys[0].split(".com.spotify")[0]
  52. //Get spotify search history
  53. const searchHistory = spotifyData[username + '.com.spotify.feature.search.com.spotify.search.fancyRecents']
  54. searchHistory.forEach(element => {
  55. element.username = username
  56. });
  57. spotifyResult = searchHistory
  58. }
  59. resolve(spotifyResult)
  60. } catch (e) {
  61. reject(e)
  62. }
  63. })
  64. }