-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
111 lines (79 loc) · 3.64 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
output: github_document
---
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/musicgraph)](https://cran.r-project.org/package=musicgraph)[![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html)[![minimal R version](https://img.shields.io/badge/R%3E%3D-`r R.version$minor`-6666ff.svg)](https://cran.r-project.org/)[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](http://www.repostatus.org/badges/latest/wip.svg)](http://www.repostatus.org/#wip)
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```
# README
Basic overview of the project
The basic idea is to connect to the graphsearch api, not the other pieces.
I will make some pieces that connect and keep as many things open. So that you
can construct a query without much interference from R. My idea is to have
a query field like "prefix=gree&genre=rock".
The graphsearch consists of Artist, Album and Track.
[] build something that takes into acoount the rate limiting.
[x] function that translates the result into a data.frame
[] check limit when given between 1 and 100
You will usually have to do multiple calls. Searching for artist returns an ID
and the ID can then be used on the artists metadata.
# Installation
Install with `devtools::install_github("RMHogervorst/musicgraph")`
# Basic use
1. register on musicgraph.com for a developer key.
2. You have to either supply the key in every call, or save the api key
in your .Renviron as MUSICGRAPH_KEY = "yourkey" and restart your R-session.
3. do calls with the package
## Practical usecase
I want to find out about the albums of the nu-metal / rock band Linkin Park.
### artist search
```{r basic use}
library(musicgraph)
library(dplyr)
# do a search for the artist
kinda_like_linkinpark <- artist_lookup("Linkin")
# view the results
result_to_dataframe(kinda_like_linkinpark) %>%
select(id, name) %>%
head(3)
```
This search (i'm only showing the top 3 results of the twenty)
gives me the artistID: "cef94f14-4f1f-4a34-8e7b-5a0e1dd600c7".
"e6207e83-a6b5-11e0-b446-00251188dd67"
Then let's download all the tracks.
The results are parsed per page, the limit parameter tells you how many results
per page, and the offset which page you want to download.
```{r diving deeper}
LP_results1 <- artist_edges(artistID = "e6207e83-a6b5-11e0-b446-00251188dd67/tracks", limit = 100)
LP_results2 <- artist_edges(artistID = "e6207e83-a6b5-11e0-b446-00251188dd67/tracks", limit = 100, offset = 2)
result_to_dataframe(LP_results1) %>% dim()
result_to_dataframe(LP_results1) %>% names()
```
The dataframes are thus 100 rows by 22 columns.
### track search
One of the tracks has the id : "794c1901-3da7-45d1-913b-da7da90d0387"
It's guilty all the same. If we want to know more about that track we can
explore the tracks endpoint.
```{r exploring tracks}
song <- track_edges("794c1901-3da7-45d1-913b-da7da90d0387")
result_to_dataframe(song)
```
### album search
In the artist search a album ID came up for the album 'the hunting party':
"516c15c1-c80c-4456-abd5-1a271f170ab3"
```{r album search}
album <- album_edges(albumID = "516c15c1-c80c-4456-abd5-1a271f170ab3/tracks")
album %>%
result_to_dataframe() %>%
select( title, release_year, popularity, main_genre) %>%
head(4)
```
### known issues
- when an artist has no tracks an empty list is returned.
- I have not made a message that returns how many results there are
- tracks result is not useful. it returns a nested list.