-
Notifications
You must be signed in to change notification settings - Fork 1
/
player.py
79 lines (65 loc) · 2.59 KB
/
player.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import db
from threading import Thread
from db import kodi
class Player(Thread):
def __init__(self, event):
Thread.__init__(self)
self.stopped = event
self.kodi = kodi()
def run(self):
while not self.stopped.wait(2):
if not self.is_playing():
self.play_new_song()
if self.is_finish_playing() and db.data_exist():
self.stop_player()
self.play_new_song()
def is_finish_playing(self):
result = self.kodi.Player.GetProperties(playerid=1, properties=["percentage"])
if float(result['result']['percentage']) >= 98:
return True
else:
return False
def stop_player(self):
self.kodi.Player.Stop(playerid=1)
def play_new_song(self):
song = db.play_next()
if song:
try:
db.set_to_done()
self.play_the_song(song)
except:
None
elif db.is_working():
db.next_alternative_song()
def play_the_song(self, play):
self.kodi.VideoLibrary.Scan()
result = self.kodi.Player.Open(item={"file": str(db.path() + play['title'] + ".mp4")})
self.kodi.GUI.ShowNotification(title=play['title'], message="Now Playing", displaytime=20000)
if 'error' in result:
if play['error'] >= 20:
db.update(play['youtube_id'], 'error', 0)
db.update(play['youtube_id'], 'status', 'error')
self.kodi.VideoLibrary.Scan()
db.update(play['youtube_id'], 'error', play['error'] + 1)
else:
db.set_to_done()
db.update(play['youtube_id'], 'status', 'playing')
def play_current_song(self):
if not self.is_playing():
play = db.current_playing_song()
if play:
self.kodi.VideoLibrary.Scan()
result = self.kodi.Player.Open(item={"file": str(db.path() + play['title'] + ".mp4")})
self.kodi.GUI.ShowNotification(title=play['title'], message="Now Playing", displaytime=20000)
if 'error' in result:
if play['error'] >= 20:
db.update(play['youtube_id'], 'error', 0)
db.update(play['youtube_id'], 'status', 'error')
self.kodi.VideoLibrary.Scan()
db.update(play['youtube_id'], 'error', play['error'] + 1)
def is_playing(self):
active = self.kodi.Player.GetActivePlayers()
if active['result']:
return True
else:
return False