Add warning messages

This commit is contained in:
Nguyễn Gia Phong 2018-01-25 17:30:46 +07:00
parent 37f92bcc74
commit f4791e6e99
2 changed files with 49 additions and 44 deletions

View File

@ -62,7 +62,7 @@ class Omp(object):
self = super(Comp, cls).__new__(cls)
self.play_backward, self.reading = False, False
self.playing = -1
self.json_file, self.mode = json_file
self.json_file, self.mode = json_file, mode
self.entries, self.played = entries, []
self.playlist, self.search_res = iter(()), deque()
self.mp = MPV(input_default_bindings=True, input_vo_keyboard=True,
@ -79,6 +79,41 @@ class Omp(object):
def __enter__(self): return self
def seek(self, amount, reference='relative', precision='default-precise'):
"""Wrap a try clause around mp.seek to avoid crashing when
nothing is being played.
"""
try:
self.mp.seek(amount, reference, precision)
except:
self.print_msg(_("Failed to seek"), error=True)
def add(self, name, value=1):
"""Wrap a try clause around mp.property_add."""
try:
self.mp.property_add(name, value)
except:
self.print_msg(
_("Failed to add {} to '{}'").format(value, name), error=True)
def multiply(self, name, factor):
"""Wrap a try clause around mp.property_multiply."""
try:
self.mp.property_multiply(name, factor)
except:
self.print_msg(
_("Failed to multiply '{}' with {}").format(name, value),
error=True)
def cycle(self, name, direction='up'):
"""Wrap a try clause around mp.cycle."""
try:
self.mp.cycle(name, direction='up')
except:
self.print_msg(
_("Failed to cycle {} '{}'").format(direction, name),
error=True)
def update_play_list(self, pick):
"""Update the list of entries to be played."""
if pick == 'current':
@ -101,42 +136,12 @@ class Omp(object):
self.playlist = iter(lambda: choice(self.play_list), None)
if self.playing < -1: self.played = self.played[:self.playing+1]
def seek(self, amount, reference='relative', precision='default-precise'):
"""Wrap a try clause around mp.seek to avoid crashing when
nothing is being played.
"""
try:
self.mp.seek(amount, reference, precision)
except:
pass
def add(self, name, value=1):
"""Wrap a try clause around mp.property_add."""
try:
self.mp.property_add(name, value)
except:
pass
def cycle(self, name, direction='up'):
"""Wrap a try clause around mp.cycle."""
try:
self.mp.cycle(name, direction='up')
except:
pass
def multiply(self, name, factor):
"""Wrap a try clause around mp.property_multiply."""
try:
self.mp.property_multiply(name, factor)
except:
pass
def next(self, force=False, backward=False):
self.play_backward = backward
if self.mp.idle_active:
self.play(force)
else:
self.seek(100, 'absolute-percent')
self.mp.time_pos = self.mp.duration
if force: self.mp.pause = False
def search(self, backward=False):

View File

@ -56,7 +56,7 @@
"title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber"
},
{
"duration": "00:00:00",
"duration": "00:03:41",
"error": false,
"filename": "https://youtu.be/D5drYkLiLI8",
"playing": false,
@ -64,7 +64,7 @@
"title": "Kygo, Selena Gomez - It Ain't Me (with Selena Gomez) (Audio)"
},
{
"duration": "00:00:00",
"duration": "00:03:00",
"error": false,
"filename": "https://youtu.be/Zgmvg-zzctI",
"playing": false,
@ -80,7 +80,7 @@
"title": "gplv3.ogg"
},
{
"duration": "00:00:00",
"duration": "00:04:49",
"error": false,
"filename": "https://youtu.be/xvZqHgFz51I",
"playing": false,
@ -88,7 +88,7 @@
"title": "Future - Mask Off"
},
{
"duration": "00:00:00",
"duration": "00:03:47",
"error": false,
"filename": "https://youtu.be/8j9zMok6two",
"playing": false,
@ -96,7 +96,7 @@
"title": "Miley Cyrus - Malibu (Official Video)"
},
{
"duration": "00:00:00",
"duration": "00:04:17",
"error": false,
"filename": "https://youtu.be/dPI-mRFEIH0",
"playing": false,
@ -104,7 +104,7 @@
"title": "Katy Perry - Bon Appétit (Official) ft. Migos"
},
{
"duration": "00:00:00",
"duration": "00:04:06",
"error": false,
"filename": "https://youtu.be/aatr_2MstrI",
"playing": false,
@ -120,7 +120,7 @@
"title": "Nicole Ray and James Deen"
},
{
"duration": "00:00:00",
"duration": "00:04:16",
"error": false,
"filename": "https://youtu.be/7F37r50VUTQ",
"playing": false,
@ -128,7 +128,7 @@
"title": "ZAYN, Taylor Swift - I Dont Wanna Live Forever (Fifty Shades Darker)"
},
{
"duration": "00:00:00",
"duration": "00:04:57",
"error": false,
"filename": "https://youtu.be/qFLhGq0060w",
"playing": false,
@ -144,7 +144,7 @@
"title": "toystory.mp4"
},
{
"duration": "00:00:00",
"duration": "00:05:13",
"error": false,
"filename": "https://youtu.be/6ImFf__U6io",
"playing": false,
@ -152,7 +152,7 @@
"title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine"
},
{
"duration": "00:03:56",
"duration": "00:03:55",
"error": false,
"filename": "https://www.youtube.com/watch?v=3M3xfu0m5o4",
"playing": false,
@ -243,7 +243,7 @@
"duration": "00:03:36",
"error": false,
"filename": "https://youtu.be/7wtfhZwyrcc",
"playing": true,
"playing": false,
"selected": false,
"title": "Imagine Dragons - Believer"
},
@ -288,7 +288,7 @@
"title": "Shawn Mendes - There's Nothing Holdin' Me Back (Lyric Video)"
},
{
"duration": "00:00:00",
"duration": "00:03:51",
"error": false,
"filename": "https://youtu.be/FG9M0aEpJGE",
"playing": false,