-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from calluswhatyouwant/v0.2.x
Upgrade to v0.2.0
- Loading branch information
Showing
38 changed files
with
2,372 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export * from './albums'; | ||
export * from './artists'; | ||
export * from './driver'; | ||
export * from './tracks'; | ||
export * from './follow'; | ||
export * from './artists'; | ||
export * from './albums'; | ||
export * from './personalization'; | ||
export * from './playlists'; | ||
export * from './player'; | ||
export * from './search'; | ||
export * from './tracks'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { getAxiosSpotifyInstance } from '../../driver'; | ||
|
||
class CursorBasedPage<T> { | ||
private t: new (json: any) => T; | ||
href: string; | ||
items: T[]; | ||
limit: number; | ||
next: string; | ||
cursors: any; | ||
total: number; | ||
|
||
constructor(json: any, t: new (json: any) => T) { | ||
this.t = t; | ||
this.href = json.href; | ||
this.items = json.items.map((json: any) => new t(json)); | ||
this.limit = json.limit; | ||
this.next = json.next ? json.next.split('?')[1] : null; | ||
this.cursors = json.cursors; | ||
this.total = json.total; | ||
} | ||
|
||
get queryParams(): any { | ||
const queryString = this.href.split('?')[1]; | ||
const paramsString = queryString.split('&'); | ||
const queryParams: any = {}; | ||
|
||
for (const param of paramsString) { | ||
const [name, value] = param.split('='); | ||
queryParams[name] = value; | ||
} | ||
|
||
return queryParams; | ||
} | ||
|
||
private getAxiosPageInstance() { | ||
const instance = getAxiosSpotifyInstance(); | ||
instance.defaults.baseURL = this.href.split('?')[0]; | ||
return instance; | ||
} | ||
|
||
hasNext() { | ||
return Boolean(this.next); | ||
} | ||
|
||
async getNextPage() { | ||
if (!this.hasNext()) throw new Error('There are no more pages'); | ||
const response = await this.getAxiosPageInstance().get(`?${this.next}`); | ||
return new CursorBasedPage<T>(response.data, this.t); | ||
} | ||
} | ||
|
||
export default CursorBasedPage; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import Context from './context'; | ||
import Track from '../track/track'; | ||
|
||
class CurrentlyPlaying { | ||
context: Context | null; | ||
currentlyPlayingType: string; | ||
isPlaying: boolean; | ||
item: Track | null; | ||
progressMs: number; | ||
timestamp: number; | ||
|
||
constructor(json: any) { | ||
this.context = json.context ? new Context(json.context) : null; | ||
this.currentlyPlayingType = json.currently_playing_type; | ||
this.isPlaying = json.is_playing; | ||
this.item = json.item ? new Track(json.item) : null; | ||
this.progressMs = json.progress_ms; | ||
this.timestamp = json.timestamp; | ||
} | ||
} | ||
|
||
export default CurrentlyPlaying; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
class AudioAnalysis { | ||
bars: TimeInterval[]; | ||
beats: TimeInterval[]; | ||
sections: Section[]; | ||
segments: Segment[]; | ||
tatums: TimeInterval[]; | ||
track: TrackAnalysisData; | ||
|
||
constructor(json: any) { | ||
this.bars = json.bars.map((bar: any) => new TimeInterval(bar)); | ||
this.beats = json.beats.map((beat: any) => new TimeInterval(beat)); | ||
this.sections = json.sections.map( | ||
(section: any) => new Section(section) | ||
); | ||
this.segments = json.segments.map( | ||
(segment: any) => new Segment(segment) | ||
); | ||
this.tatums = json.tatums.map((tatum: any) => new TimeInterval(tatum)); | ||
this.track = new TrackAnalysisData(json.track); | ||
} | ||
} | ||
|
||
class TimeInterval { | ||
start: number; | ||
duration: number; | ||
confidence: number; | ||
|
||
constructor(json: any) { | ||
this.start = json.start; | ||
this.duration = json.duration; | ||
this.confidence = json.confidence; | ||
} | ||
} | ||
|
||
class Section { | ||
start: number; | ||
duration: number; | ||
confidence: number; | ||
loudness: number; | ||
tempo: number; | ||
tempoConfidence: number; | ||
key: number; | ||
keyConfidence: number; | ||
mode: number; | ||
modeConfidence: number; | ||
timeSignature: number; | ||
timeSignatureConfidence: number; | ||
|
||
constructor(json: any) { | ||
this.start = json.start; | ||
this.duration = json.duration; | ||
this.confidence = json.confidence; | ||
this.loudness = json.loudness; | ||
this.tempo = json.tempo; | ||
this.tempoConfidence = json.tempo_confidence; | ||
this.key = json.key; | ||
this.keyConfidence = json.key_confidence; | ||
this.mode = json.mode; | ||
this.modeConfidence = json.mode_confidence; | ||
this.timeSignature = json.time_signature; | ||
this.timeSignatureConfidence = json.time_signature_confidence; | ||
} | ||
} | ||
|
||
class Segment { | ||
start: number; | ||
duration: number; | ||
confidence: number; | ||
loudnessStart: number; | ||
loudnessMaxTime: number; | ||
loudnessMax: number; | ||
loudnessEnd: number; | ||
pitches: number[]; | ||
timbre: number[]; | ||
|
||
constructor(json: any) { | ||
this.start = json.start; | ||
this.duration = json.duration; | ||
this.confidence = json.confidence; | ||
this.loudnessStart = json.loudness_start; | ||
this.loudnessMaxTime = json.loudness_max_time; | ||
this.loudnessMax = json.loudness_max; | ||
this.loudnessEnd = json.loudness_end; | ||
this.pitches = json.pitches; | ||
this.timbre = json.timbre; | ||
} | ||
} | ||
|
||
class TrackAnalysisData { | ||
duration: number; | ||
sampleMd5: string; | ||
offsetSeconds: number; | ||
windowSeconds: number; | ||
analysisSampleRate: number; | ||
analysisChannels: number; | ||
endOfFadeIn: number; | ||
startOfFadeOut: number; | ||
loudness: number; | ||
tempo: number; | ||
tempoConfidence: number; | ||
timeSignature: number; | ||
timeSignatureConfidence: number; | ||
key: number; | ||
keyConfidence: number; | ||
mode: number; | ||
modeConfidence: number; | ||
codeString: string; | ||
codeVersion: number; | ||
echoprintString: string; | ||
echoprintVersion: number; | ||
synchString: string; | ||
synchVersion: number; | ||
rhythmString: string; | ||
rhythmVersion: number; | ||
|
||
constructor(json: any) { | ||
this.duration = json.duration; | ||
this.sampleMd5 = json.sample_md5; | ||
this.offsetSeconds = json.offset_seconds; | ||
this.windowSeconds = json.window_seconds; | ||
this.analysisSampleRate = json.analysis_sample_rate; | ||
this.analysisChannels = json.analysis_channels; | ||
this.endOfFadeIn = json.end_of_fade_in; | ||
this.startOfFadeOut = json.start_of_fade_out; | ||
this.loudness = json.loudness; | ||
this.tempo = json.tempo; | ||
this.tempoConfidence = json.tempo_confidence; | ||
this.timeSignature = json.time_signature; | ||
this.timeSignatureConfidence = json.time_signature_confidence; | ||
this.key = json.key; | ||
this.keyConfidence = json.key_confidence; | ||
this.mode = json.mode; | ||
this.modeConfidence = json.mode_confidence; | ||
this.codeString = json.codestring; | ||
this.codeVersion = json.code_version; | ||
this.echoprintString = json.echoprintstring; | ||
this.echoprintVersion = json.echoprint_version; | ||
this.synchString = json.synchstring; | ||
this.synchVersion = json.synch_version; | ||
this.rhythmString = json.rhythmstring; | ||
this.rhythmVersion = json.rhythm_version; | ||
} | ||
} | ||
|
||
export default AudioAnalysis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.