Spotify Grabber

Next is another simple application that is useful to keeping that inner demon I have about losing personal data. My personally curated playlists. We all have them, but we don’t necessarily own them. I rely exclusively on Spotify for my playlists and when I have a song I like, it gets added to a playlist which suits the vibe.

Its not hard to accidentally delete a playlist, its two clicks and irreversible. Also should the platform fade off (which I doubt) I lose the songs and artists and songs. The application simply takes the OAUTH credentials from your account so you will need to visit the spotify developer page and get these credentials. Its free. Once you enter this into the terminal you enter the playlist ID and thats all there is to it. A CSV with the artists and songs will be exported to your desktop or designated location from the app.config.

Grabber image

HTTP Auth

The main two functions that get this to work (excuse the json parsing not using a lib but quicker to stick with what you know to do in 5 mins for little personal applets.)

public string GetTrackInfo(string url) {

            string webResponse = string.Empty;
            var myToken = GetAccessToken();

            try {
                // Get token for request
                HttpClient hc = new HttpClient();
                var request = new HttpRequestMessage() {
                    RequestUri = new Uri(url),
                    Method = HttpMethod.Get
                };

                request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                request.Headers.Authorization = new AuthenticationHeaderValue("Authorization", "Bearer " + myToken);

                var task = hc.SendAsync(request).ContinueWith((taskwithmsg) => {
                        var response = taskwithmsg.Result;
                        var jsonTask = response.Content.ReadAsStringAsync();
                        webResponse = jsonTask.Result;
                });

                task.Wait();


            } catch (WebException ex) {
                Console.WriteLine("Track Request Error: " + ex.Status);
            } catch (TaskCanceledException tex) {
                Console.WriteLine("Track Request Error: " + tex.Message);
            }

            return webResponse;
        }

Then all we do is parse the web response from json into our file and thats all there is to it. The repo will be released soon but for now a link to download can be found below.

            var jsonData = g.GetTrackInfo(url);
            var obj = JObject.Parse(jsonData);
            //Console.WriteLine(obj.ToString());

            JArray items = (JArray)obj["tracks"]["items"];

            for(int i = 0; i < items.Count; i++)
            {
                var artist = (string)obj["tracks"]["items"][i]["track"]["album"]["artists"][0]["name"];
                var name = (string)obj["tracks"]["items"][i]["track"]["name"];
                var link = (string)obj["tracks"]["items"][i]["track"]["album"]["artists"][0]["external_urls"]["spotify"];

                Console.WriteLine("ADDED: " + name + " " + artist + " " + link);
                g.WriteToFile(name, artist, link, playListName);
            }

Sentence a day

This is v1 and I’ve been using it daily for about 4 months now with no issues. I would like an installer and to handle only having one instance of the application open at a time as currently you can have numerous. The .csv file doesn’t let locked as its just a save operation that will append to the csv. The application doesn’t ever parse the csv and simply appends lines to a csv document that I can then open in excel to do some data analysis.

Sentence a day

Mood Prediction

The theory was if I can record a lot of simple, relatively similar data on mood, activities and the grammar I use in this application, I could then aggregate the data into a model. A model of perhaps words I frequently use, allowing me to adapt and improve ways to describe activities or other. A model could also be used after a large data set has been collected and perhaps working with something like GPT-2 you could then generate similar activities and have this artificial life in a csv document. This was the kicker idea that pushed me to making this. The future-proof aspect, collect now and figure out a use later. Imagine having years of daily data about yourself and then create an AI model on yourself. “Hey computer how will I feel in 2023 1st April” and it could look at the behavior or mood patterns in previous years to generate a response which could be utter rubbish.. or hold somewhat true. Either way the idea is that the response would be written in such a way that is similar to myself.

And the heart of the code that will likely never change is found below. Simple and sweet to append a line to a csv document.

using (FileStream fs = new FileStream(_path, FileMode.Append, FileAccess.Write)) {
                        using (StreamWriter sw = new StreamWriter(fs)) {
                            sw.WriteLine(date + "," + EncloseInParenthsisIfNotEmpty(sentence)); // Excel will only respect the escaping of commas and speech marks if the column value is NOT preceded by a space.
                        }
                    }

Future Features

  • Emoji or star based buttons to enter mood from 1-5 rather than manually typing in a key that can be used as a delimiter “mood = 2”
  • Ramification, add a simple graph to the side to share daily streaks from entering data.
  • Create release on github.. but the code is so dumb ill be roasted but its not the complexity its the practical application that this software has impacted my life. It’s really reflective to look back on achievements and activities on specific dates without a third party seeing the data.

Further Reading

Check out the following links for inspiration and further reading about this topic

My Email