Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Bruns gate5th

  • Modern Submissions
  • Austin TX
View GitHub Profile
@gate5th
gate5th / Procfile
Created Sep 17, 2018
oldschoolshuffle
View Procfile
web: npm run productionstart
@gate5th
gate5th / app.js
Last active Sep 17, 2018
oldschoolshuffle
View app.js
//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 Sep 17, 2018
oldschoolshuffle
View package.json
{
"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 Sep 17, 2018
oldschoolshuffle
View spotifyFunctions.js
//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 = "";
View spotifyFunctions.js
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' : ''}`;
View FeaturedPost.js
//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 {
View spotifyFunctions.js
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);
View spotifyFunctions.js
const promiseArrayOfTracksFromAlbum = shuffledAlbums.map(async (albumObject) => {
const response = await getSimpleAlbumTracks(albumObject.albumId, albumObject.albumName, albumObject.albumUri)
return response
})
const tracksByAlbum = await Promise.all(promiseArrayOfTracksFromAlbum);
View spotifyFunctions.js
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)
View spotifyFunctions.js
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]
});
You can’t perform that action at this time.