Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/JeanBaptiste-dlb/Skiptify
Browse files Browse the repository at this point in the history
…into develop
  • Loading branch information
noeminellen committed Oct 23, 2022
2 parents 3ca35f7 + f1320ff commit f09deba
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
13 changes: 12 additions & 1 deletion backend/src/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
from backend
from backend.src.spotify_api.skip_listener import SKIP_LISTENER
from backend.src.model.decision_maker import DecisionLoop
from backend.src.config import settings
from multiprocessing import Process

def main():
processes=[]
loop_1=DecisionLoop()
loop_2=SKIP_LISTENER()
p1 = Process(target=loop_1.decision_maker(), args=())
processes.append(p1)
p2 = Process(target=loop_2.decision_maker(), args=())
processes.append(p2)

if __name__ == "__main__":
main()
10 changes: 6 additions & 4 deletions backend/src/model/decision_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from backend.src.spotify_api.api_interface import SPOTIFY_API_INTERFACE
import pandas as pd
from pathlib import Path
import time

class DecisionLoop:
def __init__(self):
Expand All @@ -15,19 +16,20 @@ def __init__(self):
self.all_skipped = []
self.all_non_skipped = []
self.next_song = None
self.to_skip_path=Path(settings.APP_PATH, "tmp", "to_skip")
self.to_skip_path=Path(settings.DATA_PATH, "tmp", "to_skip")
self.to_skip_path.mkdir(parents=True, exist_ok= True)

def decision_maker(self):
while True:
next_song = self.interface.get_next_song()
if next_song != self.next_song:
print("wrote a decision")
self.next_song = next_song
skip_decision = self.interface.is_song_skipped(next_song["id"])
skip_decision = self.interface.is_song_skipped(next_song)
# true or false
with open(self.to_skip_path, "w") as writer:
with open(Path(self.to_skip_path, "skip_decision.txt"), "w") as writer:
writer.write(str(skip_decision))
sleep(5)
time.sleep(5)

def main():
loop=DecisionLoop()
Expand Down
5 changes: 2 additions & 3 deletions backend/src/spotify_api/skip_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
self.end_time = 0
self.all_skipped = []
self.all_non_skipped = []
self.to_skip_path = Path(settings.APP_PATH, "tmp", "to_skip")
self.to_skip_path = Path(settings.DATA_PATH, "tmp", "to_skip")
self.actioner = SpotifyActioner()
Path(settings.DATA_PATH, "player_data").mkdir(parents=True, exist_ok = True)

Expand All @@ -32,13 +32,12 @@ def listen(self):
self.update_end_time()
while True:
if time.time() > self.end_time:

with open(self.to_skip_path, "r") as reader:
line = reader.readline()
if line == "True":
self.interface.save_song_features(self.current_song, skip_state="SKIPPED BY ALGORITHM")
self.actioner.skip_current_song()
with open(self.to_skip_path, "w") as writer:
with open(Path(self.to_skip_path, "skip_decision.txt"), "w") as writer:
writer.write("False")
self.current_song = self.interface.get_current_song()
self.previous_song = self.current_song
Expand Down
1 change: 1 addition & 0 deletions backend/src/spotify_api/spotify_actioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def _update_scope(self, scope: str):

def skip_current_song(self) -> None:
self._update_scope(scope="user-modify-playback-state")
print("skipped algorithmically")
song = self.interface.get_current_song()
self.sp.next_track()

Expand Down
1 change: 1 addition & 0 deletions tmp/to_skip/skip_decision.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
True

0 comments on commit f09deba

Please sign in to comment.