Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download playlists #325

Merged
merged 2 commits into from
Jul 10, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions mps_youtube/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,8 @@ def generate_songlist_display(song=False, zeromsg=None, frmat="search"):
if g.browse_mode == "ytpl":
return generate_playlist_display()

max_results = screen.getxy().max_results

songs = g.model.songs or []

if not songs:
Expand Down Expand Up @@ -1230,7 +1232,7 @@ def generate_songlist_display(song=False, zeromsg=None, frmat="search"):
hrow = c.ul + fmt % titles + c.w
out = "\n" + hrow + "\n"

for n, x in enumerate(songs):
for n, x in enumerate(songs[:max_results]):
col = (c.r if n % 2 == 0 else c.p) if not song else c.b
details = {'title': x.title, "length": fmt_time(x.length)}
details = g.meta[x.ytid].copy() if have_meta else details
Expand Down Expand Up @@ -2625,6 +2627,7 @@ def handle_error(message):

try:
for song in downsongs:
g.result_count = len(g.model.songs)
disp = generate_songlist_display()
title = "Download Queue (%s):%s\n\n" % (av, c.w)
disp = re.sub(r"(Num\s*?Title.*?\n)", title, disp)
Expand Down Expand Up @@ -2662,6 +2665,7 @@ def handle_error(message):
finally:
g.model.songs = temp[::]
g.message = msg
g.result_count = len(g.model.songs)
g.content = generate_songlist_display()


Expand All @@ -2672,6 +2676,9 @@ def down_plist(dltype, parturl):
title = g.pafy_pls[parturl]['title']
subdir = mswinfn(title.replace("/", "-"))
down_many(dltype, "1-", subdir=subdir)
msg = g.message
plist(parturl, page=0, splash=True)
g.message = msg


def down_user_pls(dltype, user):
Expand Down Expand Up @@ -3525,8 +3532,6 @@ def plist(parturl, page=0, splash=True, dumps=False):
g.pafy_pls[parturl] = yt_playlist
ytpl_items = yt_playlist['items']
ytpl_title = yt_playlist['title']
g.result_count = len(ytpl_items)
g.more_pages = max_results < len(ytpl_items)

songs = []

Expand All @@ -3545,7 +3550,9 @@ def plist(parturl, page=0, splash=True, dumps=False):
g.browse_mode = "normal"
g.ytpl = dict(name=ytpl_title, items=songs)
g.current_page = 0
g.model.songs = songs[:max_results]
g.result_count = len(g.ytpl['items'])
g.more_pages = max_results < len(g.ytpl['items'])
g.model.songs = songs[:max_results] if not dumps else songs[::]
# preload first result url
kwa = {"song": songs[0], "delay": 0}
t = threading.Thread(target=preload, kwargs=kwa)
Expand Down