From 3a0e10de8f21198826796f3e1b39d9b284c5cba8 Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 25 Feb 2014 18:08:31 +0000 Subject: [PATCH 01/13] wait if an item that is busy preloading is played --- CHANGELOG | 5 +++++ mpsyt | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index 21014f33..aadad513 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,8 @@ + + - Wait for preloading thread if a selected item is busy preloading + +------------------------------------------------------------------------------- + Version 0.01.35 Feb 25 2014 diff --git a/mpsyt b/mpsyt index 6ebafe35..7b0acf51 100755 --- a/mpsyt +++ b/mpsyt @@ -333,6 +333,7 @@ class g(object): """ Class for holding globals that are needed throught the module. """ urlopen = None + preloading=[] expiry = 5 * 60 * 60 # 5 hours blank_text = "\n" * 200 helptext = [] @@ -1096,6 +1097,11 @@ def playsong(song, failcount=0, override=False): # pylint: disable=R0912 # too many branches + # don't interrupt preloading: + while song.ytid in g.preloading: + writestatus("fetching item..") + time.sleep(0.1) + video = Config.SHOW_VIDEO video = True if override in ("fullscreen", "window") else video video = False if override == "audio" else video @@ -1617,6 +1623,7 @@ def vp(): def preload(song, delay=2, override=False): """ Get streams (runs in separate thread). """ + g.preloading.append(song.ytid) time.sleep(delay) video = Config.SHOW_VIDEO video = True if override in ("fullscreen", "window") else video @@ -1627,7 +1634,10 @@ def preload(song, delay=2, override=False): get_size(song, is_video=video) except (ValueError, AttributeError, IOError): - return None # fail silently on preload + pass # fail silently on preload + + finally: + g.preloading.remove(song.ytid) def play_range(songlist, shuffle=False, repeat=False, override=False): From f7fb8fb3ff3181a3ede8baf41ed17358b6580b0d Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 25 Feb 2014 21:44:06 +0000 Subject: [PATCH 02/13] Added screenshots --- README | 31 ++++++++++++++++++++++++++++++- README.rst | 31 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/README b/README index 497a8d7e..6675e62e 100644 --- a/README +++ b/README @@ -14,13 +14,42 @@ Features - Download audio/video - Works with Python 2.7 and 3.x - Works with Windows, Linux and Mac OS X -- Requires mplayer +- Requires mplayer or mpv This project is based on `mps `_, which is a terminal based program to search, stream and download music. This implementation uses YouTube as a source of content and can play and download video as well as audio. The `pafy `_ library handles interfacing with YouTube. +Screenshots +----------- + +Search +~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png + +Playback +~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playback.png + +Playlists +~~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png + +Download +~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-download.png + + +Installation +------------ + +Using `pip `_:: + Installation ------------ diff --git a/README.rst b/README.rst index 497a8d7e..6675e62e 100644 --- a/README.rst +++ b/README.rst @@ -14,13 +14,42 @@ Features - Download audio/video - Works with Python 2.7 and 3.x - Works with Windows, Linux and Mac OS X -- Requires mplayer +- Requires mplayer or mpv This project is based on `mps `_, which is a terminal based program to search, stream and download music. This implementation uses YouTube as a source of content and can play and download video as well as audio. The `pafy `_ library handles interfacing with YouTube. +Screenshots +----------- + +Search +~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png + +Playback +~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playback.png + +Playlists +~~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png + +Download +~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-download.png + + +Installation +------------ + +Using `pip `_:: + Installation ------------ From 8cebeb185d443f99a13013b8f1c3b7790d07f3f3 Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 25 Feb 2014 21:47:39 +0000 Subject: [PATCH 03/13] corrected image url --- README | 13 ++++--------- README.rst | 13 ++++--------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/README b/README index 6675e62e..dbfb1faf 100644 --- a/README +++ b/README @@ -29,10 +29,10 @@ Search .. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png -Playback +Playback (video) ~~~~~~~~ -.. image:: http://np1.github.io/mpsyt-images/mpsyt-playback.png +.. image:: http://np1.github.io/mpsyt-images/mpsyt-vid-playback.png Playlists ~~~~~~~~~ @@ -50,12 +50,7 @@ Installation Using `pip `_:: -Installation ------------- - -Using `pip `_:: - - sudo pip install mps-youtube + [sudo] pip install mps-youtube Mac OS X installation notes ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -85,7 +80,7 @@ It is recommended you update to the latest version. Upgrade pip installation:: - sudo pip install mps-youtube --upgrade + [sudo] pip install mps-youtube --upgrade Usage ----- diff --git a/README.rst b/README.rst index 6675e62e..dbfb1faf 100644 --- a/README.rst +++ b/README.rst @@ -29,10 +29,10 @@ Search .. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png -Playback +Playback (video) ~~~~~~~~ -.. image:: http://np1.github.io/mpsyt-images/mpsyt-playback.png +.. image:: http://np1.github.io/mpsyt-images/mpsyt-vid-playback.png Playlists ~~~~~~~~~ @@ -50,12 +50,7 @@ Installation Using `pip `_:: -Installation ------------- - -Using `pip `_:: - - sudo pip install mps-youtube + [sudo] pip install mps-youtube Mac OS X installation notes ~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -85,7 +80,7 @@ It is recommended you update to the latest version. Upgrade pip installation:: - sudo pip install mps-youtube --upgrade + [sudo] pip install mps-youtube --upgrade Usage ----- From 7a12fd96bbe76006a20a92a102e6f08e81877350 Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 25 Feb 2014 21:55:06 +0000 Subject: [PATCH 04/13] minor corrections --- README | 5 +---- README.rst | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/README b/README index dbfb1faf..85f209f1 100644 --- a/README +++ b/README @@ -16,10 +16,7 @@ Features - Works with Windows, Linux and Mac OS X - Requires mplayer or mpv -This project is based on `mps `_, which is a terminal based program -to search, stream and download music. This implementation uses YouTube as a -source of content and can play and download video as well as audio. The `pafy `_ -library handles interfacing with YouTube. +This project is based on `mps `_, a terminal based program to search, stream and download music. This implementation uses YouTube as a source of content and can play and download video as well as audio. The `pafy `_ library handles interfacing with YouTube. Screenshots ----------- diff --git a/README.rst b/README.rst index dbfb1faf..85f209f1 100644 --- a/README.rst +++ b/README.rst @@ -16,10 +16,7 @@ Features - Works with Windows, Linux and Mac OS X - Requires mplayer or mpv -This project is based on `mps `_, which is a terminal based program -to search, stream and download music. This implementation uses YouTube as a -source of content and can play and download video as well as audio. The `pafy `_ -library handles interfacing with YouTube. +This project is based on `mps `_, a terminal based program to search, stream and download music. This implementation uses YouTube as a source of content and can play and download video as well as audio. The `pafy `_ library handles interfacing with YouTube. Screenshots ----------- From eb746f9fb51656b5efc9df5cebda115805a265a9 Mon Sep 17 00:00:00 2001 From: darren Date: Tue, 25 Feb 2014 21:59:15 +0000 Subject: [PATCH 05/13] Repositioned images --- README | 11 ++++++----- README.rst | 11 ++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README b/README index 85f209f1..bb7f1a6b 100644 --- a/README +++ b/README @@ -26,16 +26,17 @@ Search .. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png +Local Playlists +~~~~~~~~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png + + Playback (video) ~~~~~~~~ .. image:: http://np1.github.io/mpsyt-images/mpsyt-vid-playback.png -Playlists -~~~~~~~~~ - -.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png - Download ~~~~~~~~ diff --git a/README.rst b/README.rst index 85f209f1..bb7f1a6b 100644 --- a/README.rst +++ b/README.rst @@ -26,16 +26,17 @@ Search .. image:: http://np1.github.io/mpsyt-images/mpsyt-search.png +Local Playlists +~~~~~~~~~~~~~~~ + +.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png + + Playback (video) ~~~~~~~~ .. image:: http://np1.github.io/mpsyt-images/mpsyt-vid-playback.png -Playlists -~~~~~~~~~ - -.. image:: http://np1.github.io/mpsyt-images/mpsyt-playlists.png - Download ~~~~~~~~ From 7e6ae2ffbd635f290b078d993b9a8fca9f48d95c Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 01:08:27 +0000 Subject: [PATCH 06/13] Recognise webm video-only streams, offer mux --- mpsyt | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/mpsyt b/mpsyt index 7b0acf51..3c84aef8 100755 --- a/mpsyt +++ b/mpsyt @@ -757,7 +757,7 @@ def init_text(): 'no pl match for rename_': (c.r, c.w), 'invalid range': "*Invalid item / range entered!*", 'invalid range_': (c.r, c.w), - '-audio': "*Warning* - the filetype you selected (m4v) has no audio!", + '-audio': "*Warning* - the video file you selected has no audio!", '-audio_': (c.y, c.w), # Info messages @@ -1803,10 +1803,10 @@ def menu_prompt(model, prompt=" > ", rows=None, header=None, theading=None, force) elif not choice.strip(): - return False, False + return False, False, False else: # unrecognised input - return False, "abort" + return False, "abort", False def prompt_dl(song): @@ -1818,12 +1818,12 @@ def prompt_dl(song): model = [x['url'] for x in dl_data] ed = enumerate(dl_data) - model = {str(n + 1): (x['url'], x['ext']) for n, x in ed} - url, ext = menu_prompt(model, "Download number: ", *dl_text) + model = {str(n + 1): (x['url'], x['ext'], x['mediatype']) for n, x in ed} + url, ext, mediatype = menu_prompt(model, "Download number: ", *dl_text) url2 = ext2 = None muxapp = has_exefile("avconv") or has_exefile("ffmpeg") - if ext == "m4v" and muxapp: + if mediatype == "video" and muxapp: dl_data, p = get_dl_data(song, mediatype="audio") dl_text = gen_dl_text(dl_data, song, p) au_choices = "1" if len(dl_data) == 1 else "1-%s" % len(dl_data) @@ -1832,9 +1832,9 @@ def prompt_dl(song): aext = ("ogg", "m4a") model = [x['url'] for x in dl_data if x['ext'] in aext] ed = enumerate(dl_data) - model = {str(n + 1): (x['url'], x['ext']) for n, x in ed} + model = {str(n + 1): (x['url'], x['ext'], "_") for n, x in ed} prompt = "Audio stream: " - url2, ext2 = menu_prompt(model, prompt, *dl_text) + url2, ext2, _ = menu_prompt(model, prompt, *dl_text) return url, ext, url2, ext2 @@ -1944,7 +1944,11 @@ def download(dltype, num): mux_cmd += " -map 1:a:0 -threads 2 BOSH" mux_cmd = mux_cmd.split() mux_cmd[2], mux_cmd[6] = args[1], args_au[1] - mux_cmd[0], mux_cmd[15] = muxapp, args[1][:-3] + "mp4" + # replace file extension + dotpos, fname = args[1].rfind("."), args[1] + nom, ext = fname[:dotpos], fname[dotpos + 1:] + ext = "mp4" if ext == "m4v" else ext + mux_cmd[0], mux_cmd[15] = muxapp, nom + "." + ext try: subprocess.call(mux_cmd) From 2e1aad4161e0e6c0c7aed634d17c73589918dcbe Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 01:28:43 +0000 Subject: [PATCH 07/13] Revert "Recognise webm video-only streams, offer mux" This reverts commit 7e6ae2ffbd635f290b078d993b9a8fca9f48d95c. --- mpsyt | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/mpsyt b/mpsyt index 3c84aef8..7b0acf51 100755 --- a/mpsyt +++ b/mpsyt @@ -757,7 +757,7 @@ def init_text(): 'no pl match for rename_': (c.r, c.w), 'invalid range': "*Invalid item / range entered!*", 'invalid range_': (c.r, c.w), - '-audio': "*Warning* - the video file you selected has no audio!", + '-audio': "*Warning* - the filetype you selected (m4v) has no audio!", '-audio_': (c.y, c.w), # Info messages @@ -1803,10 +1803,10 @@ def menu_prompt(model, prompt=" > ", rows=None, header=None, theading=None, force) elif not choice.strip(): - return False, False, False + return False, False else: # unrecognised input - return False, "abort", False + return False, "abort" def prompt_dl(song): @@ -1818,12 +1818,12 @@ def prompt_dl(song): model = [x['url'] for x in dl_data] ed = enumerate(dl_data) - model = {str(n + 1): (x['url'], x['ext'], x['mediatype']) for n, x in ed} - url, ext, mediatype = menu_prompt(model, "Download number: ", *dl_text) + model = {str(n + 1): (x['url'], x['ext']) for n, x in ed} + url, ext = menu_prompt(model, "Download number: ", *dl_text) url2 = ext2 = None muxapp = has_exefile("avconv") or has_exefile("ffmpeg") - if mediatype == "video" and muxapp: + if ext == "m4v" and muxapp: dl_data, p = get_dl_data(song, mediatype="audio") dl_text = gen_dl_text(dl_data, song, p) au_choices = "1" if len(dl_data) == 1 else "1-%s" % len(dl_data) @@ -1832,9 +1832,9 @@ def prompt_dl(song): aext = ("ogg", "m4a") model = [x['url'] for x in dl_data if x['ext'] in aext] ed = enumerate(dl_data) - model = {str(n + 1): (x['url'], x['ext'], "_") for n, x in ed} + model = {str(n + 1): (x['url'], x['ext']) for n, x in ed} prompt = "Audio stream: " - url2, ext2, _ = menu_prompt(model, prompt, *dl_text) + url2, ext2 = menu_prompt(model, prompt, *dl_text) return url, ext, url2, ext2 @@ -1944,11 +1944,7 @@ def download(dltype, num): mux_cmd += " -map 1:a:0 -threads 2 BOSH" mux_cmd = mux_cmd.split() mux_cmd[2], mux_cmd[6] = args[1], args_au[1] - # replace file extension - dotpos, fname = args[1].rfind("."), args[1] - nom, ext = fname[:dotpos], fname[dotpos + 1:] - ext = "mp4" if ext == "m4v" else ext - mux_cmd[0], mux_cmd[15] = muxapp, nom + "." + ext + mux_cmd[0], mux_cmd[15] = muxapp, args[1][:-3] + "mp4" try: subprocess.call(mux_cmd) From acb3e97967d0bd5e218bef5e0e9a6b56cb076e12 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 13:25:50 +0000 Subject: [PATCH 08/13] Carry override preference for failed playback --- mpsyt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mpsyt b/mpsyt index 7b0acf51..d911509c 100755 --- a/mpsyt +++ b/mpsyt @@ -1184,7 +1184,7 @@ def playsong(song, failcount=0, override=False): logging.warn("stream failed to open") writestatus("trying again (attempt %s)" % (2 + failcount)) failcount += 1 - playsong(song, failcount=failcount) + playsong(song, failcount=failcount, override=override) if not failed: save_to_file() From 8e41455b56d00f7d6495054d331ed7c28f6f69d6 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 16:40:13 +0000 Subject: [PATCH 09/13] updated comment --- mpsyt | 1 + 1 file changed, 1 insertion(+) diff --git a/mpsyt b/mpsyt index d911509c..4e183563 100755 --- a/mpsyt +++ b/mpsyt @@ -1575,6 +1575,7 @@ def play(pre, choice, post=""): songlist = [g.model.songs[x - 1] for x in selection] # cache next result of displayed items + # when selecting a single item if len(songlist) == 1: chosen = selection[0] - 1 From a4c353c62ad3ee3032d4eb05b8fdd551ec71e7b0 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 21:09:20 +0000 Subject: [PATCH 10/13] Changed some debugging messages --- mpsyt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mpsyt b/mpsyt index 4e183563..80443140 100755 --- a/mpsyt +++ b/mpsyt @@ -193,8 +193,8 @@ def populate_video(video, callback=None): callback("Fetching video...") try: + dbg(" - pafy fetch for %s", video.title) g.pafs[video.ytid] = pafy.new(video.ytid, callback=callback) - dbg("pafy fetch for %s", video.title) p = g.pafs[video.ytid] except (ValueError, IndexError): @@ -796,7 +796,7 @@ def save_to_file(): f = open(g.PLFILE, "wb") pickle.dump(g.userpl, f, protocol=2) - dbg("Playlist saved") + dbg("Playlist saved\n---") def open_from_file(): @@ -1177,12 +1177,12 @@ def playsong(song, failcount=0, override=False): return fin = time.time() - failed = fin - now < 1 and song.length > 10 + failed = fin - now < 1 and song.length > 1 if failed and failcount < g.max_retries: reset_video(song) logging.warn("stream failed to open") - writestatus("trying again (attempt %s)" % (2 + failcount)) + dbg("trying again (attempt %s)" % (2 + failcount)) failcount += 1 playsong(song, failcount=failcount, override=override) From bbf06f2ab61d494e9db5bcf73a49f8e9443c6ee8 Mon Sep 17 00:00:00 2001 From: darren Date: Wed, 26 Feb 2014 22:45:06 +0000 Subject: [PATCH 11/13] updated changes --- CHANGELOG | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG b/CHANGELOG index aadad513..9b10d2c7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ +Version 0.01.36 - dev, not yet released +DATE TBA - - Wait for preloading thread if a selected item is busy preloading + - Wait for preloading item if it is selected while preloading + - Fix bug where -a audio override is sometimes ignored ------------------------------------------------------------------------------- From 1ae97510b5b19ddc7fd903aad1231c39fb5f2418 Mon Sep 17 00:00:00 2001 From: darren Date: Thu, 27 Feb 2014 13:06:13 +0000 Subject: [PATCH 12/13] Documented changes --- CHANGELOG | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9b10d2c7..ee4ad5a7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,5 @@ -Version 0.01.36 - dev, not yet released -DATE TBA +Version 0.01.36 +Feb 27 2014 - Wait for preloading item if it is selected while preloading - Fix bug where -a audio override is sometimes ignored From 8964ada490108100b8f4ac5e4c183601c43649f4 Mon Sep 17 00:00:00 2001 From: darren Date: Thu, 27 Feb 2014 13:26:53 +0000 Subject: [PATCH 13/13] Version 0.01.36 --- VERSION | 2 +- mpsyt | 2 +- setup.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/VERSION b/VERSION index 889f8954..10166b4d 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ # This file is used by clients to check for updates -version 0.01.35 +version 0.01.36 diff --git a/mpsyt b/mpsyt index 80443140..eb6ac261 100755 --- a/mpsyt +++ b/mpsyt @@ -24,7 +24,7 @@ along with this program. If not, see . from __future__ import print_function -__version__ = "0.01.35" +__version__ = "0.01.36" __author__ = "nagev" __license__ = "GPLv3" diff --git a/setup.py b/setup.py index 903c4a2b..e7389b95 100755 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name="mps-youtube", - version="0.01.35", + version="0.01.36", description="Terminal based YouTube jukebox with playlist management", keywords=["video", "music", "audio", "youtube", "stream", "download"], author="nagev",