finished base version 1.0 and as such the app is fully functional though there might still be bugs around and also some improvements will be made later on
This commit is contained in:
122
bin/csv_parsers.py
Normal file
122
bin/csv_parsers.py
Normal file
@@ -0,0 +1,122 @@
|
||||
"""@package docstring
|
||||
This is a simplification of the csv module"""
|
||||
|
||||
import csv
|
||||
|
||||
|
||||
class CsvRead:
|
||||
"""This is a class that reads csv files and depending on the module selected does do different things with it"""
|
||||
def __init__(self):
|
||||
self.__imp = ""
|
||||
self.__raw = ""
|
||||
self.__raw_list = ""
|
||||
|
||||
def importing(self, path):
|
||||
"""Returns a list of the imported csv-file, requires path, either direct system path or relative path"""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__raw_list = list(self.__raw)
|
||||
self.__imp.close()
|
||||
return self.__raw_list
|
||||
|
||||
|
||||
class CsvWrite:
|
||||
"""This is a class that modifies csv files"""
|
||||
def __init__(self):
|
||||
self.__impl = []
|
||||
self.__strpop = []
|
||||
self.__removed = []
|
||||
self.__removing = 0
|
||||
self.__change = 0
|
||||
self.__appending = 0
|
||||
self.__imp = []
|
||||
self.__raw = []
|
||||
|
||||
def rem_str(self, path, row):
|
||||
"""Opens the csv-file in write mode which is specified as an argument either as direct or relative path"""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__removed = self.__impl.pop(row + 1)
|
||||
with open(path, "w") as removedata:
|
||||
self.__removing = csv.writer(removedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as removedata:
|
||||
self.__removing = csv.writer(removedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
removedata.close()
|
||||
|
||||
|
||||
def chg_str(self, path, row, pos, new_value):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipes is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.pop(pos)
|
||||
self.__strpop.insert(pos, new_value)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def chg_str_rem(self, path, row, pos):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipes is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.pop(pos)
|
||||
self.__strpop.pop(pos)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def chg_str_add(self, path, row, new_value1, new_value2):
|
||||
"""Opens the csv-file in write mode to change a value, e.g. if a recipes is changed."""
|
||||
self.__imp = open(path)
|
||||
self.__raw = csv.reader(self.__imp, delimiter=',')
|
||||
self.__impl = list(self.__raw)
|
||||
self.__strpop = self.__impl.pop(row)
|
||||
self.__strpop.append(new_value1)
|
||||
self.__strpop.append(new_value2)
|
||||
self.__impl.insert(row, self.__strpop)
|
||||
with open(path, "w") as changedata:
|
||||
self.__change = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(self.__impl.pop(0))
|
||||
while len(self.__impl) > 0:
|
||||
with open(path, "a") as changedata:
|
||||
self.__removing = csv.writer(changedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__removing.writerow(self.__impl.pop(0))
|
||||
self.__imp.close()
|
||||
changedata.close()
|
||||
|
||||
def app_str(self, path, value):
|
||||
"""Opens the csv-file in append mode and writes given input. CsvWrite.app_str(path, value).
|
||||
Path can be specified both as direct or relative. value is a list. Will return an error if type of value is
|
||||
not a list."""
|
||||
with open(path, "a") as appenddata:
|
||||
self.__appending = csv.writer(appenddata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__appending.writerow(value)
|
||||
appenddata.close()
|
||||
|
||||
def write_str(self, path, value):
|
||||
with open(path, "w") as writedata:
|
||||
self.__change = csv.writer(writedata, delimiter=',', quoting=csv.QUOTE_MINIMAL)
|
||||
self.__change.writerow(value)
|
||||
writedata.close()
|
||||
26
bin/filepathanalysis.py
Normal file
26
bin/filepathanalysis.py
Normal file
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
|
||||
|
||||
class PathAnalysis:
|
||||
def __init__(self):
|
||||
self.__output = []
|
||||
self.__input = []
|
||||
self.__file_extension = ""
|
||||
self.__filepath = ""
|
||||
self.__returns = []
|
||||
self.__names = []
|
||||
|
||||
def validsonglistcreator(self, path):
|
||||
self.__input = os.listdir(path)
|
||||
for self.item in self.__input:
|
||||
self.__file_extension = self.item[(len(self.item) - 4):]
|
||||
if self.__file_extension == ".mp3" or self.__file_extension == ".wav":
|
||||
self.__filepath = str(path)
|
||||
self.__filepath += f"/{str(self.item)}"
|
||||
self.__names.append(self.item)
|
||||
self.__output.append(self.__filepath)
|
||||
else:
|
||||
pass
|
||||
self.__returns.append(self.__output)
|
||||
self.__returns.append(self.__names)
|
||||
return self.__returns
|
||||
113
bin/gui/gui.kv
113
bin/gui/gui.kv
@@ -1,6 +1,11 @@
|
||||
RootScreen:
|
||||
Home:
|
||||
Main:
|
||||
ShowcaseS
|
||||
|
||||
###########
|
||||
# POPUPS
|
||||
###########
|
||||
|
||||
<PathMissingPU>:
|
||||
title: "NOTICE!"
|
||||
@@ -20,6 +25,46 @@ RootScreen:
|
||||
on_release:
|
||||
root.dismiss()
|
||||
|
||||
<PathWrongPU>:
|
||||
title: "NOTICE!"
|
||||
font_size: 50
|
||||
size_hint: 0.5, 0.4
|
||||
auto_dismiss: False
|
||||
GridLayout:
|
||||
cols:1
|
||||
Label:
|
||||
text: "Path without any mp3/wav files specified"
|
||||
font_size: 18
|
||||
Label:
|
||||
text: "Please enter another path and try again"
|
||||
font_size: 15
|
||||
Button:
|
||||
text:"Ok"
|
||||
on_release:
|
||||
root.dismiss()
|
||||
|
||||
<invalidpathPU>:
|
||||
title: "NOTICE!"
|
||||
font_size: 50
|
||||
size_hint: 0.5, 0.4
|
||||
auto_dismiss: False
|
||||
GridLayout:
|
||||
cols:1
|
||||
Label:
|
||||
text: "Invalid path specified"
|
||||
font_size: 18
|
||||
Label:
|
||||
text: "Please enter a valid path and try again"
|
||||
font_size: 15
|
||||
Button:
|
||||
text:"Ok"
|
||||
on_release:
|
||||
root.dismiss()
|
||||
|
||||
###########
|
||||
# SCREENS
|
||||
###########
|
||||
|
||||
<Home>:
|
||||
name: "Home"
|
||||
md_bg_color: app.theme_cls.accent_color
|
||||
@@ -42,6 +87,7 @@ RootScreen:
|
||||
hint_text: "Path to Folder containing the Music files"
|
||||
pos_hint: {"x":0.2, "y":0.5}
|
||||
size_hint_x: 0.6
|
||||
text: "/home/janis/Downloads"
|
||||
Button:
|
||||
text: "Start"
|
||||
color: app.theme_cls.primary_color
|
||||
@@ -52,11 +98,74 @@ RootScreen:
|
||||
root.change_screen()
|
||||
|
||||
<Main>:
|
||||
on_pre_enter: root.initialize()
|
||||
name: "Main"
|
||||
GridLayout:
|
||||
cols: 1
|
||||
GridLayout:
|
||||
cols: 2
|
||||
Button:
|
||||
text: "Next"
|
||||
on_release:
|
||||
root.nextsong()
|
||||
Button:
|
||||
text: "Rewind"
|
||||
on_release:
|
||||
root.rewindsong()
|
||||
Button:
|
||||
text: "Back"
|
||||
text: "Play"
|
||||
id: pp_button
|
||||
on_release:
|
||||
app.root.current = "Home"
|
||||
root.playmusic()
|
||||
GridLayout:
|
||||
cols: 2
|
||||
Button:
|
||||
text: "Back"
|
||||
on_release:
|
||||
root.go_back()
|
||||
Button:
|
||||
text: "Showcase"
|
||||
on_release:
|
||||
app.root.current = "Showcase"
|
||||
root.manager.transition.direction = "left"
|
||||
|
||||
|
||||
<ShowcaseS>:
|
||||
on_pre_enter: root.screen_updater_start()
|
||||
name: "Showcase"
|
||||
md_bg_color: (0, 0, 0, 1)
|
||||
FloatLayout:
|
||||
Label:
|
||||
text: "Currently Playing"
|
||||
pos_hint: {"y": 0.4}
|
||||
font_size: 35
|
||||
color: app.theme_cls.primary_color
|
||||
MDProgressBar:
|
||||
orientation: "horizontal"
|
||||
value: 100
|
||||
pos_hint: {"y": 0.35}
|
||||
color: app.theme_cls.primary_dark
|
||||
Label:
|
||||
id: current_song
|
||||
text: "Currently playing Song will appear here"
|
||||
pos_hint: {"y": 0.25}
|
||||
font_size: 30
|
||||
color: app.theme_cls.primary_color
|
||||
Label:
|
||||
text: "upcoming"
|
||||
font_size: 25
|
||||
color: app.theme_cls.primary_color
|
||||
Label:
|
||||
id: upcoming_songs
|
||||
text: "Upcoming Songs will appear here"
|
||||
pos_hint: {"y": -0.25}
|
||||
font_size: 20
|
||||
color: app.theme_cls.primary_color
|
||||
Button:
|
||||
text: "back"
|
||||
font_size: 10
|
||||
size_hint: 0.05, 0.05
|
||||
background_color: app.theme_cls.accent_light
|
||||
on_release:
|
||||
app.root.current = "Main"
|
||||
root.manager.transition.direction = "right"
|
||||
96
bin/player.py
Normal file
96
bin/player.py
Normal file
@@ -0,0 +1,96 @@
|
||||
import pygame.mixer as mx
|
||||
import bin.csv_parsers
|
||||
import copy
|
||||
import bin.filepathanalysis
|
||||
import pygame
|
||||
import time
|
||||
|
||||
pa = bin.filepathanalysis.PathAnalysis()
|
||||
cvr = bin.csv_parsers.CsvRead()
|
||||
cvw = bin.csv_parsers.CsvWrite()
|
||||
|
||||
|
||||
class Player:
|
||||
def __init__(self):
|
||||
self.__running = 1
|
||||
self.event = ""
|
||||
self.__recent_change = 1000000
|
||||
self.__imports = []
|
||||
self.information = []
|
||||
self.current_playing_pos = 0
|
||||
|
||||
def start_playing(self):
|
||||
# initialize playing
|
||||
if pygame.get_init() == True:
|
||||
pass
|
||||
else:
|
||||
pygame.init()
|
||||
self.path = cvr.importing("./data/temp.csv").pop(0)
|
||||
self.__imports = pa.validsonglistcreator(self.path.pop())
|
||||
self.playlist = self.__imports.pop(0)
|
||||
self.playlist_backup = copy.deepcopy(self.playlist)
|
||||
self.information = self.__imports.pop(0)
|
||||
mx.init()
|
||||
self.current_playing = self.playlist.pop(0)
|
||||
mx.music.load(self.current_playing)
|
||||
mx.music.play()
|
||||
mx.music.pause()
|
||||
|
||||
def infoupdater(self):
|
||||
self.transmission = []
|
||||
cvw.write_str("./data/songtemp.csv", [self.current_playing_pos])
|
||||
cvw.app_str("./data/songtemp.csv", self.information)
|
||||
|
||||
def musicmanager(self, inst, other):
|
||||
self.start_playing()
|
||||
self.infoupdater()
|
||||
while self.__running == 1:
|
||||
if self.__recent_change < 1:
|
||||
pass
|
||||
else:
|
||||
self.__recent_change -= 1
|
||||
# instructions from main class
|
||||
if other.value == 1:
|
||||
other.value = 0
|
||||
mx.music.unload()
|
||||
if len(self.playlist) > 0:
|
||||
pass
|
||||
else:
|
||||
self.playlist = copy.deepcopy(self.playlist_backup)
|
||||
self.current_playing_pos = -1
|
||||
self.current_playing = self.playlist.pop(0)
|
||||
self.current_playing_pos += 1
|
||||
mx.music.load(self.current_playing)
|
||||
mx.music.play()
|
||||
self.__recent_change = 1000000
|
||||
self.infoupdater()
|
||||
|
||||
elif other.value == 2:
|
||||
mx.music.rewind()
|
||||
other.value = 0
|
||||
|
||||
elif other.value == 3:
|
||||
self.__recent_change = 1000000
|
||||
other.value = 0
|
||||
else:
|
||||
if inst.value == 1:
|
||||
mx.music.unpause()
|
||||
else:
|
||||
mx.music.pause()
|
||||
# Main event-checking part
|
||||
if mx.music.get_busy() is False and inst.value == 1 and self.__recent_change == 0:
|
||||
mx.music.unload()
|
||||
if len(self.playlist) > 0:
|
||||
pass
|
||||
else:
|
||||
self.playlist = copy.deepcopy(self.playlist_backup)
|
||||
self.current_playing_pos = -1
|
||||
self.current_playing = self.playlist.pop(0)
|
||||
self.current_playing_pos += 1
|
||||
mx.music.load(self.current_playing)
|
||||
mx.music.play()
|
||||
self.__recent_change = 10000000
|
||||
self.infoupdater()
|
||||
else:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user