Skip to content

Instantly share code, notes, and snippets.

View gate5th's full-sized avatar

Michael Bruns gate5th

View GitHub Profile
@gate5th
gate5th / spotifyFunctions.js
Last active September 17, 2018 03:34
oldschoolshuffle
//spotifyFunctions.js
import Spotify from 'spotify-web-api-js';
import uniq from 'lodash.uniq';
import flatten from 'lodash.flatten';
import chunk from 'lodash.chunk';
const spotifyApi = new Spotify();
export function redirectUrlToSpotifyForLogin(){
@gate5th
gate5th / .env
Last active September 17, 2018 03:33
oldschoolshuffle
//.env file. Don't include this comment
REACT_APP_COSMIC_BUCKET=yourAppNameAkaCosmicBucketSlug
REACT_APP_SPOTIFY_CLIENT_ID=asdfghjk1223kjhdf78sdfkjh2kjdsfkjdsf8
REACT_APP_SPOTIFY_DEVELOPMENT_REDIRECT_URI=http://localhost:3000
REACT_APP_SPOTIFY_PRODUCTION_REDIRECT_URI=http://oldschoolshuffle.cosmicapp1.co
@gate5th
gate5th / spotifyFunctions.js
Last active September 17, 2018 03:33
oldschoolshuffle
//spotifyFunctions.js
import Spotify from 'spotify-web-api-js';
import uniq from 'lodash.uniq';
import flatten from 'lodash.flatten';
import chunk from 'lodash.chunk';
export function redirectUrlToSpotifyForLogin(){
const CLIENT_ID = process.env.REACT_APP_SPOTIFY_CLIENT_ID;
const REDIRECT_URI =
@gate5th
gate5th / Procfile
Created September 17, 2018 03:02
oldschoolshuffle
web: npm run productionstart
@gate5th
gate5th / package.json
Last active September 17, 2018 02:58
oldschoolshuffle
{
"name": "oldschoolshuffle",
"version": "0.1.0",
"private": true,
"engines": {
"node": "7.10.0"
},
"dependencies": {
"@material-ui/core": "^3.0.1",
"cosmicjs": "^3.2.12",
@gate5th
gate5th / app.js
Last active September 17, 2018 02:52
oldschoolshuffle
//app.js in your ROOT directory
const express = require("express");
const path = require("path");
const app = express();
// Serve static files from the React app
app.use(express.static(path.join(__dirname, "build")));
@gate5th
gate5th / spotifyFunctions.js
Last active September 17, 2018 01:57
oldschoolshuffle
//spotifyFunctions.js
//waiting for the API to be fixed so can't use spotify-web-api-js library
//for playlist stuff. Creating this global variable to hold the accessToken
//and use it manually for our temporary playlist function. Once the JMPerez library
//is fixed then can go back to just using it.
//Playlist API issues: https://developer.spotify.com/community/news/2018/06/12/changes-to-playlist-uris/
let globalAccessToken = "";
@gate5th
gate5th / spotifyFunctions.js
Created September 12, 2018 19:05
oldschoolshuffle
async function createPlaylist(simplifiedTrackArray, playlistName, addRelatedDiscography) {
//have to get userId, create a playlist in spotify with the name, and then add the tracks to it
//options is whether to addDiscography
//Note that Spotify is very picky about what counts as an 'active device' so likely don't have permission to press
//play. Also only works if the user has premium. Also spotify will only let you add 100 tracks
//per addTracksToPlaylist request, so need to split the trackUris up if more than 100 tracks
const maxTracksToAddInEachRequest = 100;
const userInfoResponse = await spotifyApi.getMe();
const name = `${playlistName} - Album Shuffled - ${addRelatedDiscography === "true" ? 'with related discography' : ''}`;
@gate5th
gate5th / FeaturedPost.js
Created September 12, 2018 19:04
oldschoolshuffle
//FeaturedPost.js
import React, { Component } from 'react';
import './FeaturedPost.css';
import Typography from '@material-ui/core/Typography';
import Paper from '@material-ui/core/Paper';
import Author from './Author';
import * as SpotifyFunctions from '../spotifyFunctions.js'
class FeaturedPost extends Component {
@gate5th
gate5th / spotifyFunctions.js
Created September 12, 2018 19:03
oldschoolshuffle
export async function playArtistDiscography(artistId, artistName){
//receives this.state from playlistChooser and extract what you need
try {
const albumIds = await identifyAlbumsByArtistId(artistId, false);
const shuffledAlbums = shuffleArray(albumIds);
const promiseArrayOfTracksFromAlbum = shuffledAlbums.map(async (albumObject) => {
const response = await getSimpleAlbumTracks(albumObject.albumId, albumObject.albumName, albumObject.albumUri)
return response
})
const tracksByAlbum = await Promise.all(promiseArrayOfTracksFromAlbum);