Added status update and minor usability features

This commit is contained in:
Kepoor Hampond 2016-09-16 10:55:44 -07:00
parent b386df5368
commit c0330ce3f4
2 changed files with 77 additions and 63 deletions

View file

@ -2,6 +2,8 @@
Downloads or streams media from the name of the song / album / movie / tv-show that you requested.
# CURRENTLY BEING REMADE BECAUSE kat.cr WAS TAKEN DOWN.
### Dependencies
First, actually install python and pip:

36
irs.py
View file

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os, sys, time, re, select, requests, subprocess
import os, sys, time, re, select, requests
import urllib.request, urllib.parse
from termcolor import colored
from urllib.request import Request, urlopen
@ -62,12 +62,13 @@ def embed_mp3(art_location, song_path):
def find_mp3(song, author, soundtrack=False):
try:
special_chars = "\ / : * ? \" < > | - ( )".split(" ")
operator = 'by'
searching = "%s %s lyrics" % (song, author)
if soundtrack == True:
operator = "from"
searching = "%s soundtrack %s" % (author, song)
print ("'%s' %s '%s'\n" % (song, operator, author))
print ("%s %s %s\n" % (song, operator, author))
query_string = urllib.parse.urlencode({"search_query" : (searching)})
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())
@ -80,9 +81,13 @@ def find_mp3(song, author, soundtrack=False):
i += 1
audio_url = ("http://www.youtube.com/watch?v=" + search_results[i])
title = (BeautifulSoup(urlopen(audio_url), 'html.parser')).title.string.lower()
for char in special_chars:
title = title.replace(char, "")
song_title = (song.lower()).split("/")
for song in song_title:
if song in title:
for char in special_chars:
song = song.replace(char, "")
if song in title and "full album" not in title:
in_song = True
if in_song == False:
given_up_score += 1
@ -92,20 +97,23 @@ def find_mp3(song, author, soundtrack=False):
def rip_mp3(song, author, album, tracknum, soundtrack=False):
audio_url = find_mp3(song, author, soundtrack=soundtrack)
song = song.replace("/", "\\")
special_chars = "\ / : * ? \" < > | ".split(" ")
filename = song
for char in special_chars:
filename = filename.replace(char, "")
command = 'youtube-dl --metadata-from-title "%(title)s" --extract-audio \
--audio-format mp3 --add-metadata ' + audio_url
os.system(command)
for filename in os.listdir("."):
if str(audio_url).strip("http://www.youtube.com/watch?v=") in filename:
os.rename(filename, song + ".mp3") # &PATH;
for file in os.listdir("."):
if str(audio_url).strip("http://www.youtube.com/watch?v=") in file:
os.rename(file, filename + ".mp3") # &PATH;
try:
googled = search_google(song, author, "")
mp3file = MP3(song + ".mp3", ID3=EasyID3)
mp3file = MP3(filename + ".mp3", ID3=EasyID3)
print ("\n%s Metadata parsing:" % output("s"))
try:
mp3file['title'] = song.replace("\\", "/")
mp3file['title'] = song
except Exception:
mp3file['title'] = ""
mp3file.save()
@ -231,11 +239,11 @@ def get_album(album_name, artist, what_to_do, search, tried=False):
print ("%s Trying to find album ..." % output("s"))
get_album(album_name, artist, what_to_do, "", True)
else:
print ("%s Could not find album '%s'" % (output("e"), album_))
print ("%s Could not find album %s" % (output("e"), album_))
exit(0)
else:
print ("%s There was an error with getting the contents \
of the album '%s':\n%s" % (output("e"), album_name, e) )
of the album %s:\n%s" % (output("e"), album_name, e) )
def get_torrent_url(args, category):
@ -308,7 +316,7 @@ def download_link(link, title, artist):
mp3file = MP3(title + '.mp3', ID3=EasyID3)
googled = search_google(title, artist, "")
try:
mp3file['title'] = title.replace("\\", "/")
mp3file['title'] = title
print ("\n%s Metadata parsing:")
print ('\t%s Title parsed: %s' % (output("g"), mp3file['title']))
mp3file['artist'] = artist
@ -349,6 +357,7 @@ def rip_soundtrack(movie, what_to_do):
print ("%s There was an error finding the soundtrack for '%s':\n%s" % (output('e'), movie, e))
def main():
try:
i = 0
args = sys.argv
del args[i]
@ -408,6 +417,9 @@ def main():
rip_soundtrack(" ".join(args[0:]), what_to_do)
else:
raise Exception("no media")
except Exception as e:
invalid_format()
def invalid_format():
# I feel like there should be an easier way to write out help for command-line interfaces ...