2020-02-16 19:51:14 +01:00
|
|
|
#!/usr/bin/env python
|
2020-02-16 16:49:10 +01:00
|
|
|
import json
|
2020-03-01 18:29:45 +01:00
|
|
|
import os
|
2020-02-16 16:49:10 +01:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
import kivy
|
|
|
|
kivy.require('1.11.1')
|
|
|
|
|
|
|
|
from kivy.app import App
|
2020-02-16 18:46:30 +01:00
|
|
|
from kivy.config import Config
|
2020-02-16 16:49:10 +01:00
|
|
|
from kivy.core.window import Window
|
|
|
|
from kivy.properties import StringProperty, ObjectProperty, ListProperty, BooleanProperty
|
2020-03-01 18:29:45 +01:00
|
|
|
from kivy.resources import resource_add_path
|
2020-02-16 16:49:10 +01:00
|
|
|
from kivy.uix.boxlayout import BoxLayout
|
|
|
|
from kivy.uix.button import Button
|
|
|
|
from kivy.uix.widget import Widget
|
|
|
|
|
2020-09-25 18:04:42 +02:00
|
|
|
from negromate.songs import load_songs
|
2020-02-16 16:49:10 +01:00
|
|
|
|
2020-09-25 18:04:42 +02:00
|
|
|
|
|
|
|
class SongWidget(BoxLayout):
|
2020-02-16 16:49:10 +01:00
|
|
|
active = BooleanProperty(False)
|
2020-09-25 18:04:42 +02:00
|
|
|
song = ObjectProperty('')
|
2020-02-16 16:49:10 +01:00
|
|
|
|
|
|
|
@property
|
2020-09-25 18:04:42 +02:00
|
|
|
def name(self):
|
|
|
|
return self.song.name
|
2020-02-16 16:49:10 +01:00
|
|
|
|
|
|
|
@property
|
|
|
|
def subtitle(self):
|
2020-09-25 18:04:42 +02:00
|
|
|
return self.song.karaoke_ass or self.song.ass or self.song.srt or self.song.vtt
|
|
|
|
|
|
|
|
@property
|
|
|
|
def video(self):
|
|
|
|
return self.song.video
|
|
|
|
|
|
|
|
@property
|
|
|
|
def cover(self):
|
|
|
|
return str(self.song.cover)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def thumbnail(self):
|
|
|
|
return str(self.song.thumbnail)
|
2020-02-16 16:49:10 +01:00
|
|
|
|
|
|
|
|
|
|
|
class KaraokeGUI(BoxLayout):
|
|
|
|
active_song = ObjectProperty(None)
|
|
|
|
songs = ListProperty([])
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.keyboard = Window.request_keyboard(
|
|
|
|
self.keyboard_closed,
|
|
|
|
self,
|
|
|
|
'text',
|
|
|
|
)
|
|
|
|
self.keyboard.bind(on_key_down=self.on_key_down)
|
|
|
|
|
|
|
|
def on_key_down(self, keyboard, keycode, text, modifiers):
|
|
|
|
if text == 'a':
|
|
|
|
self.previous()
|
|
|
|
return True
|
|
|
|
elif text == 'd':
|
|
|
|
self.next()
|
|
|
|
return True
|
|
|
|
elif text == 's':
|
|
|
|
self.play()
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def keyboard_closed(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_songs(self, instance, value):
|
|
|
|
container = self.ids['song_container']
|
|
|
|
container.clear_widgets()
|
|
|
|
for song in self.songs:
|
|
|
|
container.add_widget(song)
|
|
|
|
self.active_song = self.songs[0]
|
|
|
|
|
|
|
|
def on_active_song(self, instance, value):
|
|
|
|
for song in self.songs:
|
|
|
|
song.active = False
|
|
|
|
value.active = True
|
|
|
|
current_song_image = self.ids['current_song_image']
|
2020-02-16 18:46:30 +01:00
|
|
|
current_song_title = self.ids['current_song_title']
|
2020-02-16 16:49:10 +01:00
|
|
|
current_song_image.source = value.cover
|
2020-02-16 18:46:30 +01:00
|
|
|
current_song_title.text = value.name
|
2020-02-16 16:49:10 +01:00
|
|
|
|
|
|
|
scrollview = self.ids['songs_scroll']
|
|
|
|
scrollview.scroll_to(value)
|
|
|
|
|
|
|
|
def previous(self):
|
|
|
|
idx = self.songs.index(self.active_song)
|
|
|
|
|
|
|
|
if idx > 0:
|
|
|
|
idx -= 1
|
|
|
|
else:
|
|
|
|
idx = len(self.songs) - 1
|
|
|
|
|
|
|
|
self.active_song = self.songs[idx]
|
|
|
|
|
|
|
|
def next(self):
|
|
|
|
idx = self.songs.index(self.active_song)
|
|
|
|
|
|
|
|
if idx < len(self.songs) - 1:
|
|
|
|
idx += 1
|
|
|
|
else:
|
|
|
|
idx = 0
|
|
|
|
|
|
|
|
self.active_song = self.songs[idx]
|
|
|
|
|
|
|
|
def play(self):
|
|
|
|
subprocess.call([
|
|
|
|
'vlc',
|
|
|
|
'--fullscreen',
|
2020-09-22 19:11:53 +02:00
|
|
|
'--no-sub-autodetect-file',
|
2020-02-16 16:49:10 +01:00
|
|
|
'--sub-file',
|
|
|
|
self.active_song.subtitle,
|
|
|
|
self.active_song.video,
|
|
|
|
'vlc://quit'
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
class KaraokeApp(App):
|
2020-03-01 18:29:45 +01:00
|
|
|
kv_directory = os.path.join(os.path.dirname(__file__, ), 'kv_templates')
|
2020-02-16 16:49:10 +01:00
|
|
|
|
|
|
|
def __init__(self, root_folder, **kwargs):
|
|
|
|
super().__init__(**kwargs)
|
|
|
|
self.root_folder = root_folder
|
|
|
|
|
|
|
|
def build(self):
|
|
|
|
super().build()
|
2020-09-25 18:04:42 +02:00
|
|
|
songs, pending_songs = load_songs(self.root_folder)
|
2020-03-01 18:29:45 +01:00
|
|
|
songs.sort(key=lambda a: a.name.lower())
|
2020-09-25 18:04:42 +02:00
|
|
|
self.root.songs = [SongWidget(song=s) for s in songs]
|
2020-02-16 16:49:10 +01:00
|
|
|
return self.root
|
|
|
|
|
|
|
|
|
2020-03-01 18:29:45 +01:00
|
|
|
def main():
|
|
|
|
if len(sys.argv) == 2:
|
|
|
|
path = sys.argv[1]
|
|
|
|
else:
|
|
|
|
path = '../bideoak/'
|
2020-02-16 19:51:14 +01:00
|
|
|
# Window.fullscreen = True
|
2020-03-01 18:29:45 +01:00
|
|
|
resource_add_path(os.path.dirname(__file__))
|
|
|
|
Config.set('graphics', 'font_name', 'resources/fonts/CyrBit.ttf')
|
2020-02-16 18:46:30 +01:00
|
|
|
Config.write()
|
2020-03-01 18:29:45 +01:00
|
|
|
KaraokeApp(Path(path)).run()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|