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.
"""
if self.reading: return
curses.update_lines_cols()
y %= curses.LINES
x %= curses.COLS
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')
with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp:
c = comp.scr.get_wch()
while c != 'q':
while True:
c = comp.scr.get_wch()
comp.print_msg('')
# mpv keybindings
if c == curses.KEY_LEFT:
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)
elif c == curses.KEY_BACKSPACE:
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', ' '):
comp.cycle('pause')
elif c == '.':
@ -543,4 +549,3 @@ with Comp(entries, json_file, mode, mpv_args, ytdlf) as comp:
comp.mp.command(*comp.read_input(':').split())
except:
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.
# Copyright (C) YEAR ORGANIZATION
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
# Vietnamese translation for Omp front-ends.
# Copyright (C) 2018 Nguyễn Gia Phong
# Nguyễn Gia Phong <vn.mcsinyx@gmail.com>, 2018
#
msgid ""
msgstr ""
@ -50,6 +50,12 @@ msgstr "Tiêu đề"
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."
msgid "Save playlist? [Y/n]"
msgstr "Lưu danh sách phát? [C/k]"
msgid "Nn"
msgstr "Kk"
msgid "Save playlist to [{}]: "
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',
'error': False, 'playing': False, 'selected': False}
JSON_KEYS = 'filename', 'title', 'duration', 'error', 'selected'
class YoutubeDLLogger:

View File

@ -31,7 +31,7 @@ from youtube_dl import YoutubeDL
from pkg_resources import resource_filename
from mpv import MPV, MpvFormat
from .ie import extract_info
from .ie import JSON_KEYS, extract_info
# Init gettext
bindtextdomain('omp', resource_filename('omp', 'locale'))
@ -171,19 +171,22 @@ class Omp(object):
self.update_status(_("Pattern not found"), curses.color_pair(1))
def dump_json(self):
"""Read user input needed to save the playlist."""
s = self.read_input(
_("Save playlist to [{}]: ").format(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:
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:
errmsg = _("'{}': Can't open file for writing").format(
self.json_file)
self.print_msg(errmsg, error=True)
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))
def __exit__(self, exc_type, exc_value, traceback):

View File

@ -3,7 +3,6 @@
"duration": "00:05:21",
"error": false,
"filename": "https://youtu.be/weeI1G46q0o",
"playing": false,
"selected": true,
"title": "DJ Khaled - I'm the One ft. Justin Bieber, Quavo, Chance the Rapper, Lil Wayne"
},
@ -11,47 +10,13 @@
"duration": "00:04:23",
"error": false,
"filename": "https://youtu.be/JGwWNGJdvx8",
"playing": false,
"selected": true,
"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",
"error": false,
"filename": "https://youtu.be/72UO0v5ESUo",
"playing": false,
"selected": true,
"title": "Luis Fonsi, Daddy Yankee - Despacito (Audio) ft. Justin Bieber"
},
@ -59,47 +24,20 @@
"duration": "00:03:41",
"error": false,
"filename": "https://youtu.be/D5drYkLiLI8",
"playing": false,
"selected": false,
"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",
"error": false,
"filename": "test/gplv3.ogg",
"playing": false,
"selected": true,
"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",
"error": false,
"filename": "https://youtu.be/dPI-mRFEIH0",
"playing": false,
"selected": false,
"title": "Katy Perry - Bon Appétit (Official) ft. Migos"
},
@ -107,23 +45,13 @@
"duration": "00:04:06",
"error": false,
"filename": "https://youtu.be/aatr_2MstrI",
"playing": false,
"selected": false,
"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",
"error": false,
"filename": "https://youtu.be/7F37r50VUTQ",
"playing": false,
"selected": true,
"title": "ZAYN, Taylor Swift - I Dont Wanna Live Forever (Fifty Shades Darker)"
},
@ -131,7 +59,6 @@
"duration": "00:04:57",
"error": false,
"filename": "https://youtu.be/qFLhGq0060w",
"playing": false,
"selected": true,
"title": "The Weeknd - I Feel It Coming ft. Daft Punk"
},
@ -139,7 +66,6 @@
"duration": "00:02:29",
"error": false,
"filename": "http://www.html5videoplayer.net/videos/toystory.mp4",
"playing": false,
"selected": false,
"title": "toystory.mp4"
},
@ -147,7 +73,6 @@
"duration": "00:05:13",
"error": false,
"filename": "https://youtu.be/6ImFf__U6io",
"playing": false,
"selected": true,
"title": "Birdman - Dark Shades (Explicit) ft. Lil Wayne, Mack Maine"
},
@ -155,7 +80,6 @@
"duration": "00:03:55",
"error": false,
"filename": "https://www.youtube.com/watch?v=3M3xfu0m5o4",
"playing": false,
"selected": false,
"title": "David Banner - Play (Dirty version)"
},
@ -163,31 +87,13 @@
"duration": "00:03:55",
"error": false,
"filename": "https://youtu.be/NGLxoKOvzu4",
"playing": false,
"selected": false,
"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",
"error": false,
"filename": "https://youtu.be/nfs8NYg7yQM",
"playing": false,
"selected": false,
"title": "Charlie Puth - Attention [Official Video]"
},
@ -195,39 +101,27 @@
"duration": "00:04:10",
"error": false,
"filename": "https://www.youtube.com/watch?v=sRIkXM8S1J8",
"playing": false,
"selected": true,
"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",
"error": false,
"filename": "https://youtu.be/dMK_npDG12Q",
"playing": false,
"selected": false,
"title": "Lorde - Green Light"
},
{
"duration": "00:00:00",
"duration": "00:03:32",
"error": false,
"filename": "https://youtu.be/h--P8HzYZ74",
"playing": false,
"selected": true,
"title": "Zedd, Alessia Cara - Stay (Lyric Video)"
},
{
"duration": "00:00:00",
"duration": "00:02:45",
"error": false,
"filename": "https://youtu.be/Mdh2p03cRfw",
"playing": false,
"selected": false,
"title": "Sam Hunt - Body Like A Back Road (Audio)"
},
@ -235,7 +129,6 @@
"duration": "00:03:40",
"error": false,
"filename": "https://youtu.be/Fq0xEpRDL9Q",
"playing": false,
"selected": false,
"title": "Chris Brown - Privacy (Explicit Version)"
},
@ -243,87 +136,55 @@
"duration": "00:03:36",
"error": false,
"filename": "https://youtu.be/7wtfhZwyrcc",
"playing": false,
"selected": false,
"title": "Imagine Dragons - Believer"
},
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/t_jHrUE5IOk",
"playing": false,
"filename": "https://youtu.be/A-Rn0iQEpc8",
"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",
"error": false,
"filename": "https://youtu.be/wzZWXrlDj-A",
"playing": false,
"filename": "https://youtu.be/SYRlTISvjww",
"selected": false,
"title": "DNCE - Kissing Strangers ft. Nicki Minaj"
},
{
"duration": "00:03:18",
"error": false,
"filename": "https://youtu.be/AEB6ibtdPZc",
"playing": false,
"selected": false,
"title": "Paramore: Hard Times [OFFICIAL VIDEO]"
"title": "Uptime Funk - (Uptown Funk parody)"
},
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/vqW18C4plZ8",
"playing": false,
"filename": "https://youtu.be/VNkDJk5_9eU",
"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",
"error": false,
"filename": "https://youtu.be/A7xzXDStQnk",
"playing": false,
"filename": "https://youtu.be/M9bq_alk-sw",
"selected": false,
"title": "Shawn Mendes - There's Nothing Holdin' Me Back (Lyric Video)"
},
{
"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]"
"title": "SUSE. Yes Please. (Maroon 5 - Sugar parody)"
},
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/vp8VZe5kqEM",
"playing": false,
"selected": false,
"title": "Lady Gaga - The Cure (Audio)"
"filename": "https://youtu.be/oHNKTlz1lps",
"selected": true,
"title": "Linus Said - Music Parody (Momma Said)"
},
{
"duration": "00:00:00",
"error": false,
"filename": "https://youtu.be/eP4eqhWc7sI",
"playing": false,
"filename": "https://youtu.be/4VrhlyIgo3M",
"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",
"error": false,
"filename": "https://youtu.be/5qJp6xlKEug",
"playing": false,
"selected": false,
"title": "Gorillaz - Saturnz Barz (Spirit House)"
},
{
"duration": "00:00:00",
"duration": "00:03:52",
"error": false,
"filename": "https://youtu.be/9sg-A-eS6Ig",
"playing": false,
"selected": true,
"title": "Enrique Iglesias - SUBEME LA RADIO (Official Video) ft. Descemer Bueno, Zion & Lennox"
}