Add warning messages
This commit is contained in:
parent
37f92bcc74
commit
f4791e6e99
69
omp/omp.py
69
omp/omp.py
|
@ -62,7 +62,7 @@ class Omp(object):
|
||||||
self = super(Comp, cls).__new__(cls)
|
self = super(Comp, cls).__new__(cls)
|
||||||
self.play_backward, self.reading = False, False
|
self.play_backward, self.reading = False, False
|
||||||
self.playing = -1
|
self.playing = -1
|
||||||
self.json_file, self.mode = json_file
|
self.json_file, self.mode = json_file, mode
|
||||||
self.entries, self.played = entries, []
|
self.entries, self.played = entries, []
|
||||||
self.playlist, self.search_res = iter(()), deque()
|
self.playlist, self.search_res = iter(()), deque()
|
||||||
self.mp = MPV(input_default_bindings=True, input_vo_keyboard=True,
|
self.mp = MPV(input_default_bindings=True, input_vo_keyboard=True,
|
||||||
|
@ -79,6 +79,41 @@ class Omp(object):
|
||||||
|
|
||||||
def __enter__(self): return self
|
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):
|
def update_play_list(self, pick):
|
||||||
"""Update the list of entries to be played."""
|
"""Update the list of entries to be played."""
|
||||||
if pick == 'current':
|
if pick == 'current':
|
||||||
|
@ -101,42 +136,12 @@ class Omp(object):
|
||||||
self.playlist = iter(lambda: choice(self.play_list), None)
|
self.playlist = iter(lambda: choice(self.play_list), None)
|
||||||
if self.playing < -1: self.played = self.played[:self.playing+1]
|
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):
|
def next(self, force=False, backward=False):
|
||||||
self.play_backward = backward
|
self.play_backward = backward
|
||||||
if self.mp.idle_active:
|
if self.mp.idle_active:
|
||||||
self.play(force)
|
self.play(force)
|
||||||
else:
|
else:
|
||||||
self.seek(100, 'absolute-percent')
|
self.mp.time_pos = self.mp.duration
|
||||||
if force: self.mp.pause = False
|
if force: self.mp.pause = False
|
||||||
|
|
||||||
def search(self, backward=False):
|
def search(self, backward=False):
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
"title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber"
|
"title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:03:41",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/D5drYkLiLI8",
|
"filename": "https://youtu.be/D5drYkLiLI8",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -64,7 +64,7 @@
|
||||||
"title": "Kygo, Selena Gomez - It Ain't Me (with Selena Gomez) (Audio)"
|
"title": "Kygo, Selena Gomez - It Ain't Me (with Selena Gomez) (Audio)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:03:00",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/Zgmvg-zzctI",
|
"filename": "https://youtu.be/Zgmvg-zzctI",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -80,7 +80,7 @@
|
||||||
"title": "gplv3.ogg"
|
"title": "gplv3.ogg"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:04:49",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/xvZqHgFz51I",
|
"filename": "https://youtu.be/xvZqHgFz51I",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -88,7 +88,7 @@
|
||||||
"title": "Future - Mask Off"
|
"title": "Future - Mask Off"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:03:47",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/8j9zMok6two",
|
"filename": "https://youtu.be/8j9zMok6two",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -96,7 +96,7 @@
|
||||||
"title": "Miley Cyrus - Malibu (Official Video)"
|
"title": "Miley Cyrus - Malibu (Official Video)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:04:17",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/dPI-mRFEIH0",
|
"filename": "https://youtu.be/dPI-mRFEIH0",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -104,7 +104,7 @@
|
||||||
"title": "Katy Perry - Bon Appétit (Official) ft. Migos"
|
"title": "Katy Perry - Bon Appétit (Official) ft. Migos"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:04:06",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/aatr_2MstrI",
|
"filename": "https://youtu.be/aatr_2MstrI",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -120,7 +120,7 @@
|
||||||
"title": "Nicole Ray and James Deen"
|
"title": "Nicole Ray and James Deen"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:04:16",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/7F37r50VUTQ",
|
"filename": "https://youtu.be/7F37r50VUTQ",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
"title": "ZAYN, Taylor Swift - I Don’t Wanna Live Forever (Fifty Shades Darker)"
|
"title": "ZAYN, Taylor Swift - I Don’t Wanna Live Forever (Fifty Shades Darker)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:04:57",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/qFLhGq0060w",
|
"filename": "https://youtu.be/qFLhGq0060w",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -144,7 +144,7 @@
|
||||||
"title": "toystory.mp4"
|
"title": "toystory.mp4"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:05:13",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/6ImFf__U6io",
|
"filename": "https://youtu.be/6ImFf__U6io",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -152,7 +152,7 @@
|
||||||
"title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine"
|
"title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:03:56",
|
"duration": "00:03:55",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://www.youtube.com/watch?v=3M3xfu0m5o4",
|
"filename": "https://www.youtube.com/watch?v=3M3xfu0m5o4",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
@ -243,7 +243,7 @@
|
||||||
"duration": "00:03:36",
|
"duration": "00:03:36",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/7wtfhZwyrcc",
|
"filename": "https://youtu.be/7wtfhZwyrcc",
|
||||||
"playing": true,
|
"playing": false,
|
||||||
"selected": false,
|
"selected": false,
|
||||||
"title": "Imagine Dragons - Believer"
|
"title": "Imagine Dragons - Believer"
|
||||||
},
|
},
|
||||||
|
@ -288,7 +288,7 @@
|
||||||
"title": "Shawn Mendes - There's Nothing Holdin' Me Back (Lyric Video)"
|
"title": "Shawn Mendes - There's Nothing Holdin' Me Back (Lyric Video)"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"duration": "00:00:00",
|
"duration": "00:03:51",
|
||||||
"error": false,
|
"error": false,
|
||||||
"filename": "https://youtu.be/FG9M0aEpJGE",
|
"filename": "https://youtu.be/FG9M0aEpJGE",
|
||||||
"playing": false,
|
"playing": false,
|
||||||
|
|
Loading…
Reference in New Issue