mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-02 19:15:26 +00:00
It won't just blindly grab the top song off youtube results, will check if the song name is in the title. (typo in the README)
This commit is contained in:
parent
773e00240f
commit
f840b4bf8e
|
@ -15,7 +15,7 @@ First, actually install python and pip:
|
||||||
|
|
||||||
Then install `requirements.txt` from the repository:
|
Then install `requirements.txt` from the repository:
|
||||||
```bash
|
```bash
|
||||||
$ python install -r requirements.txt
|
$ pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
There are some more external command-line programs that are essential to movies, tv-shows, and streaming:
|
There are some more external command-line programs that are essential to movies, tv-shows, and streaming:
|
||||||
|
|
18
irs.py
18
irs.py
|
@ -57,12 +57,24 @@ def embed_mp3(art_location, song_path):
|
||||||
)
|
)
|
||||||
music.save()
|
music.save()
|
||||||
|
|
||||||
def find_mp3(song, author):
|
def find_mp3(song, author): #
|
||||||
print ("'%s' by '%s'\n" % (song, author))
|
print ("\n'%s' by '%s'" % (song, author))
|
||||||
query_string = urllib.parse.urlencode({"search_query" : ("%s %s lyrics" % (song, author))})
|
query_string = urllib.parse.urlencode({"search_query" : ("%s %s lyrics" % (song, author))})
|
||||||
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
|
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
|
||||||
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
|
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
|
||||||
audio_url = ("http://www.youtube.com/watch?v=" + search_results[0])
|
in_song = False
|
||||||
|
i = -1
|
||||||
|
given_up_score = 0
|
||||||
|
while in_song == False:
|
||||||
|
if given_up_score >= 10:
|
||||||
|
in_song = True
|
||||||
|
i += 1
|
||||||
|
audio_url = ("http://www.youtube.com/watch?v=" + search_results[i])
|
||||||
|
title = (BeautifulSoup(urlopen(audio_url), 'html.parser')).title.string.lower()
|
||||||
|
if song.lower() in title:
|
||||||
|
in_song = True
|
||||||
|
else:
|
||||||
|
given_up_score += 1
|
||||||
return audio_url
|
return audio_url
|
||||||
|
|
||||||
def rip_mp3(song, author, album, tracknum):
|
def rip_mp3(song, author, album, tracknum):
|
||||||
|
|
Loading…
Reference in a new issue