Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
np1 committed Feb 27, 2014
2 parents a4f7da1 + 8964ada commit 04e23f6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
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

-------------------------------------------------------------------------------

Version 0.01.35
Feb 25 2014

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file is used by clients to check for updates

version 0.01.35
version 0.01.36

25 changes: 18 additions & 7 deletions mpsyt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.

from __future__ import print_function

__version__ = "0.01.35"
__version__ = "0.01.36"
__author__ = "nagev"
__license__ = "GPLv3"

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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 = []
Expand Down Expand Up @@ -795,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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1171,14 +1177,14 @@ 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)
playsong(song, failcount=failcount, override=override)

if not failed:
save_to_file()
Expand Down Expand Up @@ -1569,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

Expand Down Expand Up @@ -1617,6 +1624,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
Expand All @@ -1627,7 +1635,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):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 04e23f6

Please sign in to comment.