Advertisement
Guest User

Untitled

a guest
Dec 4th, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.81 KB | None | 0 0
  1. const data0 = require('./StreamingHistory_music_0.json') // All data put your own steaming history json
  2. const data1 = require('./StreamingHistory_music_1.json')
  3. const data2 = require('./StreamingHistory_music_2.json')
  4. const data3 = require('./StreamingHistory_music_3.json')
  5. const data4 = require('./StreamingHistory_music_4.json')
  6. const data5 = require('./StreamingHistory_music_5.json')
  7. const data6 = require('./StreamingHistory_music_6.json')
  8. const data7 = require('./StreamingHistory_music_7.json')
  9. const data8 = require('./StreamingHistory_music_8.json')
  10. const data9 = require('./StreamingHistory_music_9.json')
  11. const data10 = require('./StreamingHistory_music_10.json')
  12.  
  13. let month = "" // Check for month
  14. const song = []
  15. const artist = []
  16. const songMs=[]
  17.  
  18. Object.entries(data0).forEach((indiv) => { // Run through each object in json
  19. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  20. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  21. if (!song.includes(indiv[1]['trackName'])){
  22. song.push(indiv[1]['trackName'])
  23. artist.push(indiv[1]['artistName'])
  24. songMs.push(indiv[1]['msPlayed'])
  25. }
  26. else {
  27. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  28. }
  29. }
  30. });
  31. Object.entries(data1).forEach((indiv) => {
  32. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  33. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  34. if (!song.includes(indiv[1]['trackName'])){
  35. song.push(indiv[1]['trackName'])
  36. artist.push(indiv[1]['artistName'])
  37. songMs.push(indiv[1]['msPlayed'])
  38. }
  39. else {
  40. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  41. }
  42. }
  43. });
  44. Object.entries(data2).forEach((indiv) => {
  45. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  46. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  47. if (!song.includes(indiv[1]['trackName'])){
  48. song.push(indiv[1]['trackName'])
  49. artist.push(indiv[1]['artistName'])
  50. songMs.push(indiv[1]['msPlayed'])
  51. }
  52. else {
  53. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  54. }
  55. }
  56. });
  57. Object.entries(data3).forEach((indiv) => {
  58. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  59. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  60. if (!song.includes(indiv[1]['trackName'])){
  61. song.push(indiv[1]['trackName'])
  62. artist.push(indiv[1]['artistName'])
  63. songMs.push(indiv[1]['msPlayed'])
  64. }
  65. else {
  66. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  67. }
  68. }
  69. });
  70. Object.entries(data4).forEach((indiv) => {
  71. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  72. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  73. if (!song.includes(indiv[1]['trackName'])){
  74. song.push(indiv[1]['trackName'])
  75. artist.push(indiv[1]['artistName'])
  76. songMs.push(indiv[1]['msPlayed'])
  77. }
  78. else {
  79. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  80. }
  81. }
  82. });
  83. Object.entries(data5).forEach((indiv) => {
  84. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  85. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  86. if (!song.includes(indiv[1]['trackName'])){
  87. song.push(indiv[1]['trackName'])
  88. artist.push(indiv[1]['artistName'])
  89. songMs.push(indiv[1]['msPlayed'])
  90. }
  91. else {
  92. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  93. }
  94. }
  95. });
  96. Object.entries(data6).forEach((indiv) => {
  97. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  98. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  99. if (!song.includes(indiv[1]['trackName'])){
  100. song.push(indiv[1]['trackName'])
  101. artist.push(indiv[1]['artistName'])
  102. songMs.push(indiv[1]['msPlayed'])
  103. }
  104. else {
  105. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  106. }
  107. }
  108. });
  109. Object.entries(data7).forEach((indiv) => {
  110. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  111. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  112. if (!song.includes(indiv[1]['trackName'])){
  113. song.push(indiv[1]['trackName'])
  114. artist.push(indiv[1]['artistName'])
  115. songMs.push(indiv[1]['msPlayed'])
  116. }
  117. else {
  118. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  119. }
  120. }
  121. });
  122. Object.entries(data8).forEach((indiv) => {
  123. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  124. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  125. if (!song.includes(indiv[1]['trackName'])){
  126. song.push(indiv[1]['trackName'])
  127. artist.push(indiv[1]['artistName'])
  128. songMs.push(indiv[1]['msPlayed'])
  129. }
  130. else {
  131. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  132. }
  133. }
  134. });
  135. Object.entries(data9).forEach((indiv) => {
  136. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  137. if (indiv[1]['endTime'][3] === '4' && month !== "11"){ // check if it ends in 4 meaning 2024 and if the month is not 11 meaning only takes from 1 jan to 31 oct
  138. if (!song.includes(indiv[1]['trackName'])){
  139. song.push(indiv[1]['trackName'])
  140. artist.push(indiv[1]['artistName'])
  141. songMs.push(indiv[1]['msPlayed'])
  142. }
  143. else {
  144. songMs[song.indexOf(indiv[1]['trackName'])] += indiv[1]['msPlayed']
  145. }
  146. }
  147. });
  148.  
  149. // if you listen to alot just copy paste add another data variable and import json again
  150.  
  151. // Object.entries(data10).forEach((indiv) => {
  152. // if (indiv[1]['endTime'][3] === '4'){
  153. // msTotal += indiv[1]['msPlayed']
  154. // }
  155. // });
  156.  
  157. // let songCombine = []
  158. // song.forEach((current, idx) => {
  159. // songCombine[current] = current
  160. // songCombine[current]["time"] = songMs[idx]
  161. // })
  162. let copyMs = [...songMs]
  163.  
  164. // console.log(Math.max(...songMs))
  165. idxTop = songMs.indexOf(Math.max(...songMs))
  166. console.log("\nYour Top song : " + song[idxTop] + " by " + artist[idxTop])
  167. console.log("You have listen to " + song[idxTop] + " for " + (Math.max(...songMs)/60000) + " minutes or " + (Math.max(...songMs)/60000/60)+ " hours.\n")
  168.  
  169. songMs.splice(idxTop, 1)
  170. song.splice(idxTop, 1)
  171. artist.splice(idxTop,1)
  172.  
  173. // console.log(Math.max(...songMs))
  174. idxTop = songMs.indexOf(Math.max(...songMs))
  175. console.log("Your 2nd Top song : " + song[idxTop] + " by " + artist[idxTop])
  176. console.log("You have listen to " + song[idxTop] + " for " + (Math.max(...songMs)/60000) + " minutes or " + (Math.max(...songMs)/60000/60)+ " hours.\n")
  177.  
  178. songMs.splice(idxTop, 1)
  179. song.splice(idxTop, 1)
  180. artist.splice(idxTop,1)
  181.  
  182. // console.log(Math.max(...songMs))
  183. idxTop = songMs.indexOf(Math.max(...songMs))
  184. console.log("Your 3rd Top song : " + song[idxTop] + " by " + artist[idxTop])
  185. console.log("You have listen to " + song[idxTop] + " for " + (Math.max(...songMs)/60000) + " minutes or " + (Math.max(...songMs)/60000/60)+ " hours.\n")
  186.  
  187. songMs.splice(idxTop, 1)
  188. song.splice(idxTop, 1)
  189. artist.splice(idxTop,1)
  190.  
  191. // console.log(Math.max(...songMs))
  192. idxTop = songMs.indexOf(Math.max(...songMs))
  193. console.log("Your 4th Top song : " + song[idxTop] + " by " + artist[idxTop])
  194. console.log("You have listen to " + song[idxTop] + " for " + (Math.max(...songMs)/60000) + " minutes or " + (Math.max(...songMs)/60000/60)+ " hours.\n")
  195.  
  196. songMs.splice(idxTop, 1)
  197. song.splice(idxTop, 1)
  198. artist.splice(idxTop,1)
  199.  
  200. // console.log(Math.max(...songMs))
  201. idxTop = songMs.indexOf(Math.max(...songMs))
  202. console.log("Your 5th Top song : " + song[idxTop] + " by " + artist[idxTop])
  203. console.log("You have listen to " + song[idxTop] + " for " + (Math.max(...songMs)/60000) + " minutes or " + (Math.max(...songMs)/60000/60)+ " hours.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement