Skip to content
Open

Content #1176

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
051f442
Semi-complete / semi-broken port of songlist display to new content api
ids1024 Feb 1, 2016
5483aea
Merge branch 'develop' into content
ids1024 Mar 12, 2016
55b7d78
Merge branch 'develop' into content
ids1024 Apr 10, 2016
4c584cd
Merge branch 'develop' into content
ids1024 Jun 16, 2016
6368aa7
Undo unneeded changes from merge
ids1024 Jun 16, 2016
c7ce0e0
Remove duplicate functions from merge
ids1024 Jun 16, 2016
7d52d5d
Do not call generate_playlist_display() in generate_songlist_display()
ids1024 Jun 21, 2016
d54ab33
Use content API for pl_search
ids1024 Jun 21, 2016
6ef95a6
Correct variable name
ids1024 Jun 21, 2016
3822377
Remove remaining references to g.result_count
ids1024 Jun 21, 2016
9a17320
Simplify nextprev()
ids1024 Jun 21, 2016
7b6b67e
Display load and fail messages with playlist search
ids1024 Jun 21, 2016
18cbb4e
Display normal message on success
ids1024 Jun 21, 2016
f343f23
Remove no longer used 'token' function
ids1024 Jun 21, 2016
e5e72c6
Do not check max_results in generate_songlist_display()
ids1024 Jun 21, 2016
e8ec4e8
Do not restart numbering at on on each page
ids1024 Jun 21, 2016
c5767f0
Remove dump command, which will not be needed with content API
ids1024 Jun 21, 2016
164084a
Do not import dump in download
ids1024 Jun 21, 2016
2036c45
Get play() sort of working
ids1024 Jun 21, 2016
0bc8785
Avoid crash after playing
ids1024 Jun 21, 2016
7db97d5
Fix prompt_for_exit()
ids1024 Jun 21, 2016
556b933
Rename generate_songlist_display to _generate_songlist_display
ids1024 Jun 21, 2016
a86a54c
Slight simplification to play_all()
ids1024 Jun 21, 2016
036dfd7
Create class for redundancy between SongList and PlistList
ids1024 Jun 21, 2016
8ff1e45
Implement __getitem__() for SearchList
ids1024 Jun 21, 2016
8738341
Use __getitem__ powered slicing in the play command
ids1024 Jun 21, 2016
f017db1
Make info work with content api
ids1024 Jun 21, 2016
9d7c353
Partially fix x command for content api
ids1024 Jun 21, 2016
5cd1553
Start updating download for content API
ids1024 Jun 21, 2016
b7f0adb
Remove g.last_search_query
ids1024 Jun 21, 2016
5fbf83b
Remove line setting g.browse_mode
ids1024 Jun 21, 2016
db72e94
Remove lines setting browse_mode before yt_pl
ids1024 Jun 21, 2016
ffab650
Remove last uses of g.browse_mode
ids1024 Jun 21, 2016
b64db3b
Correct variable name
ids1024 Jun 21, 2016
175873f
Implement __len__ in SearchList
ids1024 Jun 21, 2016
46aff9d
Use g.content instead of g.model in parse_multi
ids1024 Jun 21, 2016
c5c4b4d
Make yt_url work with content API
ids1024 Jun 21, 2016
9dd1bac
Remove unused import
ids1024 Jun 22, 2016
987b0b2
Use xprint in set_window_title
ids1024 Jun 22, 2016
f8e27e0
Move set_window_title to screen.py
ids1024 Jun 22, 2016
894783b
Use print instead of xprint for version info
ids1024 Jun 22, 2016
0f40782
Correct variable name
ids1024 Jun 22, 2016
62b34ce
Correct play_url
ids1024 Jun 22, 2016
7d90cf8
Remov documentation for dump command
ids1024 Jun 22, 2016
cf491f9
Restructure _playback_progress()
ids1024 Jun 22, 2016
1ad6324
Do not include max_results in getxy, but in LineContent
ids1024 Jun 22, 2016
7c0b64e
Simplify max_results calculation
ids1024 Jun 22, 2016
053dfb1
Merge branch 'develop' into content
ids1024 Jul 17, 2016
0efd4d8
Move g.current_page to g.content.current_page
ids1024 Jul 17, 2016
088818f
Use content api for logo
ids1024 Jul 18, 2016
47a9f1e
Merge branch 'develop' into content
ids1024 Aug 16, 2016
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
2 changes: 1 addition & 1 deletion mps_youtube/commands/album_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _do_query(url, query, err='query failed', report=False):

