valeriangalliat / spotify-buddylist

Fetch the friend activity Spotify feed.
125 stars 8 forks source link

For idiots pls #1

Closed iCrowd closed 3 years ago

iCrowd commented 3 years ago

I hope its ok to write here. Im not into coding or something like that i just wanted to use this script so i got node and node-fetch, installed it etc. bun when i try to run the the index.js i get a Syntax Error. Can you please explain for idiots how to set it up properly?

valeriangalliat commented 3 years ago

Hey! I took a shortcut in the script example so it makes sense you get a syntax error, here's what it should look like:

const buddyList = require('spotify-buddylist')

async function main () {
  const spDcCookie = 'put your cookie here'
  const { accessToken } = await buddyList.getWebAccessToken(spDcCookie)
  const friendActivity = await buddyList.getFriendActivity(accessToken)

  console.log(JSON.stringify(friendActivity, null, 2))
}

main()
  .catch(err => {
    console.error(err)
    process.exit(1)
  })

If you installed this using npm install spotify-buddylist that should be all you need. If you downloaded the source of this project directly, make sure your script file is in the same directory as the index.js from this project, and replace the first line of the example with:

const buddyList = require('./')

I'll update the instructions in the readme to make all of that more clear. Lmk if this helps!

iCrowd commented 3 years ago

Thank you very much i now got it to work. But i do i have to run the script everytime Because i wanted something to collect all the data of what friends hear(one in particular) and put it in like a txt, while im not on my pc to see it by myself. Can i somehow convert the timestamp given to "normal" time? Sorry for the dumb questions :D

valeriangalliat commented 3 years ago

Awesome! Oh yeah, to do that you'd need to learn a little bit of JavaScript. The setInterval function would help you run something periodically like:

setInterval(() => {
  main()
    .catch(err => {
      console.error(err)
    })
}, 1000 * 60)

That would run the main function every 60 seconds.

The timestamp field is the number of milliseconds since January 1st, 1970, it's a common representation of time in programming. You can parse it with the Date object:

console.log(new Date(friendActivity.friends[0].timestamp).toString())

That'll give you a human representation of the timestamp from the Spotify response.

If you want to learn more like writing to files and stuff you should look for JavaScript and Node.js tutorials, courses or books, there a ton online! Cheers =)

iCrowd commented 3 years ago

Thank you very much. I already did the thing with interval and that it give me the current time each time it repeats, but yours it better. Thank you very much for your kindness.