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