From f8185d1b3116948859b28cdba7d6b6cc1c3241d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Tue, 30 Jan 2018 17:08:47 +0700 Subject: [PATCH] Make comp ask to dump when quit and dump less bullsh*t --- comp | 11 ++- locale/vi/LC_MESSAGES/comp.mo | Bin 1697 -> 1752 bytes locale/vi/LC_MESSAGES/comp.po | 12 ++- omp/ie.py | 1 + omp/omp.py | 11 ++- test/playlist.json | 171 ++++------------------------------ 6 files changed, 41 insertions(+), 165 deletions(-) diff --git a/comp b/comp index 4c6238a..5e2c4de 100755 --- a/comp +++ b/comp @@ -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() diff --git a/locale/vi/LC_MESSAGES/comp.mo b/locale/vi/LC_MESSAGES/comp.mo index b07171560f386c76ea3ee9a45b3e0dd42cd8f347..e0c11ba1ffdbaba20b3ddb02ae1b75e4149872ee 100644 GIT binary patch delta 586 zcmX}pze_?<6u|N8)92Ij^~2N*q^yRb28qUkhKM&vEfEyrAQTab7=_r9Z4tCxqAiRF zio!)&+v+c9Fo&Rjp|z#&v0Dev{XFm0d(OS@+HJe_k7(dR5yNDPd?Uxma~}f{vXqKo z7-cc_8^}l9GX(Jw2eE}Qd_ii~RmV(xq0NHh|J}$%DV#tTC$R_T zun!lpAG6qtIUK-UoTB*}%KsVxrDm~-GuS~7ZHlc>U#;>W8)(T^!D-O_YOinGY=P%^? zq+o)Sn~;!`MoDR0LJEh;I4MnW=>MQhH-;E(d1n#*?z^+r%KF6eV(W$KPP$Sm9F_JC l4wurotxP$uU#+uN&7ZQYY*A}_Uw_(hhqdKQF|Yl>s~=Z7Hwyp& delta 545 zcmX}pKP&@r6u|Lc@2)-6(H21vtpU+o@;gDL27`ZV2QhW&&_N>pym#;3oolD@k+RMdF+`4&&*TKT7vVsBVlTE) zu6HnlaYLzDba4cCunVi92N+|0gh_1TAYR}w-eXj$hI-*d9(+Y9^o9<8VGn*|AO2uJ z#!V8(Fo82zps8h)=T0o8vUrYj_=H>7!3|uZs=VhAZR)EQC(`LDPT^(fV`v+tpv6s6 zFoCkppnRDd?yrXXg>b)!GMNgF;xW=^5cHzxS0#&o>)_?CKX^G&3#$ diff --git a/locale/vi/LC_MESSAGES/comp.po b/locale/vi/LC_MESSAGES/comp.po index 9ab8bd5..5f3b978 100644 --- a/locale/vi/LC_MESSAGES/comp.po +++ b/locale/vi/LC_MESSAGES/comp.po @@ -1,6 +1,6 @@ -# SOME DESCRIPTIVE TITLE. -# Copyright (C) YEAR ORGANIZATION -# FIRST AUTHOR , YEAR. +# Vietnamese translation for Omp front-ends. +# Copyright (C) 2018 Nguyễn Gia Phong +# Nguyễn Gia Phong , 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 [{}]: " diff --git a/omp/ie.py b/omp/ie.py index 6775ffa..857a813 100644 --- a/omp/ie.py +++ b/omp/ie.py @@ -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: diff --git a/omp/omp.py b/omp/omp.py index 2f08c55..61c73d0 100644 --- a/omp/omp.py +++ b/omp/omp.py @@ -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): diff --git a/test/playlist.json b/test/playlist.json index 2dff02b..191edbf 100644 --- a/test/playlist.json +++ b/test/playlist.json @@ -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 - That’s 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 Don’t 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" }