diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..054884e --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +dev.portalurbanna.com.br \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..613cfa2 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Camila L. Oliveira + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 68663d5..0000000 --- a/README.md +++ /dev/null @@ -1,3 +0,0 @@ -This is an example application that creates a playlist using the [Spotify Web API](https://developer.spotify.com/web-api/). - -Please check out the **[demo](http://lab.possan.se/playlistcreator-example/)** to try it out! diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..bc2739b --- /dev/null +++ b/_config.yml @@ -0,0 +1,58 @@ +name: Playlist Generator +title: Playlist Generator +description: Create your Spotify Playlist +baseurl: http://dev.portalurbanna.com.br/ + +include: ["_pages"] +permalink: /:title/ + +# Plugins +plugins: + - jekyll-feed + - jekyll-sitemap + - jekyll-paginate + - jekyll-seo-tag + - jekyll-pug + +authors: + milla: + name: Camila L. Oliveira + site: https://camilaloliveira.com.br + avatar: media/images/avatar_milla.png + bio: "Tecnóloga em Análise e Desenvolvimento de Sistemas, Bacharel em Administração Pública, Programadora de Computadores e Dispositivos Móveis e Técnica em Informática para Internet. + Com experiências nas empresas TCS e BRQ, atuando no desenvolvimento de soluções aos clientes há mais de 2 anos." + email: ola@camilaloliveira.com.br + twitter: https://twitter.com/millaloliveira + linkedin: https://linkedin.com/in/clcmo + facebook: https://facebook.com/millaloliveira + + +# Defaults +defaults: + + # all posts + - scope: + path: "_posts" + values: + layout: post + author: milla + avatar: /media/images/avatar_milla.png + + # all pages + - scope: + path: "_pages" + values: + layout: page + +# Syntax +markdown: kramdown +highlighter: rouge + +# Paginate +paginate: 10 + + + +# Exclude metadata and development time dependencies (like Grunt plugins) +exclude: [README.markdown, package.json, grunt.js, Gruntfile.js, Gruntfile.coffee, node_modules] + diff --git a/_layouts/default.html b/_layouts/default.html new file mode 100644 index 0000000..8f4fbc3 --- /dev/null +++ b/_layouts/default.html @@ -0,0 +1,54 @@ + + + + + + + {{site.title}} + + + + + + + + + + + + + + + +
+
+
+

+ Playlist Generator +

+

+ Generated by Json +

+
+
+
+
+ {{content}} +
+ + + + + + + + \ No newline at end of file diff --git a/_pages/callback.md b/_pages/callback.md new file mode 100644 index 0000000..a70d826 --- /dev/null +++ b/_pages/callback.md @@ -0,0 +1,21 @@ +--- +layout: default +permalink: "/callback.html" +--- + +
+
+
+

Creating playlist...

+
+
+
+ +
+
\ No newline at end of file diff --git a/_pages/create.md b/_pages/create.md new file mode 100644 index 0000000..323c341 --- /dev/null +++ b/_pages/create.md @@ -0,0 +1,20 @@ +--- +layout: default +--- + +
+
+

Write your text here

+
+ +
+
+ +
+
+

Corresponding track names

+
+
+
+
+
\ No newline at end of file diff --git a/_pages/login.md b/_pages/login.md new file mode 100644 index 0000000..c73635e --- /dev/null +++ b/_pages/login.md @@ -0,0 +1,43 @@ +--- +layout: default +--- + +
+
+

This is an example of the Authorization Code flow

+ Log in with Spotify +
+
+
+
+ +
+
+ + + + \ No newline at end of file diff --git a/assets/css/default.css b/assets/css/default.css new file mode 100644 index 0000000..3f7655e --- /dev/null +++ b/assets/css/default.css @@ -0,0 +1,10 @@ +.column left { + position: absolute; + width: 50%; + height: 100%; + } + + .column right { + position: absolute; + width: 50%; +} \ No newline at end of file diff --git a/assets/css/logo_urb.png b/assets/css/logo_urb.png new file mode 100644 index 0000000..f89c75e Binary files /dev/null and b/assets/css/logo_urb.png differ diff --git a/app.js b/assets/js/app.js similarity index 80% rename from app.js rename to assets/js/app.js index 4bf6348..05b58c8 100644 --- a/app.js +++ b/assets/js/app.js @@ -6,13 +6,9 @@ var g_tracks = ''; function setStatus(text) { - if (text != '') { + if(text != ''){ $('#status').html( - '
' + - '
' + - text + - '
' + - '
' + '15%' ); } else { $('#status').html(''); @@ -32,13 +28,12 @@ } var refreshText = function() { - setStatus('Updating text...'); + setStatus('Loading...'); g_name = $('#alltext').val().trim(); var words = splitText(g_name); console.log('text changed.', g_name, words); cache.lookupWords(words, function(worddata) { - setStatus(''); console.log('wordcache callback', worddata); @@ -93,13 +88,18 @@ console.log('found', found); if (found) { g_tracks.push(found.uri); - txt += '
' + - '' + - '
' + - '

' + found.name + '

' + - 'Album: ' + found.album + - '
Artist: ' + found.artist+'' + - '
' + + txt += + '
' + + '' + + '' + + '' + + '
' + + '

'+ + '' + found.name + ''+ + '

' + + 'Album: ' + found.album +''+ + '
Artist: ' + found.artist+'' + + '
' + '
\n'; } else { txt += '
No match found for the word "' + data.word+ '"
\n' @@ -173,12 +173,12 @@ var redirect_uri = ''; - if (location.host == 'localhost:8000') { - client_id = 'd37a9e88667b4fb3bc994299de2a52bd'; - redirect_uri = 'http://localhost:8000/callback.html'; + if (location.host == 'localhost:8888') { + client_id = '2a8909c2980143c496833de968725bf0'; + redirect_uri = 'http://localhost:8888/callback.html'; } else { - client_id = '6f9391eff32647baa44b1a700ad4a7fc'; - redirect_uri = 'http://lab.possan.se/playlistcreator-example/callback.html'; + client_id = '2a8909c2980143c496833de968725bf0'; + redirect_uri = 'https://dev.portalurbanna.com.br/callback.html'; } var doLogin = function(callback) { @@ -188,7 +188,7 @@ '&redirect_uri=' + encodeURIComponent(redirect_uri); localStorage.setItem('createplaylist-tracks', JSON.stringify(g_tracks)); localStorage.setItem('createplaylist-name', g_name); - var w = window.open(url, 'asdf', 'WIDTH=400,HEIGHT=500'); + var w = window.open(url, 'asdf', 'WIDTH=400, HEIGHT=500'); } var refreshtimer = 0; @@ -218,4 +218,4 @@ resolveOneWord(); } -})(window); +})(window); \ No newline at end of file diff --git a/fuzzyset.js b/assets/js/fuzzyset.js similarity index 100% rename from fuzzyset.js rename to assets/js/fuzzyset.js diff --git a/assets/js/main.js b/assets/js/main.js new file mode 100644 index 0000000..eb17042 --- /dev/null +++ b/assets/js/main.js @@ -0,0 +1,112 @@ +var g_access_token = ""; +var g_username = ""; +var g_tracks = []; + +function getUsername(callback) { + console.log("getUsername"); + var url = "https://api.spotify.com/v1/me"; + $.ajax(url, { + dataType: "json", + headers: { + Authorization: "Bearer " + g_access_token + }, + success: function (r) { + console.log("got username response", r); + callback(r.id); + }, + error: function (r) { + callback(null); + } + }); +} + +function createPlaylist(username, name, callback) { + console.log("createPlaylist", username, name); + var url = "https://api.spotify.com/v1/users/" + username + "/playlists"; + $.ajax(url, { + method: "POST", + data: JSON.stringify({ + name: name, + public: false + }), + dataType: "json", + headers: { + Authorization: "Bearer " + g_access_token, + "Content-Type": "application/json" + }, + success: function (r) { + console.log("create playlist response", r); + callback(r.id); + }, + error: function (r) { + callback(null); + } + }); +} + +function addTracksToPlaylist(username, playlist, tracks, callback) { + console.log("addTracksToPlaylist", username, playlist, tracks); + var url = + "https://api.spotify.com/v1/users/" + + username + + "/playlists/" + + playlist + + "/tracks"; // ?uris='+encodeURIComponent(tracks.join(',')); + $.ajax(url, { + method: "POST", + data: JSON.stringify(tracks), + dataType: "text", + headers: { + Authorization: "Bearer " + g_access_token, + "Content-Type": "application/json" + }, + success: function (r) { + console.log("add track response", r); + callback(r.id); + }, + error: function (r) { + callback(null); + } + }); +} + +function doit() { + // parse hash + var hash = location.hash.replace(/#/g, ""); + var all = hash.split("&"); + var args = {}; + console.log("all", all); + all.forEach(function (keyvalue) { + var idx = keyvalue.indexOf("="); + var key = keyvalue.substring(0, idx); + var val = keyvalue.substring(idx + 1); + args[key] = val; + }); + + g_name = localStorage.getItem("createplaylist-name"); + g_tracks = JSON.parse(localStorage.getItem("createplaylist-tracks")); + + console.log("got args", args); + + if (typeof args["access_token"] != "undefined") { + // got access token + console.log("got access token", args["access_token"]); + g_access_token = args["access_token"]; + } + + getUsername(function (username) { + console.log("got username", username); + createPlaylist(username, g_name, function (playlist) { + console.log("created playlist", playlist); + addTracksToPlaylist(username, playlist, g_tracks, function () { + console.log("tracks added."); + $("#playlistlink").attr( + "href", + "spotify:user:" + username + ":playlist:" + playlist + ); + $("#creating").hide(); + $("#done").show(); + }); + }); + }); +} \ No newline at end of file diff --git a/assets/js/server.js b/assets/js/server.js new file mode 100644 index 0000000..2a91fde --- /dev/null +++ b/assets/js/server.js @@ -0,0 +1,10 @@ + /* Load the HTTP library */ + var http = require("http"); + + /* Create an HTTP server to handle responses */ + + http.createServer(function(request, response) { + response.writeHead(200, {"Content-Type": "text/plain"}); + response.write("Hello World"); + response.end(); + }).listen(8888); \ No newline at end of file diff --git a/wordcache.js b/assets/js/wordcache.js similarity index 100% rename from wordcache.js rename to assets/js/wordcache.js diff --git a/callback.html b/callback.html deleted file mode 100644 index d95bc33..0000000 --- a/callback.html +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - - - - -
-
-
-

Creating playlist...

-
- -
-
- - diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..bd963a7 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,11 @@ +# Playlist Creator for Spotify + + +[![GitHub license](https://img.shields.io/github/license/urbanna/playlistcreator-example?style=for-the-badge)](https://github.com/urbanna/playlistcreator-example) +[![GitHub stars](https://img.shields.io/github/stars/urbanna/playlistcreator-example?style=for-the-badge)](https://github.com/urbanna/playlistcreator-example/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/urbanna/playlistcreator-example?style=for-the-badge)](https://github.com/urbanna/playlistcreator-example/network) +[![GitHub issues](https://img.shields.io/github/issues/urbanna/playlistcreator-example?style=for-the-badge)](https://github.com/urbanna/playlistcreator-example/issues) + +This is an example application that creates a playlist using the [Spotify Web API](https://developer.spotify.com/web-api/). + +Please check out the **[demo](http://dev.portalurbanna.com.br/)** to try it out! diff --git a/docs/SECURITY.md b/docs/SECURITY.md new file mode 100644 index 0000000..c57a29b --- /dev/null +++ b/docs/SECURITY.md @@ -0,0 +1,18 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Firefox | Safari | Edge | Opera | +| ------- | ------------------ |------------------ |------------------ |------------------ | +| 2022.2.x | :x: | :x: |:x: |:x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. diff --git a/index.html b/index.html deleted file mode 100644 index 3723381..0000000 --- a/index.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - -
-
-

Spotify WebAPI Playlist creation example

-

- Browse the sourcecode on GitHub, - Example by @possan -

-
-
- -
- -
-
-

Write your text here

-
- -
-

- -

-
-
-
-

Corresponding track names

-
-
-
-
- - \ No newline at end of file diff --git a/index.md b/index.md new file mode 100644 index 0000000..323c341 --- /dev/null +++ b/index.md @@ -0,0 +1,20 @@ +--- +layout: default +--- + +
+
+

Write your text here

+
+ +
+
+ +
+
+

Corresponding track names

+
+
+
+
+
\ No newline at end of file diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f2b97b4 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,12 @@ +{ + "name": "playlistcreator-example-1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "cookie-parser": "1.3.2", + "express": "~4.16.0", + "cors": "^2.8.4", + "querystring": "~0.2.0", + "request": "~2.83.0" + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..2d3dda2 --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "playlistcreator-example-1", + "lockfileVersion": 2, + "requires": true, + "packages": { + "cookie-parser": "1.3.2", + "express": "~4.16.0", + "cors": "^2.8.4", + "querystring": "~0.2.0", + "request": "~2.83.0" + } + } + \ No newline at end of file