Make comp ask to dump when quit and dump less bullsh*t

This commit is contained in:
Nguyễn Gia Phong 2018-01-30 17:08:47 +07:00
parent 082685cee3
commit f8185d1b31
6 changed files with 41 additions and 165 deletions

11
comp
View File

@ -93,6 +93,7 @@ class Comp(Omp):
previously on the display. previously on the display.
""" """
if self.reading: return if self.reading: return
curses.update_lines_cols()
y %= curses.LINES y %= curses.LINES
x %= curses.COLS x %= curses.COLS
length = X % curses.COLS - x + (y != curses.LINES - 1) length = X % curses.COLS - x + (y != curses.LINES - 1)
@ -348,8 +349,9 @@ if args.vo is not None: mpv_args['vo'] = args.vo
ytdlf = args.format or config.get('youtube-dl', 'format', fallback='best') ytdlf = args.format or config.get('youtube-dl', 'format', fallback='best')
with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp: with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp:
c = comp.scr.get_wch() while True:
while c != 'q': c = comp.scr.get_wch()
comp.print_msg('')
# mpv keybindings # mpv keybindings
if c == curses.KEY_LEFT: if c == curses.KEY_LEFT:
comp.seek(-5, precision='exact') comp.seek(-5, precision='exact')
@ -377,6 +379,10 @@ with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp:
comp.multiply('speed', 2.0) comp.multiply('speed', 2.0)
elif c == curses.KEY_BACKSPACE: elif c == curses.KEY_BACKSPACE:
comp.mp.speed = 1.0 comp.mp.speed = 1.0
elif c == 'q':
comp.print_msg(_("Save playlist? [Y/n]"))
if comp.scr.get_wch() not in _("Nn"): comp.dump_json()
break
elif c in ('p', ' '): elif c in ('p', ' '):
comp.cycle('pause') comp.cycle('pause')
elif c == '.': elif c == '.':
@ -543,4 +549,3 @@ with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp:
comp.mp.command(*comp.read_input(':').split()) comp.mp.command(*comp.read_input(':').split())
except: except:
comp.print_msg(_("Failed to execute command"), error=True) comp.print_msg(_("Failed to execute command"), error=True)
c = comp.scr.get_wch()

Binary file not shown.

View File

@ -1,6 +1,6 @@
# SOME DESCRIPTIVE TITLE. # Vietnamese translation for Omp front-ends.
# Copyright (C) YEAR ORGANIZATION # Copyright (C) 2018 Nguyễn Gia Phong
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR. # Nguyễn Gia Phong <vn.mcsinyx@gmail.com>, 2018
# #
msgid "" msgid ""
msgstr "" msgstr ""
@ -50,6 +50,12 @@ msgstr "Tiêu đề"
msgid "Current size: {}x{}. Minimum size: {}x4." msgid "Current size: {}x{}. Minimum size: {}x4."
msgstr "Kích thước hiện tại: {}x{}. Kích thước tối thiểu: {}x4." msgstr "Kích thước hiện tại: {}x{}. Kích thước tối thiểu: {}x4."
msgid "Save playlist? [Y/n]"
msgstr "Lưu danh sách phát? [C/k]"
msgid "Nn"
msgstr "Kk"
msgid "Save playlist to [{}]: " msgid "Save playlist to [{}]: "
msgstr "Lưu danh sách phát tại [{}]: " msgstr "Lưu danh sách phát tại [{}]: "

View File

@ -27,6 +27,7 @@ from mpv import MPV
DEFAULT_ENTRY = {'filename': '', 'title': '', 'duration': '00:00:00', DEFAULT_ENTRY = {'filename': '', 'title': '', 'duration': '00:00:00',
'error': False, 'playing': False, 'selected': False} 'error': False, 'playing': False, 'selected': False}
JSON_KEYS = 'filename', 'title', 'duration', 'error', 'selected'
class YoutubeDLLogger: class YoutubeDLLogger:

