knitr::opts_chunk$set(echo = TRUE) library(devtools) #devtools::install_github('charlie86/spotifyr') library(spotifyr) library(tidyverse) library(genius) #devtools::install_github("drew-walkerr/musichistoRy") library(musichistoRy) library(tictoc) library(syuzhet) library(knitr)
tic() myhistory <- get_history("thedrewwalker") toc()
tic() myhistory_snip <- myhistory %>% head(10) toc() myaudiofeatures <- get_history_audio_features(myhistory_snip,"drew")
mysession_df <- get_session_df(myaudiofeatures) #Should create group_by track dataset that summarizes playcount values and such unique_songs <- mysession_df %>% distinct(id, .keep_all = TRUE)
#unique dataset for lyrics tic() mylyrics <- unique_songs %>% add_genius(artist, title, type = "track") toc() head(mylyrics, n=100) kable(mylyrics)
install.packages("googleLanguageR") library(googleLanguageR) gl_auth("googletranslateR-717ce515dfc4.json") tic() mylyrics_detected <- mylyrics %>% mutate(language = gl_translate_detect(lyric), en_translation = gl_translate(lyric)) toc() mylyrics_detected2 <- flatten(mylyrics_detected) save(mylyrics_detected, file = "mylyrics_detected.Rdata")
spanish_songs <- mylyrics_detected %>% filter(language$language == "es") spanish_songs_uniques <- spanish_songs %>% distinct(artist,title)
We'll transform the lyrics data to prepare for the deck import files, and utilize the reticulate package to interface with AnkiConnect to build Anki decks within R.
library(reticulate)
https://github.com/kerrickstaley/genanki genanki may be better, looks like ankiconnect can only make blank decks
https://medium.com/python-in-plain-english/make-flashier-flashcards-automating-anki-with-python-2744ed025366 looks like it could be helpful
```{python, get-anki-connect} import json import urllib.request
def request(action, **params): return {'action': action, 'params': params, 'version': 6}
def invoke(action, params): requestJson = json.dumps(request(action, params)).encode('utf-8') response = json.load(urllib.request.urlopen(urllib.request.Request('http://localhost:8765', requestJson))) if len(response) != 2: raise Exception('response has an unexpected number of fields') if 'error' not in response: raise Exception('response is missing required error field') if 'result' not in response: raise Exception('response is missing required result field') if response['error'] is not None: raise Exception(response['error']) return response['result']
invoke('createDeck', deck='Song') result = invoke('deckNames') print('got list of decks: {}'.format(result)) ```
https://cran.r-project.org/web/packages/syuzhet/vignettes/syuzhet-vignette.html{.uri}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.