mirror of
https://github.com/cgzirim/seek-tune.git
synced 2025-12-17 08:54:19 +00:00
commit
2e18fa5cfe
7 changed files with 80 additions and 12 deletions
|
|
@ -11,10 +11,9 @@ import "react-toastify/dist/ReactToastify.css";
|
|||
import { MediaRecorder, register } from "extendable-media-recorder";
|
||||
import { connect } from "extendable-media-recorder-wav-encoder";
|
||||
|
||||
const backendServer =
|
||||
process.env.REACT_APP_BACKEND_URL || "http://localhost:5000";
|
||||
const server = process.env.REACT_APP_BACKEND_URL || "http://localhost:5000";
|
||||
|
||||
var socket = io(backendServer);
|
||||
var socket = io(server);
|
||||
|
||||
function App() {
|
||||
const [stream, setStream] = useState();
|
||||
|
|
@ -299,7 +298,6 @@ function App() {
|
|||
closeOnClick
|
||||
rtl={false}
|
||||
pauseOnFocusLoss
|
||||
draggable
|
||||
pauseOnHover
|
||||
theme="light"
|
||||
transition={Slide}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,14 @@ const CarouselSliders = (props) => {
|
|||
const [activeVideoID, setActiveVideoID] = useState(null);
|
||||
const players = useRef({});
|
||||
|
||||
const activeVid = props.matches.length ? props.matches[0].YouTubeID : "";
|
||||
|
||||
useEffect(() => {
|
||||
setActiveVideoID(activeVid);
|
||||
if (props.matches.length > 0) {
|
||||
const firstVideoID = props.matches[0].YouTubeID;
|
||||
document
|
||||
.getElementById(`slide-${firstVideoID}`)
|
||||
.scrollIntoView({ behavior: "smooth" });
|
||||
setActiveVideoID(firstVideoID);
|
||||
}
|
||||
}, [props.matches]);
|
||||
|
||||
const onReady = (event, videoId) => {
|
||||
|
|
@ -72,7 +76,11 @@ const CarouselSliders = (props) => {
|
|||
: `${styles.Link} ${styles.ActiveLink}`
|
||||
}
|
||||
href={`#slide-${match.YouTubeID}`}
|
||||
onClick={() => {
|
||||
onClick={(e) => {
|
||||
e.preventDefault();
|
||||
document
|
||||
.getElementById(`slide-${match.YouTubeID}`)
|
||||
.scrollIntoView({ behavior: "smooth" });
|
||||
setActiveVideoID(match.YouTubeID);
|
||||
}}
|
||||
></a>
|
||||
|
|
|
|||
|
|
@ -7,6 +7,8 @@ import (
|
|||
"log"
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"song-recognition/shazam"
|
||||
"song-recognition/spotify"
|
||||
"song-recognition/utils"
|
||||
|
|
@ -188,3 +190,51 @@ func serveHTTP(socketServer *socketio.Server, serveHTTPS bool, port string) {
|
|||
log.Fatalf("HTTP server ListenAndServe: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func erase(songsDir string) {
|
||||
logger := utils.GetLogger()
|
||||
ctx := context.Background()
|
||||
|
||||
// wipe db
|
||||
dbClient, err := utils.NewDbClient()
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Error creating DB client: %v\n", err)
|
||||
logger.ErrorContext(ctx, msg, slog.Any("error", err))
|
||||
}
|
||||
|
||||
err = dbClient.DeleteCollection("fingerprints")
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Error deleting collection: %v\n", err)
|
||||
logger.ErrorContext(ctx, msg, slog.Any("error", err))
|
||||
}
|
||||
|
||||
err = dbClient.DeleteCollection("songs")
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Error deleting collection: %v\n", err)
|
||||
logger.ErrorContext(ctx, msg, slog.Any("error", err))
|
||||
}
|
||||
|
||||
// delete song files
|
||||
err = filepath.Walk(songsDir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !info.IsDir() {
|
||||
ext := filepath.Ext(path)
|
||||
if ext == ".wav" || ext == ".m4a" {
|
||||
err := os.Remove(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("Error walking through directory %s: %v\n", songsDir, err)
|
||||
logger.ErrorContext(ctx, msg, slog.Any("error", err))
|
||||
}
|
||||
|
||||
fmt.Println("Erase successful")
|
||||
}
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
func main() {
|
||||
if len(os.Args) < 2 {
|
||||
fmt.Println("Expected 'find', 'download', or 'serve' subcommands")
|
||||
fmt.Println("Expected 'find', 'download', 'erase', or 'serve' subcommands")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
|
|
@ -33,8 +33,10 @@ func main() {
|
|||
port := serveCmd.String("p", "5000", "Port to use")
|
||||
serveCmd.Parse(os.Args[2:])
|
||||
serve(*protocol, *port)
|
||||
case "erase":
|
||||
erase(SONGS_DIR)
|
||||
default:
|
||||
fmt.Println("Expected 'find', 'download', or 'serve' subcommands")
|
||||
fmt.Println("Expected 'find', 'download', 'erase', or 'serve' subcommands")
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -213,7 +213,7 @@ func handleNewRecording(socket socketio.Conn, recordData string) {
|
|||
logger.ErrorContext(ctx, "failed to convert decodedData to samples.", slog.Any("error", err))
|
||||
}
|
||||
|
||||
/** this operation alters the audio, adding some level of bass to it.
|
||||
/** this operation alters the audio, adds some level of bass to it.
|
||||
if sampleRate != 44100 {
|
||||
samples, err = shazam.Downsample(samples, sampleRate, 44100)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -146,8 +146,9 @@ func dlTrack(tracks []Track, path string) (int, error) {
|
|||
return
|
||||
}
|
||||
|
||||
if DELETE_SONG_FILE {
|
||||
DeleteFile(filepath.Join(path, fileName+".m4a"))
|
||||
|
||||
if DELETE_SONG_FILE {
|
||||
DeleteFile(filepath.Join(path, fileName+".wav"))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -214,3 +214,12 @@ func (db *DbClient) DeleteSongByID(songID uint32) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (db *DbClient) DeleteCollection(collectionName string) error {
|
||||
collection := db.client.Database("song-recognition").Collection(collectionName)
|
||||
err := collection.Drop(context.Background())
|
||||
if err != nil {
|
||||
return fmt.Errorf("error deleting collection: %v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue