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.49 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 artist = []
  15. const artistMs=[]
  16.  
  17. Object.entries(data0).forEach((indiv) => { // Run through each object in json
  18. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  19. 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
  20. if (!artist.includes(indiv[1]['artistName'])){
  21. artist.push(indiv[1]['artistName'])
  22. artistMs.push(indiv[1]['msPlayed'])
  23. }
  24. else {
  25. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  26. }
  27. }
  28. });
  29. Object.entries(data1).forEach((indiv) => {
  30. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  31. 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
  32. if (!artist.includes(indiv[1]['artistName'])){
  33. artist.push(indiv[1]['artistName'])
  34. artistMs.push(indiv[1]['msPlayed'])
  35. }
  36. else {
  37. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  38. }
  39. }
  40. });
  41. Object.entries(data2).forEach((indiv) => {
  42. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  43. 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
  44. if (!artist.includes(indiv[1]['artistName'])){
  45. artist.push(indiv[1]['artistName'])
  46. artistMs.push(indiv[1]['msPlayed'])
  47. }
  48. else {
  49. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  50. }
  51. }
  52. });
  53. Object.entries(data3).forEach((indiv) => {
  54. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  55. 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
  56. if (!artist.includes(indiv[1]['artistName'])){
  57. artist.push(indiv[1]['artistName'])
  58. artistMs.push(indiv[1]['msPlayed'])
  59. }
  60. else {
  61. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  62. }
  63. }
  64. });
  65. Object.entries(data4).forEach((indiv) => {
  66. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  67. 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
  68. if (!artist.includes(indiv[1]['artistName'])){
  69. artist.push(indiv[1]['artistName'])
  70. artistMs.push(indiv[1]['msPlayed'])
  71. }
  72. else {
  73. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  74. }
  75. }
  76. });
  77. Object.entries(data5).forEach((indiv) => {
  78. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  79. 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
  80. if (!artist.includes(indiv[1]['artistName'])){
  81. artist.push(indiv[1]['artistName'])
  82. artistMs.push(indiv[1]['msPlayed'])
  83. }
  84. else {
  85. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  86. }
  87. }
  88. });
  89. Object.entries(data6).forEach((indiv) => {
  90. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  91. 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
  92. if (!artist.includes(indiv[1]['artistName'])){
  93. artist.push(indiv[1]['artistName'])
  94. artistMs.push(indiv[1]['msPlayed'])
  95. }
  96. else {
  97. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  98. }
  99. }
  100. });
  101. Object.entries(data7).forEach((indiv) => {
  102. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  103. 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
  104. if (!artist.includes(indiv[1]['artistName'])){
  105. artist.push(indiv[1]['artistName'])
  106. artistMs.push(indiv[1]['msPlayed'])
  107. }
  108. else {
  109. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  110. }
  111. }
  112. });
  113. Object.entries(data8).forEach((indiv) => {
  114. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  115. 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
  116. if (!artist.includes(indiv[1]['artistName'])){
  117. artist.push(indiv[1]['artistName'])
  118. artistMs.push(indiv[1]['msPlayed'])
  119. }
  120. else {
  121. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  122. }
  123. }
  124. });
  125. Object.entries(data9).forEach((indiv) => {
  126. month = `${indiv[1]['endTime'][5]}${indiv[1]['endTime'][6]}` //stores the current object month
  127. 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
  128. if (!artist.includes(indiv[1]['artistName'])){
  129. artist.push(indiv[1]['artistName'])
  130. artistMs.push(indiv[1]['msPlayed'])
  131. }
  132. else {
  133. artistMs[artist.indexOf(indiv[1]['artistName'])] += indiv[1]['msPlayed']
  134. }
  135. }
  136. });
  137.  
  138. // if you listen to alot just copy paste add another data variable and import json again
  139.  
  140. // Object.entries(data10).forEach((indiv) => {
  141. // if (indiv[1]['endTime'][3] === '4'){
  142. // msTotal += indiv[1]['msPlayed']
  143. // }
  144. // });
  145.  
  146. // let artistCombine = []
  147. // artist.forEach((current, idx) => {
  148. // artistCombine[current] = current
  149. // artistCombine[current]["time"] = artistMs[idx]
  150. // })
  151. //console.log(Math.max(...artistMs))
  152. idxTop = artistMs.indexOf(Math.max(...artistMs))
  153. console.log("\nYour Top Artist : " + artist[idxTop])
  154. console.log("You have listen to " + artist[idxTop] + " for " + (Math.max(...artistMs)/60000) + " minutes or " + (Math.max(...artistMs)/60000/60)+ " hours.\n")
  155.  
  156. artistMs.splice(idxTop, 1)
  157. artist.splice(idxTop, 1)
  158.  
  159. // console.log(Math.max(...songMs))
  160. //console.log(Math.max(...artistMs))
  161. idxTop = artistMs.indexOf(Math.max(...artistMs))
  162. console.log("Your 2nd Top Artist : " + artist[idxTop])
  163. console.log("You have listen to " + artist[idxTop] + " for " + (Math.max(...artistMs)/60000) + " minutes or " + (Math.max(...artistMs)/60000/60)+ " hours.\n")
  164.  
  165. artistMs.splice(idxTop, 1)
  166. artist.splice(idxTop, 1)
  167.  
  168. // console.log(Math.max(...songMs))
  169. //console.log(Math.max(...artistMs))
  170. idxTop = artistMs.indexOf(Math.max(...artistMs))
  171. console.log("Your 3rd Top Artist : " + artist[idxTop])
  172. console.log("You have listen to " + artist[idxTop] + " for " + (Math.max(...artistMs)/60000) + " minutes or " + (Math.max(...artistMs)/60000/60)+ " hours.\n")
  173.  
  174. artistMs.splice(idxTop, 1)
  175. artist.splice(idxTop, 1)
  176.  
  177. // console.log(Math.max(...songMs))
  178. //console.log(Math.max(...artistMs))
  179. idxTop = artistMs.indexOf(Math.max(...artistMs))
  180. console.log("Your 4th Top Artist : " + artist[idxTop])
  181. console.log("You have listen to " + artist[idxTop] + " for " + (Math.max(...artistMs)/60000) + " minutes or " + (Math.max(...artistMs)/60000/60)+ " hours.\n")
  182.  
  183. artistMs.splice(idxTop, 1)
  184. artist.splice(idxTop, 1)
  185.  
  186. // console.log(Math.max(...songMs))
  187. //console.log(Math.max(...artistMs))
  188. idxTop = artistMs.indexOf(Math.max(...artistMs))
  189. console.log("Your 5th Top Artist : " + artist[idxTop])
  190. console.log("You have listen to " + artist[idxTop] + " for " + (Math.max(...artistMs)/60000) + " minutes or " + (Math.max(...artistMs)/60000/60)+ " hours.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement