├── src
├── index.js
├── App.js
├── Player.js
├── Login.js
├── TrackSearchResult.js
├── useAuth.js
└── Dashboard.js
├── .gitignore
├── README.md
├── LICENSE
├── package.json
└── public
└── index.html
/src/index.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | import ReactDOM from "react-dom";
3 |
4 | import App from "./App";
5 |
6 | ReactDOM.render(
7 |
8 |
9 | ,
10 | document.getElementById("root")
11 | );
12 |
--------------------------------------------------------------------------------
/src/App.js:
--------------------------------------------------------------------------------
1 | import "bootstrap/dist/css/bootstrap.min.css";
2 |
3 | import Login from "./Login";
4 | import Dashboard from "./Dashboard";
5 |
6 | const code = new URLSearchParams(window.location.search).get("code");
7 |
8 | function App() {
9 | return code ? : ;
10 | }
11 |
12 | export default App;
13 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2 |
3 | # dependencies
4 | /node_modules
5 | /.pnp
6 | .pnp.js
7 |
8 | # testing
9 | /coverage
10 |
11 | # production
12 | /build
13 |
14 | # misc
15 | .DS_Store
16 | .env.local
17 | .env.development.local
18 | .env.test.local
19 | .env.production.local
20 |
21 | npm-debug.log*
22 | yarn-debug.log*
23 | yarn-error.log*
24 |
--------------------------------------------------------------------------------
/src/Player.js:
--------------------------------------------------------------------------------
1 | import { useEffect } from "react";
2 | import AudioPlayer from "react-h5-audio-player";
3 | import "react-h5-audio-player/lib/styles.css";
4 |
5 | // const YoutubeMusicApi = require("youtube-music-api");
6 |
7 | export default function Player({ trackUri }, { songinfo }) {
8 | useEffect(() => {}, [trackUri]);
9 |
10 | return (
11 |
12 | Now Playing: {songinfo}
13 | console.log("onPlay")}
17 | // other props here
18 | />
19 |
20 | );
21 | }
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # LogiMusic
2 |
3 | LogiMusic (Open Source Music Streaming Platform).
4 |
5 |
6 |
7 | ## Before you run on Local-Server:
8 |
9 | - **Run the following commands**
10 |
11 | ```
12 | git clone https://github.com/hidimpu/logimusic-client.git
13 | ```
14 |
15 | ```
16 | cd logimusic-client
17 | ```
18 |
19 | ```
20 | npm i
21 | ```
22 |
23 | ```
24 | npm run start
25 | ```
26 |
27 |
28 | ### Working Screenshot:
29 |
30 |
31 |
32 |
33 |
34 | >Make sure to get the API key from your Spotify Developers account and change it to avoid crashed on localhost
35 | will Document it soon!
--------------------------------------------------------------------------------
/src/Login.js:
--------------------------------------------------------------------------------
1 | import React from "react";
2 | // require("dotenv").config();
3 |
4 | import { Container } from "react-bootstrap";
5 |
6 | const AUTH_URL =
7 | "https://accounts.spotify.com/authorize?client_id=422fb144926046c696d4149ba8ad47f8&response_type=code&redirect_uri=https://logimusic.netlify.app/&scope=streaming%20user-read-email%20user-read-private%20user-library-read%20user-library-modify%20user-read-playback-state%20user-modify-playback-state";
8 |
9 | export default function Login() {
10 | return (
11 |
15 |
16 | Login With Spotify
17 |
18 |
19 | );
20 | }
21 |
--------------------------------------------------------------------------------
/src/TrackSearchResult.js:
--------------------------------------------------------------------------------
1 | import React from 'react';
2 |
3 | export default function TrackSearchResult({ track, chooseTrack, handlePlay }) {
4 | // async function handlePlay() {
5 | // chooseTrack(track);
6 | // const song = { title: track.title, artist: track.artist };
7 |
8 | // const { data } = await axios.post('http://localhost:3001/song', {
9 | // song,
10 | // });
11 | // console.log(data);
12 | // }
13 |
14 | return (
15 | handlePlay(track)}
19 | >
20 |

25 |
26 |
{track.title}
27 |
{track.artist}
28 |
29 |
30 | );
31 | }
32 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright 2021 Parth Shukla
2 |
3 | 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:
4 |
5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6 |
7 | 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.
8 |
9 | End license text.
10 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "logifront",
3 | "version": "0.1.0",
4 | "private": true,
5 | "dependencies": {
6 | "@testing-library/jest-dom": "^5.14.1",
7 | "@testing-library/react": "^11.2.7",
8 | "@testing-library/user-event": "^12.8.3",
9 | "axios": "^0.21.1",
10 | "bootstrap": "^5.0.2",
11 | "dotenv": "^10.0.0",
12 | "react": "^17.0.2",
13 | "react-bootstrap": "^1.6.1",
14 | "react-dom": "^17.0.2",
15 | "react-h5-audio-player": "^3.7.1",
16 | "react-scripts": "^4.0.3",
17 | "spotify-web-api-node": "^5.0.2",
18 | "web-vitals": "^1.1.2"
19 | },
20 | "scripts": {
21 | "start": "react-scripts start",
22 | "build": "react-scripts build",
23 | "test": "react-scripts test",
24 | "eject": "react-scripts eject"
25 | },
26 | "eslintConfig": {
27 | "extends": [
28 | "react-app",
29 | "react-app/jest"
30 | ]
31 | },
32 | "browserslist": {
33 | "production": [
34 | ">0.2%",
35 | "not dead",
36 | "not op_mini all"
37 | ],
38 | "development": [
39 | "last 1 chrome version",
40 | "last 1 firefox version",
41 | "last 1 safari version"
42 | ]
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/useAuth.js:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from "react";
2 | import axios from "axios";
3 |
4 | export default function useAuth(code) {
5 | const [accessToken, setAccessToken] = useState();
6 | const [refreshToken, setRefreshToken] = useState();
7 | const [expiresIn, setExpiresIn] = useState();
8 |
9 | useEffect(() => {
10 | axios
11 | .post("https://logimusic-server.herokuapp.com/login", {
12 | code,
13 | })
14 | .then((res) => {
15 | setAccessToken(res.data.accessToken);
16 | setRefreshToken(res.data.refreshToken);
17 | setExpiresIn(res.data.expiresIn);
18 | window.history.pushState({}, null, "/");
19 | })
20 | .catch(() => {
21 | // window.location = "/";
22 | });
23 | }, [code]);
24 |
25 | useEffect(() => {
26 | if (!refreshToken || !expiresIn) return;
27 | const interval = setInterval(() => {
28 | axios
29 | .post("https://logimusic-server.herokuapp.com/refresh", {
30 | refreshToken,
31 | })
32 | .then((res) => {
33 | setAccessToken(res.data.accessToken);
34 | setExpiresIn(res.data.expiresIn);
35 | })
36 | .catch(() => {
37 | window.location = "/";
38 | });
39 | }, (expiresIn - 60) * 1000);
40 | return () => clearInterval(interval);
41 | }, [refreshToken, expiresIn]);
42 |
43 | return accessToken;
44 | }
45 |
--------------------------------------------------------------------------------
/public/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
17 |
18 |
27 | LogiMusic
28 |
29 |
30 |
31 |
32 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/src/Dashboard.js:
--------------------------------------------------------------------------------
1 | import { useState, useEffect } from "react";
2 | import useAuth from "./useAuth";
3 |
4 | import { Container, Form } from "react-bootstrap";
5 | import SpotifyWebApi from "spotify-web-api-node";
6 |
7 | import TrackSearchResult from "./TrackSearchResult";
8 | import Player from "./Player";
9 | import axios from "axios";
10 |
11 | const spotifyApi = new SpotifyWebApi({
12 | clientId: "422fb144926046c696d4149ba8ad47f8",
13 | });
14 |
15 | export default function Dashboard({ code }) {
16 | const accessToken = useAuth(code);
17 |
18 | const [search, setSearch] = useState("");
19 | const [searchResults, setSearchResults] = useState([]);
20 | const [playingTrack, setPlayingTrack] = useState();
21 | const [lyrics, setLyrics] = useState("");
22 | const [trackUri, setTrackUri] = useState("");
23 |
24 | function chooseTrack(track) {
25 | setPlayingTrack(track);
26 | setSearch("");
27 | setLyrics("");
28 | }
29 |
30 | useEffect(() => {
31 | if (!playingTrack) return;
32 |
33 | axios
34 | .get("https://logimusic-server.herokuapp.com/lyrics", {
35 | params: {
36 | track: playingTrack.title,
37 | artist: playingTrack.artist,
38 | },
39 | })
40 | .then((res) => setLyrics(res.data.lyrics));
41 | }, [playingTrack]);
42 |
43 | useEffect(() => {
44 | if (!accessToken) return;
45 | spotifyApi.setAccessToken(accessToken);
46 | }, [accessToken]);
47 |
48 | useEffect(() => {
49 | if (!search) return setSearchResults([]);
50 | if (!accessToken) return;
51 |
52 | let cancel = false;
53 |
54 | spotifyApi.searchTracks(search).then((res) => {
55 | if (cancel) return;
56 |
57 | setSearchResults(
58 | res.body.tracks.items.map((track) => {
59 | const smallestAlbumImage = track.album.images.reduce(
60 | (smallest, image) => {
61 | if (image.height < smallest.height) return image;
62 | return smallest;
63 | },
64 | track.album.images[0]
65 | );
66 | return {
67 | artist: track.artists[0].name,
68 | title: track.name,
69 | uri: track.uri,
70 | albumUrl: smallestAlbumImage.url,
71 | };
72 | })
73 | );
74 | });
75 |
76 | return () => (cancel = true);
77 | }, [search, accessToken]);
78 |
79 | async function handlePlay(track) {
80 | chooseTrack(track);
81 | const song = { title: track.title, artist: track.artist };
82 |
83 | const { data } = await axios.post(
84 | "https://logimusic-server.herokuapp.com/song",
85 | {
86 | song,
87 | }
88 | );
89 |
90 | setTrackUri(data);
91 | }
92 |
93 | return (
94 |
95 | setSearch(e.target.value)}
100 | />
101 |
102 |
103 | {searchResults.map((track) => (
104 |
110 | ))}
111 | {searchResults.length === 0 && (
112 |
113 | {lyrics}
114 |
115 | )}
116 |
117 |
118 |
128 |
129 | );
130 | }
131 |
--------------------------------------------------------------------------------