Play compiled playlist and skip songs in cache
konishon opened this issue · 5 comments
I would like to skip songs already present in the cache.
I have a different use case. I expect playx chill music
to play https://www.youtube.com/watch?v=wlsdMpnDBn8 but with audio full lyrics
always appended to the query. It pulls a specific song. When I was rather looking for a compiled playlist
:~/tmp/playx(develop)$ playx chill music
[cache]: Searching [chill music] in the cache at [/home/nishon/.playx/songs]
[youtube]: Searching youtube for :: chill music audio full lyrics
[cache]: Downloading Wale On Chill feat Jeremih Official Lyric Video .mp3
[utility]: Playing [Wale - On Chill (feat. Jeremih) [Official Lyric Video]]
Anyway I added a way to skip the keywords
parser.add_argument('--skip', help="If passed does not add keywords to YouTube search query",
action='store_true')
This worked for me. However, a new problem arose. Now, when queried playx chill music
I get the same playlist loaded from cache every time. When I would rather have something related played.
I have been working on it on my fork (konishon#1)
The basic gist of would be implementing a function def search_with_exclude(song, exclude_songs):
in songfinder.py
. Where song
is the user query and exclude_songs
is a list of song titles to skip
If you had any ideas on how I could go about and implement the feature(on my fork), that would make the process easier.
worked for me. However, a new problem arose. Now, when queried playx chill music I get the same playlist loaded from cache every time. When I would rather have something related played.
Regarding this, did you try --no-cache
option? so that when --skip
is used it will not append the keywords and also avoid the cache?
Also, if I am not wrong, it seems you'd want playx chill music
or similar actions to render new songs (or compiled playlist/video) whenever it is called, right? If that's so, then we have to dig a deeper on how playx
actually works:
- crawl youtube for search of keywords
- use the first link in the search list
- fetch the video link
- download the audio in parallel with playing
So, if we want to implement the behaviour you mentioned, then I think we have to modify the part with first link and come up with something iterative (or random index). That's the best guess I can bet. :)
I don't think that would work for me.
My understanding is you scrapped https://www.youtube.com/results?search_query=chill+playlist
and took the first item and played it and added everything else in a list as a related song.
It would play the same song everytime when just --no-cache
is used.
However, I was looking for it to able to play maybe an nth item on the list rather than the hardcoded first item
I don't think that would work for me.
My understanding is you scrappedhttps://www.youtube.com/results?search_query=chill+playlist
and took the first item and played it and added everything else in a list as a related song.It would play the same song everytime when just
--no-cache
is used.
However, I was looking for it to able to play maybe an nth item on the list rather than the hardcoded first item
Yes. Maybe trying with a random item on the list should do fine, but then that would add another complexity of checking (and re-checking) if it's a repeated item or not.
Another (possible workaround?) option is to use local playlist in the format .playx
and put in the links manually to the local playlist (say chill.playx) and play it using playx chill.playx
Yes. Maybe trying with a random item on the list should do fine, but then that would add another complexity of checking (and re-checking) if it's a repeated item or not.
It works for me! Here's my implementation. I think this issue can be closed now @NISH1001
Thank you.
def search_with_exclude(song, songs_to_exclude):
"""Search the song in youtube and remove songs passed in songs_to_exclude"""
videos = search_youtube(song, skip_kw=True)
string_list = []
for video in videos:
fixed_title = fix_title(video.title)
string_list.append(fixed_title)
if songs_to_exclude:
item_to_remove = get_closest_match_ignorecase(string_list, songs_to_exclude[0])
if item_to_remove:
index = string_list.index(item_to_remove)
del string_list[index]
del videos[index]
return random.choice(videos)