forked from ytmdesktop/ytmdesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ LastFM authorization and Custom Theme
- Loading branch information
Showing
13 changed files
with
207 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,5 +13,6 @@ body { | |
|
||
.bottom { | ||
position: absolute; | ||
bottom: 0; | ||
bottom: 12px; | ||
right: 12px | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<html> | ||
<head> | ||
<link | ||
type="text/css" | ||
rel="stylesheet" | ||
href="../../node_modules/materialize-css/dist/css/materialize.min.css" | ||
media="screen,projection" | ||
/> | ||
<link href="../../assets/css/material_icons.css" rel="stylesheet" /> | ||
<link type="text/css" rel="stylesheet" href="../../assets/css/styles.css" /> | ||
</head> | ||
|
||
<body> | ||
<div class="bar drag"> | ||
<div class="title"> | ||
<i class="material-icons tiny left">music_note</i> | ||
<span | ||
i18n="i18n_LABEL_SETTINGS_TAB_LAST_FM_SCROBBLER" | ||
id="i18n_LABEL_SETTINGS_TAB_LAST_FM_SCROBBLER" | ||
></span> | ||
</div> | ||
|
||
<div class="cmd-btns"> | ||
<div class="no-drag pointer cmd-btn hover-red" id="btn-close"> | ||
<i class="material-icons tiny">close</i> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="content center"> | ||
<div class="row"> | ||
<div class="input-field col s12"> | ||
<input id="username" type="text" class="white-text" /> | ||
<label for="username">Username</label> | ||
</div> | ||
<div class="input-field col s12"> | ||
<input id="password" type="password" class="white-text" /> | ||
<label for="password">Password</label> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<button class="btn red" id="btn-save" style="text-transform: none;"> | ||
<span | ||
i18n="i18n_LABEL_SETTINGS_TAB_LAST_FM_SCROBBLER_AUTHORIZE" | ||
></span> | ||
</button> | ||
</div> | ||
</div> | ||
</body> | ||
</html> | ||
|
||
<script src="../../node_modules/materialize-css/dist/js/materialize.min.js"></script> | ||
|
||
<script> | ||
M.updateTextFields(); | ||
</script> | ||
|
||
<script src="./last-fm-login.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const __ = require("../../providers/translateProvider"); | ||
const scrobbleProvider = require("../../providers/scrobblerProvider"); | ||
__.loadi18n(); | ||
const Base64 = require("js-base64").Base64; | ||
|
||
document.getElementById("btn-close").addEventListener("click", function() { | ||
window.close(); | ||
}); | ||
|
||
var login = scrobbleProvider.getLogin(); | ||
if (login) { | ||
document.getElementById("username").value = login.username; | ||
document.getElementById("password").value = login.password; | ||
} | ||
|
||
document.getElementById("btn-save").addEventListener("click", function() { | ||
var username = document.getElementById("username").value; | ||
var password = document.getElementById("password").value; | ||
scrobbleProvider.setLogin(username, password); | ||
|
||
scrobbleProvider.getToken(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,85 @@ | ||
const scribble = require("scribble"); | ||
const electronStore = require("electron-store"); | ||
const store = new electronStore(); | ||
const http = require("http"); | ||
const Base64 = require("js-base64").Base64; | ||
|
||
const apiKey = "9ab417e8b808ed071223a1b4b3c29642"; | ||
const apiSecret = "9d8830c167627e65dac63786be101964"; | ||
|
||
var Scrobbler; | ||
|
||
var userLogin = store.get("last-fm-login"); | ||
var userLogin = getLogin(); | ||
|
||
function signIn() { | ||
Scrobbler = new scribble( | ||
apiKey, | ||
apiSecret, | ||
userLogin.user, | ||
userLogin.username, | ||
userLogin.password | ||
); | ||
} | ||
|
||
exports.getToken = function() { | ||
var windowToken = window.open( | ||
`http://ws.audioscrobbler.com/2.0/?method=auth.gettoken&api_key=${apiKey}&format=json` | ||
function setLogin(username, password) { | ||
store.set("last-fm-login", { | ||
username: username, | ||
password: Base64.encode(password) | ||
}); | ||
} | ||
|
||
function getLogin() { | ||
var login = store.get("last-fm-login"); | ||
login.password = Base64.decode(login.password); | ||
|
||
return login; | ||
} | ||
|
||
function getToken() { | ||
http.get( | ||
`http://ws.audioscrobbler.com/2.0/?method=auth.gettoken&api_key=${apiKey}&format=json`, | ||
function(res) { | ||
let rawData = ""; | ||
res.on("data", chunk => { | ||
rawData += chunk; | ||
}); | ||
res.on("end", () => { | ||
try { | ||
const parsedData = JSON.parse(rawData); | ||
authorize(parsedData.token); | ||
} catch (e) { | ||
console.error(e.message); | ||
} | ||
}); | ||
} | ||
); | ||
console.log(windowToken); | ||
}; | ||
} | ||
|
||
function updateTrackInfo(title, author) { | ||
if (store.get("settings-last-fm-scrobbler")) { | ||
if (Scrobbler === undefined) { | ||
signIn(); | ||
} | ||
|
||
var song = { | ||
artist: author, | ||
track: title | ||
}; | ||
Scrobbler.Scrobble(song, function(_) {}); | ||
} | ||
} | ||
|
||
exports.updateTrackInfo = function(title, author) { | ||
console.log(Scrobbler); | ||
var song = { | ||
artist: author, | ||
track: title | ||
}; | ||
function authorize(token) { | ||
var authorize = window.open( | ||
`https://www.last.fm/api/auth?api_key=${apiKey}&token=${token}`, | ||
"Authorize App", | ||
"frame=true" | ||
); | ||
} | ||
|
||
Scrobbler.Scrobble(song, function(_) {}); | ||
module.exports = { | ||
getToken: getToken, | ||
updateTrackInfo: updateTrackInfo, | ||
getLogin: getLogin, | ||
setLogin: setLogin, | ||
authorize: authorize | ||
}; |