From 3e42f244852a83b05c629f49c5965c2d3da17ab9 Mon Sep 17 00:00:00 2001 From: Nimble Date: Sun, 29 Jan 2023 21:58:13 -0600 Subject: [PATCH] revisions + http client json gotten --- README.md | 11 ++++++++++- src/bridges/connector.cr | 34 +++++++++++++++++++++++++++++----- src/bridges/metadata.cr | 2 +- src/bridges/spotify.cr | 15 +++++++++++---- src/metadata.cr | 2 -- src/playper.cr | 13 ++++--------- src/swapper.cr | 11 ++++++++--- 7 files changed, 63 insertions(+), 25 deletions(-) delete mode 100644 src/metadata.cr diff --git a/README.md b/README.md index 775aaff..88b68a4 100644 --- a/README.md +++ b/README.md @@ -11,4 +11,13 @@ Rosetta Stone for musical Playlists. - [ ] First version is going to be terminal only no need to authentication and it maybe ephimeral meaning the playlist changed won't be stored, it will only swap or appear in a different platform - [ ] Authentication service (not necesary) - [ ] Database management -- [ ] GUI \ No newline at end of file +- [ ] GUI +- [ ] We have the Spotify JSON we can use that for playing for now + - [ ] Convert it to Array/List + - [ ] Save it as XSPF + - [ ] Save it as m3u + - [ ] Send it to Youtube + - [ ] Send it to last.fm + - [ ] Send it to libre.fm + - [ ] Send it to music.brainz + - [ ] Play with the metadata so we have a solid list diff --git a/src/bridges/connector.cr b/src/bridges/connector.cr index c01dc76..dae913b 100644 --- a/src/bridges/connector.cr +++ b/src/bridges/connector.cr @@ -1,7 +1,31 @@ -# TODO: Write documentation for `Playper` -module API_Connect - VERSION = "0.1.0" +# This is the piece of tool that will do the queries. +# It needs values for input maybe could only be made into a function. +# Where do we give it the arguments? +# Will it be embed on the bridges or will +# This will be a metamodule or an abstract class and it will accomodate to all cases - # TODO: Put your code here - print("Hello world") +require "http/client" + +module APIConnect + extend self + # params = URI::Params.encode({"author" => "John Doe", "offset" => "20"}) # => "author=John+Doe&offset=20" + # HTTP::Client.get URI.new("https", "novoa.nagoya", query: params) do |response| + # puts response.status_code # => 200 + # puts response.body_io.gets # => "" + # end + def requestGet + # The logic of this shit works but I am going to steal code from irs + # The code from IRS does not enable an Authorization Workflow for spotify + baseUrl = "https://api.spotify.com/v1/me/playlists" + key = "BQBemjJEL0k8Wg2J6Mi7pg-vKCA1SFDy06JVv8oeXck98P4a660BpF7ScpVrCZzMEGmvBo0lunmfucakBTSUeNVAJaXrs56pdFQjicQN9ueW2GVGo68GZqk06FZJOOYZHqmhomwbZ28FOGiYfosN_1GysjYQKOHnu01efGTsuzFCE2yCC7s9tJNpow" + params = "?key=#{key}" + response = HTTP::Client.get(baseUrl, HTTP::Headers{"Authorization:" => key, "Accept:" => "application/json", "Content-Type:" => "application/json" +}) + puts response.to_s + puts response.body + puts response.status_code end + def requestDelete + + end +end diff --git a/src/bridges/metadata.cr b/src/bridges/metadata.cr index d5ba98c..68b1ad3 100644 --- a/src/bridges/metadata.cr +++ b/src/bridges/metadata.cr @@ -5,5 +5,5 @@ module Metadata VERSION = "0.1.0" # TODO: Put your code here - print("Hello world") + print("Module Metadata") end diff --git a/src/bridges/spotify.cr b/src/bridges/spotify.cr index bcfa130..55b310d 100644 --- a/src/bridges/spotify.cr +++ b/src/bridges/spotify.cr @@ -2,10 +2,17 @@ # GET # POST # Need to read deep into the API and make it the most user friendly possible. +# USE THIS ---> Authorization Code Flow +# Use irs to parse the absolutely shitty json, specially the part where it gets songs from playlists -module API_Spotify - VERSION = "0.1.0" - # TODO: Put your code here - print("Hello world") +require "json" + +module APISpotify + #This should be an input/variable or a direct response from a request to Spotify + json = File.open("spec/files/spotify-user-playlists.json") do |file| + JSON.parse(file) end +end + +#puts json diff --git a/src/metadata.cr b/src/metadata.cr deleted file mode 100644 index babdf22..0000000 --- a/src/metadata.cr +++ /dev/null @@ -1,2 +0,0 @@ -# API for collecting and connecting to metadata providers as well as parsing that -# And return it for other functions diff --git a/src/playper.cr b/src/playper.cr index 63dba9d..1b7d7d3 100644 --- a/src/playper.cr +++ b/src/playper.cr @@ -20,17 +20,12 @@ # HelpTest # end -require "./tryerror/*" -require "./reader_input.cr" +require "./swapper.cr" module Playper - include ReaderInput - include HelpTest - + include APIConnect + include APISpotify VERSION = "0.1.0" - # TODO: Put your code here - puts "Hello world!" - #ReaderInput.cli_input #runs cli_input from ReaderInput - HelpTest + APIConnect.requestGet end diff --git a/src/swapper.cr b/src/swapper.cr index c492718..119c50e 100644 --- a/src/swapper.cr +++ b/src/swapper.cr @@ -1,8 +1,13 @@ # Actual swaping of playlist from one format to another # Different cases for different hosts # Make use of the metadata class for concurrency +# This is the main an crucial part of the problem, expected input in one format and output in the other. +# As such variables of the input and output are required, metadata (type/platform) and data (Actual playlist) of it. +# Here all the data has to be abstracted to only have an array containing a "ultimate list" that is interchangeable depending on the output +# We need to check the APIs first to see how to proceed best with the issue + +require "./bridges/*" + class Swapper -extend Reader_Input - reader = Reader_Input.cli_input - puts "The Beatles are singing: #{"🎡#{reader.lyrics}🎢🎸πŸ₯".colorize.mode(:blink)}" + end