View File

@ -31,7 +31,7 @@ from youtube_dl import YoutubeDL
from pkg_resources import resource_filename from pkg_resources import resource_filename
from mpv import MPV, MpvFormat from mpv import MPV, MpvFormat
from .ie import extract_info from .ie import JSON_KEYS, extract_info
# Init gettext # Init gettext
bindtextdomain('omp', resource_filename('omp', 'locale')) bindtextdomain('omp', resource_filename('omp', 'locale'))
@ -171,19 +171,22 @@ class Omp(object):
self.update_status(_("Pattern not found"), curses.color_pair(1)) self.update_status(_("Pattern not found"), curses.color_pair(1))
def dump_json(self): def dump_json(self):
"""Read user input needed to save the playlist."""
s = self.read_input( s = self.read_input(
_("Save playlist to [{}]: ").format(self.json_file)) _("Save playlist to [{}]: ").format(self.json_file))
self.json_file = abspath(expanduser(expandvars(s or self.json_file))) self.json_file = abspath(expanduser(expandvars(s or self.json_file)))
entries = [{k: v for k, v in entry.items() if k in JSON_KEYS}
for entry in self.entries]
try: try:
makedirs(dirname(self.json_file), exist_ok=True) makedirs(dirname(self.json_file), exist_ok=True)
with open(self.json_file, 'w') as f:
json.dump(entries, f, ensure_ascii=False, indent=2,
sort_keys=True)
except: except:
errmsg = _("'{}': Can't open file for writing").format( errmsg = _("'{}': Can't open file for writing").format(
self.json_file) self.json_file)
self.print_msg(errmsg, error=True) self.print_msg(errmsg, error=True)
else: else:
with open(self.json_file, 'w') as f:
json.dump(self.entries, f, ensure_ascii=False,
indent=2, sort_keys=True)
self.print_msg(_("'{}' written").format(self.json_file)) self.print_msg(_("'{}' written").format(self.json_file))
def __exit__(self, exc_type, exc_value, traceback): def __exit__(self, exc_type, exc_value, traceback):

View File

