Skip to content

Instantly share code, notes, and snippets.

View gate5th's full-sized avatar

Michael Bruns gate5th

View GitHub Profile
@gate5th
gate5th / Procfile
Created September 17, 2018 03:02
oldschoolshuffle
web: npm run productionstart
@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 / 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 / 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);
@gate5th
gate5th / spotifyFunctions.js
Created September 12, 2018 19:02
oldschoolshuffle
const promiseArrayOfTracksFromAlbum = shuffledAlbums.map(async (albumObject) => {
const response = await getSimpleAlbumTracks(albumObject.albumId, albumObject.albumName, albumObject.albumUri)
return response
})
const tracksByAlbum = await Promise.all(promiseArrayOfTracksFromAlbum);
@gate5th
gate5th / spotifyFunctions.js
Created September 12, 2018 19:00
oldschoolshuffle
export async function byAlbumWithDiscography(state){
//receives this.state from playlistChooser and extract what you need
const {chosenPlaylistId: playlistId, chosenPlaylistName:playlistName} = state;
try {
let tracks = await getSimplePlaylistTracks(playlistId);
const albumIds = identifyAlbumsInPlaylist(tracks, false);
const shuffledAlbums = shuffleArray(albumIds);
//forget the playlist now that we know the albums - start fresh
const promiseArrayOfTracksFromAlbum = shuffledAlbums.map(async (albumObject) => {
const response = await getSimpleAlbumTracks(albumObject.albumId, albumObject.albumName, albumObject.albumUri)
@gate5th
gate5th / spotifyFunctions.js
Created September 12, 2018 19:00
oldschoolshuffle
export async function byAlbumNoDiscography(state){
//receives this.state from playlistChooser and extract what you need
const {chosenPlaylistId: playlistId, chosenPlaylistName:playlistName} = state;
try {
let tracks = await getSimplePlaylistTracks(playlistId);
const albumIds = identifyAlbumsInPlaylist(tracks);
const playlistObject = convertPlaylistToObjectByProperty(tracks, 'albumId');
let tracksByAlbum = albumIds.map((albumId) => {
return playlistObject[albumId]
});