except (URLError, HTTPError) as e:
g.message = "%s: %s (%s)" % (err, e, url)
g.content = content.logo(c.r)
g.content = content.Logo(c.r)
return None if not report else (None, False)

return wdata if not report else (wdata, False)
Expand Down
17 changes: 6 additions & 11 deletions mps_youtube/commands/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from .. import g, c, screen, streams, content, config, util
from . import command, PL
from .search import yt_url, user_pls
from .songlist import dump, plist
from .songlist import plist


@command(r'(dv|da|d|dl|download)\s*(\d{1,4})')
Expand All @@ -20,25 +20,25 @@ def download(dltype, num):
# This function needs refactoring!
# pylint: disable=R0912
# pylint: disable=R0914
if g.browse_mode == "ytpl" and dltype in ("da", "dv"):
if isinstance(g.content, content.PlistList) and dltype in ("da", "dv"):
plid = g.ytpls[int(num) - 1]["link"]
down_plist(dltype, plid)
return

elif g.browse_mode == "ytpl":
elif isinstance(g.content, content.PlistList):
g.message = "Use da or dv to specify audio / video playlist download"
g.message = c.y + g.message + c.w
g.content = content.generate_songlist_display()
return

elif g.browse_mode != "normal":
elif not isinstance(g.content, content.PlistList):
g.message = "Download must refer to a specific video item"
g.message = c.y + g.message + c.w
g.content = content.generate_songlist_display()
return

screen.writestatus("Fetching video info...")
song = (g.model[int(num) - 1])
song = (g.content[int(num) - 1])
best = dltype.startswith("dv") or dltype.startswith("da")

if not best:
Expand Down Expand Up @@ -146,7 +146,6 @@ def handle_error(message):

try:
for song in downsongs:
g.result_count = len(g.model)
disp = content.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 @@ -184,7 +183,6 @@ def handle_error(message):
finally:
g.model.songs = temp[::]
g.message = msg
g.result_count = len(g.model)
g.content = content.generate_songlist_display()


Expand All @@ -193,7 +191,6 @@ def down_plist(dltype, parturl):
""" Download YouTube playlist. """

plist(parturl)
dump(False)
title = g.pafy_pls[parturl][0].title
subdir = util.mswinfn(title.replace("/", "-"))
down_many(dltype, "1-", subdir=subdir)
Expand All @@ -206,7 +203,7 @@ def down_plist(dltype, parturl):
def down_user_pls(dltype, user):
""" Download all user playlists. """
user_pls(user)
for i in g.ytpls:
for i in g.content:
down_plist(dltype, i.get('link'))

return
Expand Down Expand Up @@ -538,7 +535,6 @@ def mbsize(x):
@command(r'dlurl\s(.*[-_a-zA-Z0-9]{11}.*)')
def dl_url(url):
""" Open and prompt for download of youtube video url. """
g.browse_mode = "normal"
yt_url(url)

if len(g.model) == 1:
Expand All @@ -551,7 +547,6 @@ def dl_url(url):
@command(r'daurl\s(.*[-_a-zA-Z0-9]{11}.*)')
def da_url(url):
""" Open and prompt for download of youtube best audio from url. """
g.browse_mode = "normal"
yt_url(url)

if len(g.model) == 1:
Expand Down
37 changes: 17 additions & 20 deletions mps_youtube/commands/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from .. import g, c, __version__, content, screen, cache
from .. import streams, history, config, util
from ..helptext import get_help
from ..content import generate_songlist_display, logo
from . import command
from .songlist import paginatesongs

Expand Down Expand Up @@ -54,9 +53,9 @@ def quits(showlogo=True):

cache.save()

screen.clear()
msg = logo(c.r, version=__version__) if showlogo else ""
msg += util.F("exitmsg", 2)
g.content = content.Logo(c.r, version=__version__) if showlogo else ""
screen.update()
msg = util.F("exitmsg", 2)

if config.CHECKUPDATE.get and showlogo:

Expand Down Expand Up @@ -121,8 +120,8 @@ def fetch_comments(item):
@command(r'c\s?(\d{1,4})')
def comments(number):
""" Receive use request to view comments. """
if g.browse_mode == "normal":
item = g.model[int(number) - 1]
if isinstance(g.content, content.SongList):
item = g.content[int(number) - 1]
fetch_comments(item)

else:
Expand All @@ -133,13 +132,12 @@ def comments(number):
@command(r'x\s*(\d+)')
def clip_copy(num):
""" Copy item to clipboard. """
if g.browse_mode == "ytpl":

p = g.ytpls[int(num) - 1]
if isinstance(g.content, content.PlistList):
p = g.content[int(num) - 1]
link = "https://youtube.com/playlist?list=%s" % p['link']