@ -3,7 +3,6 @@
"duration": "00:05:21", "duration": "00:05:21",
"error": false, "error": false,
"filename": "https://youtu.be/weeI1G46q0o", "filename": "https://youtu.be/weeI1G46q0o",
"playing": false,
"selected": true, "selected": true,
"title": "DJ Khaled - I'm the One ft. Justin Bieber, Quavo, Chance the Rapper, Lil Wayne" "title": "DJ Khaled - I'm the One ft. Justin Bieber, Quavo, Chance the Rapper, Lil Wayne"
}, },
@ -11,47 +10,13 @@
"duration": "00:04:23", "duration": "00:04:23",
"error": false, "error": false,
"filename": "https://youtu.be/JGwWNGJdvx8", "filename": "https://youtu.be/JGwWNGJdvx8",
"playing": false,
"selected": true, "selected": true,
"title": "Ed Sheeran - Shape of You [Official Video]" "title": "Ed Sheeran - Shape of You [Official Video]"
}, },
{
"duration": "00:03:30",
"error": false,
"filename": "https://youtu.be/PMivT7MJ41M",
"playing": false,
"selected": true,
"title": "Bruno Mars - Thats What I Like [Official Video]"
},
{
"duration": "00:04:46",
"error": false,
"filename": "https://youtu.be/CTFtOOh47oo",
"playing": false,
"selected": false,
"title": "French Montana - Unforgettable ft. Swae Lee"
},
{
"duration": "00:04:45",
"error": false,
"filename": "https://youtu.be/NLZRYQMLDW4",
"playing": false,
"selected": false,
"title": "Kendrick Lamar - DNA."
},
{
"duration": "00:04:07",
"error": false,
"filename": "https://youtu.be/FM7MFYoylVs",
"playing": false,
"selected": true,
"title": "The Chainsmokers & Coldplay - Something Just Like This (Lyric)"
},
{ {
"duration": "00:03:48", "duration": "00:03:48",
"error": false, "error": false,
"filename": "https://youtu.be/72UO0v5ESUo", "filename": "https://youtu.be/72UO0v5ESUo",
"playing": false,
"selected": true, "selected": true,
"title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber" "title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber"
}, },
@ -59,47 +24,20 @@
"duration": "00:03:41", "duration": "00:03:41",
"error": false, "error": false,
"filename": "https://youtu.be/D5drYkLiLI8", "filename": "https://youtu.be/D5drYkLiLI8",
"playing": false,
"selected": false, "selected": false,
"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:03:00",
"error": false,
"filename": "https://youtu.be/Zgmvg-zzctI",
"playing": false,
"selected": false,
"title": "Lil Uzi Vert - XO TOUR Llif3 (Produced By TM88)"
},
{ {
"duration": "00:12:53", "duration": "00:12:53",
"error": false, "error": false,
"filename": "test/gplv3.ogg", "filename": "test/gplv3.ogg",
"playing": false,
"selected": true, "selected": true,
"title": "gplv3.ogg" "title": "gplv3.ogg"
}, },
{
"duration": "00:04:49",
"error": false,
"filename": "https://youtu.be/xvZqHgFz51I",
"playing": false,
"selected": false,
"title": "Future - Mask Off"
},
{
"duration": "00:03:47",
"error": false,
"filename": "https://youtu.be/8j9zMok6two",
"playing": false,
"selected": false,
"title": "Miley Cyrus - Malibu (Official Video)"
},
{ {
"duration": "00:04:17", "duration": "00:04:17",
"error": false, "error": false,
"filename": "https://youtu.be/dPI-mRFEIH0", "filename": "https://youtu.be/dPI-mRFEIH0",
"playing": false,
"selected": false, "selected": false,
"title": "Katy Perry - Bon Appétit (Official) ft. Migos" "title": "Katy Perry - Bon Appétit (Official) ft. Migos"
}, },
@ -107,23 +45,13 @@
"duration": "00:04:06", "duration": "00:04:06",
"error": false, "error": false,
"filename": "https://youtu.be/aatr_2MstrI", "filename": "https://youtu.be/aatr_2MstrI",
"playing": false,
"selected": false, "selected": false,
"title": "Clean Bandit - Symphony feat. Zara Larsson [Official Video]" "title": "Clean Bandit - Symphony feat. Zara Larsson [Official Video]"
}, },
{
"duration": "00:34:38",
"error": false,
"filename": "https://www.tube8.com/teen/nicole-ray-and-james-deen/409802/",
"playing": false,
"selected": true,
"title": "Nicole Ray and James Deen"
},
{ {
"duration": "00:04:16", "duration": "00:04:16",
"error": false, "error": false,
"filename": "https://youtu.be/7F37r50VUTQ", "filename": "https://youtu.be/7F37r50VUTQ",
"playing": false,
"selected": true, "selected": true,
"title": "ZAYN, Taylor Swift - I Dont Wanna Live Forever (Fifty Shades Darker)" "title": "ZAYN, Taylor Swift - I Dont Wanna Live Forever (Fifty Shades Darker)"
}, },
@ -131,7 +59,6 @@
"duration": "00:04:57", "duration": "00:04:57",
"error": false, "error": false,
"filename": "https://youtu.be/qFLhGq0060w", "filename": "https://youtu.be/qFLhGq0060w",
"playing": false,
"selected": true, "selected": true,
"title": "The Weeknd - I Feel It Coming ft. Daft Punk" "title": "The Weeknd - I Feel It Coming ft. Daft Punk"
}, },
@ -139,7 +66,6 @@
"duration": "00:02:29", "duration": "00:02:29",
"error": false, "error": false,
"filename": "http://www.html5videoplayer.net/videos/toystory.mp4", "filename": "http://www.html5videoplayer.net/videos/toystory.mp4",
"playing": false,
"selected": false, "selected": false,
"title": "toystory.mp4" "title": "toystory.mp4"
}, },
@ -147,7 +73,6 @@
"duration": "00:05:13", "duration": "00:05:13",
"error": false, "error": false,
"filename": "https://youtu.be/6ImFf__U6io", "filename": "https://youtu.be/6ImFf__U6io",
"playing": false,
"selected": true, "selected": true,
"title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine" "title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine"
}, },
@ -155,7 +80,6 @@
"duration": "00:03:55", "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,
"selected": false, "selected": false,
"title": "David Banner - Play (Dirty version)" "title": "David Banner - Play (Dirty version)"
}, },
@ -163,31 +87,13 @@
"duration": "00:03:55", "duration": "00:03:55",
"error": false, "error": false,
"filename": "https://youtu.be/NGLxoKOvzu4", "filename": "https://youtu.be/NGLxoKOvzu4",
"playing": false,
"selected": false, "selected": false,
"title": "Jason Derulo - Swalla (feat. Nicki Minaj & Ty Dolla $ign) (Official Music Video)" "title": "Jason Derulo - Swalla (feat. Nicki Minaj & Ty Dolla $ign) (Official Music Video)"
}, },
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/Hm1YFszJWbQ",
"playing": false,
"selected": false,
"title": "Migos - Slippery feat. Gucci Mane [Official Video]"
},
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/SC4xMk98Pdc",
"playing": false,
"selected": false,
"title": "Post Malone - Congratulations ft. Quavo"
},
{ {
"duration": "00:03:51", "duration": "00:03:51",
"error": false, "error": false,
"filename": "https://youtu.be/nfs8NYg7yQM", "filename": "https://youtu.be/nfs8NYg7yQM",
"playing": false,
"selected": false, "selected": false,
"title": "Charlie Puth - Attention [Official Video]" "title": "Charlie Puth - Attention [Official Video]"
}, },
@ -195,39 +101,27 @@
"duration": "00:04:10", "duration": "00:04:10",
"error": false, "error": false,
"filename": "https://www.youtube.com/watch?v=sRIkXM8S1J8", "filename": "https://www.youtube.com/watch?v=sRIkXM8S1J8",
"playing": false,
"selected": true, "selected": true,
"title": "Best Goat Song Versions Compilation Ever! (HD)" "title": "Best Goat Song Versions Compilation Ever! (HD)"
}, },
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/Dst9gZkq1a8",
"playing": false,
"selected": false,
"title": "Travis Scott - goosebumps ft. Kendrick Lamar"
},
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/dMK_npDG12Q", "filename": "https://youtu.be/dMK_npDG12Q",
"playing": false,
"selected": false, "selected": false,
"title": "Lorde - Green Light" "title": "Lorde - Green Light"
}, },
{ {
"duration": "00:00:00", "duration": "00:03:32",
"error": false, "error": false,
"filename": "https://youtu.be/h--P8HzYZ74", "filename": "https://youtu.be/h--P8HzYZ74",
"playing": false,
"selected": true, "selected": true,
"title": "Zedd, Alessia Cara - Stay (Lyric Video)" "title": "Zedd, Alessia Cara - Stay (Lyric Video)"
}, },
{ {
"duration": "00:00:00", "duration": "00:02:45",
"error": false, "error": false,
"filename": "https://youtu.be/Mdh2p03cRfw", "filename": "https://youtu.be/Mdh2p03cRfw",
"playing": false,
"selected": false, "selected": false,
"title": "Sam Hunt - Body Like A Back Road (Audio)" "title": "Sam Hunt - Body Like A Back Road (Audio)"
}, },
@ -235,7 +129,6 @@
"duration": "00:03:40", "duration": "00:03:40",
"error": false, "error": false,
"filename": "https://youtu.be/Fq0xEpRDL9Q", "filename": "https://youtu.be/Fq0xEpRDL9Q",
"playing": false,
"selected": false, "selected": false,
"title": "Chris Brown - Privacy (Explicit Version)" "title": "Chris Brown - Privacy (Explicit Version)"
}, },
@ -243,87 +136,55 @@
"duration": "00:03:36", "duration": "00:03:36",
"error": false, "error": false,
"filename": "https://youtu.be/7wtfhZwyrcc", "filename": "https://youtu.be/7wtfhZwyrcc",
"playing": false,
"selected": false, "selected": false,
"title": "Imagine Dragons - Believer" "title": "Imagine Dragons - Believer"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/t_jHrUE5IOk", "filename": "https://youtu.be/A-Rn0iQEpc8",
"playing": false,
"selected": false, "selected": false,
"title": "Maluma - Felices los 4 (Official Video)" "title": "Can't Stop the SUSE - (Can't Stop the Feeling parody)"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/wzZWXrlDj-A", "filename": "https://youtu.be/SYRlTISvjww",
"playing": false,
"selected": false, "selected": false,
"title": "DNCE - Kissing Strangers ft. Nicki Minaj" "title": "Uptime Funk - (Uptown Funk parody)"
},
{
"duration": "00:03:18",
"error": false,
"filename": "https://youtu.be/AEB6ibtdPZc",
"playing": false,
"selected": false,
"title": "Paramore: Hard Times [OFFICIAL VIDEO]"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/vqW18C4plZ8", "filename": "https://youtu.be/VNkDJk5_9eU",
"playing": false,
"selected": false, "selected": false,
"title": "WizKid - Come Closer ft. Drake" "title": "What Does the Chameleon Say? (Ylvis - What Does the Fox Say parody)"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/A7xzXDStQnk", "filename": "https://youtu.be/M9bq_alk-sw",
"playing": false,
"selected": false, "selected": false,
"title": "Shawn Mendes - There's Nothing Holdin' Me Back (Lyric Video)" "title": "SUSE. Yes Please. (Maroon 5 - Sugar parody)"
},
{
"duration": "00:03:51",
"error": false,
"filename": "https://youtu.be/FG9M0aEpJGE",
"playing": false,
"selected": false,
"title": "G-Eazy & Kehlani - Good Life (from The Fate of the Furious: The Album) [MUSIC VIDEO]"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/vp8VZe5kqEM", "filename": "https://youtu.be/oHNKTlz1lps",
"playing": false, "selected": true,
"selected": false, "title": "Linus Said - Music Parody (Momma Said)"
"title": "Lady Gaga - The Cure (Audio)"
}, },
{ {
"duration": "00:00:00", "duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/eP4eqhWc7sI", "filename": "https://youtu.be/4VrhlyIgo3M",
"playing": false,
"selected": false, "selected": false,
"title": "Lana Del Rey - Lust For Life (Official Video) ft. The Weeknd" "title": "25 Years - SUSE Music Video (7 Years parody)"
}, },
{ {
"duration": "00:00:00", "duration": "00:03:52",
"error": false,
"filename": "https://youtu.be/5qJp6xlKEug",
"playing": false,
"selected": false,
"title": "Gorillaz - Saturnz Barz (Spirit House)"
},
{
"duration": "00:00:00",
"error": false, "error": false,
"filename": "https://youtu.be/9sg-A-eS6Ig", "filename": "https://youtu.be/9sg-A-eS6Ig",
"playing": false,
"selected": true, "selected": true,
"title": "Enrique Iglesias - SUBEME LA RADIO (Official Video) ft. Descemer Bueno, Zion & Lennox" "title": "Enrique Iglesias - SUBEME LA RADIO (Official Video) ft. Descemer Bueno, Zion & Lennox"
} }