elif g.browse_mode == "normal":
item = (g.model[int(num) - 1])
elif isinstance(g.content, content.SongList):
item = g.content[int(num) - 1]
link = "https://youtube.com/watch?v=%s" % item.ytid

else:
Expand All @@ -148,7 +146,6 @@ def clip_copy(num):
return

if has_pyperclip:

try:
pyperclip.copy(link)
g.message = c.y + link + c.w + " copied"
Expand All @@ -168,14 +165,14 @@ def clip_copy(num):
@command(r'i\s*(\d{1,4})')
def info(num):
""" Get video description. """
if g.browse_mode == "ytpl":
p = g.ytpls[int(num) - 1]
if isinstance(g.content, content.PlistList):
p = g.content[int(num) - 1]

# fetch the playlist item as it has more metadata
if p['link'] in g.pafy_pls:
ytpl = g.pafy_pls[p['link']][0]
else:
g.content = logo(col=c.g)
g.content = Logo(col=c.g)
g.message = "Fetching playlist info.."
screen.update()
util.dbg("%sFetching playlist using pafy%s", c.y, c.w)
Expand All @@ -198,11 +195,11 @@ def info(num):
out += ("\n\n%s[%sPress enter to go back%s]%s" % (c.y, c.w, c.y, c.w))
g.content = out

elif g.browse_mode == "normal":
g.content = logo(c.b)
elif isinstance(g.content, content.SongList):
item = g.content[int(num) - 1]
g.content = Logo(c.b)
screen.update()
screen.writestatus("Fetching video metadata..")
item = (g.model[int(num) - 1])
streams.get(item)
p = util.get_pafy(item)
pub = time.strptime(str(p.published), "%Y-%m-%d %H:%M:%S")
Expand Down Expand Up @@ -240,7 +237,7 @@ def view_history(duplicates=True):
g.message = message

except AttributeError:
g.content = logo(c.r)
g.content = Logo(c.r)
g.message = "History empty"


Expand All @@ -256,4 +253,4 @@ def clear_history():
g.userhist['history'].songs = []
history.save()
g.message = "History cleared"
g.content = logo()
g.content = Logo()
29 changes: 13 additions & 16 deletions mps_youtube/commands/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,15 @@ def play(pre, choice, post=""):
# pylint: disable=R0914
# too many local variables

if g.browse_mode == "ytpl":

if isinstance(g.content, content.PlistList):
if choice.isdigit():
return plist(g.ytpls[int(choice) - 1]['link'])
return plist(g.content[int(choice) - 1]['link'])
else:
g.message = "Invalid playlist selection: %s" % c.y + choice + c.w
g.content = content.generate_songlist_display()
return

if not g.model:
g.message = c.r + "There are no tracks to select" + c.w
g.content = g.content or content.generate_songlist_display()

else:
elif isinstance(g.content, content.SongList):
shuffle = "shuffle" in pre + post
repeat = "repeat" in pre + post
novid = "-a" in pre + post
Expand All @@ -72,36 +67,38 @@ def play(pre, choice, post=""):
override = "forcevid" if forcevid else override

selection = util.parse_multi(choice)
songlist = [g.model[x - 1] for x in selection]
songlist = [g.content[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

if len(g.model) > chosen + 1:
streams.preload(g.model[chosen + 1], override=override)
if len(g.content) > chosen + 1:
streams.preload(g.content[chosen + 1], override=override)

play_range(songlist, shuffle, repeat, override)
g.content = content.generate_songlist_display()

else:
g.message = c.r + "There are no tracks to select" + c.w
g.content = g.content or content.generate_songlist_display()


@command(r'(%s{0,3})(?:\*|all)\s*(%s{0,3})' %
(RS, RS))
def play_all(pre, choice, post=""):
""" Play all tracks in model (last displayed). shuffle/repeat if req'd."""
options = pre + choice + post
play(options, "1-" + str(len(g.model)))
play(options, "1-")


@command(r'playurl\s(.*[-_a-zA-Z0-9]{11}[^\s]*)(\s-(?:f|a|w))?')
def play_url(url, override):
""" Open and play a youtube video url. """
override = override if override else "_"
g.browse_mode = "normal"
yt_url(url, print_title=1)

if len(g.model) == 1:
if len(g.content) == 1:
play(override, "1", "_")

if g.command_line:
Expand All @@ -113,7 +110,7 @@ def browser_play(number):
"""Open a previously searched result in the browser."""
if (len(g.model) == 0):
g.message = c.r + "No previous search." + c.w
g.content = content.logo(c.r)
g.content = content.Logo(c.r)
return

try:
Expand Down
Loading