mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-09 20:15:27 +00:00
Entirely rewrote the program so that it's much more efficient, although many features were taken out.
This commit is contained in:
parent
c0330ce3f4
commit
80cc29b818
103
README.md
103
README.md
|
@ -1,10 +1,13 @@
|
||||||
# The Ingenious Redistribution System (IRS)
|
# Ingenious Redistribution System <sub><sup>v2.0<sup><sub>
|
||||||
|
|
||||||
Downloads or streams media from the name of the song / album / movie / tv-show that you requested.
|
An "ingenious" program to download music and then parse metadata for the downloaded file.
|
||||||
|
|
||||||
# CURRENTLY BEING REMADE BECAUSE kat.cr WAS TAKEN DOWN.
|
## Examples
|
||||||
|
|
||||||
### Dependencies
|
To download the Arctic Monkeys' album AM, you would type `$ irs album AM by Arctic Monkeys`
|
||||||
|
To download a single song you would do `$ irs song Should I Stay Or Should I Go by The Clash`
|
||||||
|
|
||||||
|
## Installation/Dependencies
|
||||||
|
|
||||||
First, actually install python and pip:
|
First, actually install python and pip:
|
||||||
- To install python3 and `pip` for Ubuntu run this command:
|
- To install python3 and `pip` for Ubuntu run this command:
|
||||||
|
@ -19,86 +22,22 @@ Then install `requirements.txt` from the repository:
|
||||||
```bash
|
```bash
|
||||||
$ pip install -r requirements.txt
|
$ pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
And you should be good to just run `irs.py`!
|
||||||
|
|
||||||
There are some more external command-line programs that are essential to movies, tv-shows, and streaming:
|
## License
|
||||||
- rTorrent: [Windows](https://rtwi.jmk.hu/wiki/rTorrentOnWindows), [OSX](http://macappstore.org/rtorrent/), Ubuntu:
|
Ingenious Redistribution System, A system built to redistribute media to the consumer.
|
||||||
|
|
||||||
```bash
|
Copyright (C) 2016 Cooper Hammond
|
||||||
$ sudo apt-get install rtorrent
|
|
||||||
```
|
|
||||||
- mpv: https://mpv.io/installation/
|
|
||||||
- Peerflix:
|
|
||||||
- Windows: follow [this](http://blog.teamtreehouse.com/install-node-js-npm-windows) guide to install npm and then run this command:
|
|
||||||
```bash
|
|
||||||
$ npm install -g peerflix
|
|
||||||
```
|
|
||||||
- OSX: Same as Windows, except follow [this](http://blog.teamtreehouse.com/install-node-js-npm-mac) guide.
|
|
||||||
- Ubuntu: Again, the same, only follow [this](http://blog.teamtreehouse.com/install-node-js-npm-linux) guide instead.
|
|
||||||
|
|
||||||
### Install
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
```bash
|
This program is distributed in the hope that it will be useful,
|
||||||
$ git clone https://github.com/kepoorhampond/IngeniousRedistributionSystem.git
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
```
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
And that should be it! Eventually it'll be put up on `pip`, to make it much, much easier to install.
|
GNU General Public License for more details.
|
||||||
|
|
||||||
### Overview
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
Currently the system can stream or download the following:
|
|
||||||
- Specific songs.
|
|
||||||
- Complete albums.
|
|
||||||
- Movies. **
|
|
||||||
- TV shows. **
|
|
||||||
- Playlists.
|
|
||||||
- Links.
|
|
||||||
- Soundtracks.
|
|
||||||
- Comics and books.* **
|
|
||||||
|
|
||||||
<sup>\* Limited only to downloading.<sup>
|
|
||||||
<sup>\*\* Does not currently work, because kat.cr was taken down.<sup>
|
|
||||||
|
|
||||||
When downloading music, the system will fill out the specific meta-data so that it will appear organized in your player of choice. It parses the following pieces of meta-data:
|
|
||||||
- Title.
|
|
||||||
- Artist.
|
|
||||||
- Album.
|
|
||||||
- Album cover/art.*
|
|
||||||
- Year released.
|
|
||||||
- Tracknumber.*
|
|
||||||
|
|
||||||
<sup>\* Album art is slightly buggy, and tracknumber only works when downloading complete album.<sup>
|
|
||||||
|
|
||||||
On a personal judgement, we would say that the complete meta-data parsing works ~80% of the time.
|
|
||||||
|
|
||||||
### Usage
|
|
||||||
```bash
|
|
||||||
$ irs (stream | download) movie <movie-name>
|
|
||||||
$ irs (stream | download) tv <tv-show> <episode>
|
|
||||||
$ irs (stream | download) (song | album) <title> by <artist>
|
|
||||||
$ irs (stream | download) playlist <txt-file-name>
|
|
||||||
$ irs (stream | download) '<link>' <title> <author>
|
|
||||||
$ irs (stream | download) soundtrack <movie>
|
|
||||||
$ irs download (comic <title> <run> | book <title> by <author>)
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Examples
|
|
||||||
```bash
|
|
||||||
$ irs download book I, Robot by Isaac Asimov
|
|
||||||
$ irs stream song Where Is My Mind by The Pixies
|
|
||||||
$ irs download album A Night At The Opera by Queen
|
|
||||||
$ irs stream movie Fight Club
|
|
||||||
$ irs download tv mr.robot s01e01
|
|
||||||
$ irs stream playlist "Rock Save The Queen.txt"
|
|
||||||
$ irs download comic Paper Girls 001
|
|
||||||
$ irs download soundtrack Super 8
|
|
||||||
$ irs download link 'https://www.youtube.com/watch?v=5sy2qLtrQQQ' "Stranger Things OST" "Kyle Dixon and Michael Stein"
|
|
||||||
```
|
|
||||||
|
|
||||||
The text file should be formatted like so: `<song>: <artist>`
|
|
||||||
```
|
|
||||||
Good Times Bad Times: Led Zeppelin
|
|
||||||
I Want To Break Free: Queen
|
|
||||||
The Man Who Sold The World: David Bowie
|
|
||||||
```
|
|
||||||
|
|
||||||
### Disclaimer
|
|
||||||
Copyrighted content may be illegal to stream and/or download in your country.
|
|
||||||
|
|
505
irs.py
505
irs.py
|
@ -1,211 +1,139 @@
|
||||||
#!/usr/bin/python3
|
import mutagen.id3, mutagen.easyid3, mutagen.mp3, youtube_dl
|
||||||
# Ingenious Redistribution System, A system built to redistribute media to the consumer.
|
import urllib.request, urllib.parse, re, sys, os, requests
|
||||||
# Copyright (C) 2016 Cooper Hammond
|
|
||||||
#
|
|
||||||
# This program is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# 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
|
|
||||||
import urllib.request, urllib.parse
|
|
||||||
from termcolor import colored
|
|
||||||
from urllib.request import Request, urlopen
|
|
||||||
|
|
||||||
from mutagen.id3 import APIC
|
|
||||||
from mutagen.easyid3 import EasyID3
|
|
||||||
from mutagen.mp3 import MP3
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import youtube_dl, mutagen
|
|
||||||
|
|
||||||
def download_album_art(album, band):
|
def search_google(song, artist, search_terms=""):
|
||||||
try:
|
def visible(element):
|
||||||
search = "%s %s" % (album, band)
|
if element.parent.name in ['style', 'script', '[document]', 'head', 'title']:
|
||||||
url = "http://www.seekacover.com/cd/" + urllib.parse.quote_plus(search)
|
return False
|
||||||
page = requests.get(url).text
|
elif re.match('<!--.*-->', str(element)):
|
||||||
soup = BeautifulSoup(page, 'html.parser')
|
return False
|
||||||
done = False
|
return True
|
||||||
for img in soup.findAll('img'):
|
string = "%s %s %s" % (song, artist, search_terms)
|
||||||
if done == False:
|
filename = 'http://www.google.com/search?q=' + urllib.parse.quote_plus(string)
|
||||||
try:
|
hdr = {
|
||||||
if search.lower() in img['title'].lower():
|
'User-Agent':'Mozilla/5.0',
|
||||||
url = img['src']
|
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
||||||
urllib.request.urlretrieve(url, "cover.jpg" % album) # &PATH;
|
}
|
||||||
done = True
|
texts = BeautifulSoup(urllib.request.urlopen(urllib.request.Request(filename, \
|
||||||
except Exception:
|
headers=hdr)).read(), 'html.parser').findAll(text=True)
|
||||||
pass
|
return list(filter(visible, texts))
|
||||||
except Exception:
|
|
||||||
print ("%s There was an error parsing the album art of '%s'" % (output("e"), album) )
|
|
||||||
|
|
||||||
def embed_mp3(art_location, song_path):
|
def parse_metadata(song, artist, location, filename, tracknum="", album=""):
|
||||||
music = mutagen.id3.ID3(song_path)
|
googled = search_google(song, artist)
|
||||||
|
mp3file = mutagen.mp3.MP3("%s/%s" % (location, filename), ID3=mutagen.easyid3.EasyID3)
|
||||||
|
print ("%s Metadata parsing:" % color('[+]','OKBLUE'))
|
||||||
|
|
||||||
music.delall('APIC')
|
# Song title
|
||||||
|
|
||||||
music.add(APIC(
|
|
||||||
encoding=0,
|
|
||||||
mime="image/jpg",
|
|
||||||
type=3,
|
|
||||||
desc='',
|
|
||||||
data=open(art_location, "rb").read()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
music.save()
|
|
||||||
|
|
||||||
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))
|
|
||||||
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())
|
|
||||||
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()
|
|
||||||
for char in special_chars:
|
|
||||||
title = title.replace(char, "")
|
|
||||||
song_title = (song.lower()).split("/")
|
|
||||||
for song in song_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
|
|
||||||
return audio_url
|
|
||||||
except Exception as e:
|
|
||||||
print ("%s There was an error finding the url of '%s'" % (output("e"), song) )
|
|
||||||
|
|
||||||
def rip_mp3(song, author, album, tracknum, soundtrack=False):
|
|
||||||
audio_url = find_mp3(song, author, soundtrack=soundtrack)
|
|
||||||
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 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(filename + ".mp3", ID3=EasyID3)
|
|
||||||
print ("\n%s Metadata parsing:" % output("s"))
|
|
||||||
try:
|
|
||||||
mp3file['title'] = song
|
mp3file['title'] = song
|
||||||
except Exception:
|
|
||||||
mp3file['title'] = ""
|
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
print ('\t%s Title parsed: %s' % (output("g"), mp3file['title']))
|
print ("\t%s Title parsed: " % color('[+]','OKGREEN') + mp3file['title'][0])
|
||||||
|
|
||||||
mp3file['artist'] = author
|
# Artist
|
||||||
|
mp3file['artist'] = artist
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
print ('\t%s Author parsed: %s' % (output("g"), mp3file['artist']))
|
print ("\t%s Artist parsed: " % color('[+]','OKGREEN') + mp3file['artist'][0])
|
||||||
|
|
||||||
|
# Album
|
||||||
if album == "":
|
if album == "":
|
||||||
for i, j in enumerate(googled):
|
for i, j in enumerate(googled):
|
||||||
if "Album:" in j:
|
if "Album:" in j:
|
||||||
album = (googled[i + 1])
|
album = (googled[i + 1])
|
||||||
try:
|
try:
|
||||||
mp3file['album'] = album
|
mp3file['album'] = album
|
||||||
mp3file.save()
|
print ("\t%s Album parsed: " % color('[+]','OKGREEN') + mp3file['album'][0])
|
||||||
except Exception:
|
except Exception:
|
||||||
mp3file['album'] = ""
|
|
||||||
mp3file.save()
|
|
||||||
print ('\t%s Album Auto-parsed: %s' % (output("g"), mp3file['album']))
|
|
||||||
else:
|
|
||||||
try:
|
|
||||||
mp3file['album'] = album
|
mp3file['album'] = album
|
||||||
|
print ("\t%s Album not parsed" % color('[-]','FAIL'))
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
except Exception:
|
|
||||||
mp3file['album'] = ""
|
|
||||||
mp3file.save()
|
|
||||||
print ('\t%s Album parsed: %s' % (output("g"), mp3file['album']))
|
|
||||||
|
|
||||||
|
# Album art
|
||||||
if mp3file['album'][0] != "":
|
if mp3file['album'][0] != "":
|
||||||
try:
|
try:
|
||||||
download_album_art(mp3file['album'][0], author)
|
download_album_art(mp3file['album'][0], artist, location=location)
|
||||||
embed_mp3("cover.jpg", song + ".mp3") # &PATH;
|
embed_mp3("%s/cover.jpg" % location, "%s/%s" % (location, filename))
|
||||||
print ("\t%s Album art Auto-parsed!" % output("g"))
|
print ("\t%s Album art parsed" % color('[+]','OKGREEN'))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print ("%s There was a problem with Auto-parsing the album art of: '%s'"\
|
print ("\t%s Album art not parsed" % color('[-]','FAIL'))
|
||||||
% (output("e"), song))
|
|
||||||
print (e)
|
|
||||||
|
|
||||||
|
# Release date
|
||||||
for i, j in enumerate(googled):
|
for i, j in enumerate(googled):
|
||||||
if "Released:" in j:
|
if "Released:" in j:
|
||||||
date = (googled[i + 1])
|
date = (googled[i + 1])
|
||||||
try:
|
try:
|
||||||
mp3file['date'] = date
|
mp3file['date'] = date
|
||||||
|
print ("\t%s Release date parsed" % color('[+]','OKGREEN'))
|
||||||
except Exception:
|
except Exception:
|
||||||
mp3file['date'] = ""
|
mp3file['date'] = ""
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
print ('\t%s Release date Auto-parsed: "%s"' % (output("g"), mp3file['date'][0]))
|
|
||||||
|
|
||||||
|
# Track number
|
||||||
if tracknum != "":
|
if tracknum != "":
|
||||||
mp3file['tracknumber'] = str(tracknum)
|
mp3file['tracknumber'] = str(tracknum)
|
||||||
mp3file.save()
|
mp3file.save()
|
||||||
|
|
||||||
print ('\n%s "' % output("g") + song + '" by ' + author + ' downloaded successfully\n')
|
print ("\n%s \"%s\" downloaded successfully!\n" % (color('[+]','OKGREEN'), song))
|
||||||
except Exception as e:
|
|
||||||
print (e)
|
|
||||||
|
|
||||||
def output(string):
|
def embed_mp3(art_location, song_location):
|
||||||
if string == "q":
|
music = mutagen.id3.ID3(song_location)
|
||||||
return colored("[?]", "cyan", attrs=['bold'])
|
music.delall("APIC")
|
||||||
elif string == "e":
|
music.add(mutagen.id3.APIC(encoding=0, mime="image/jpg", type=3, desc='', \
|
||||||
return colored("[-]", "red", attrs=['bold'])
|
data=open(art_location, 'rb').read()))
|
||||||
elif string == "g":
|
music.save()
|
||||||
return colored("[+]", "green", attrs=['bold'])
|
|
||||||
elif string == "s":
|
|
||||||
return colored("[*]", "blue", attrs=['bold'])
|
|
||||||
|
|
||||||
def visible(element):
|
def download_album_art(album, artist, location=""):
|
||||||
if element.parent.name in ['style', 'script', '[document]', 'head', 'title']:
|
|
||||||
return False
|
|
||||||
elif re.match('<!--.*-->', str(element)):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
def search_google(song_name, band, search_terms):
|
|
||||||
try:
|
try:
|
||||||
string = "%s %s %s" % (song_name, band, search_terms)
|
search = "%s %s" % (album, artist)
|
||||||
filename = 'http://www.google.com/search?q=' + urllib.parse.quote_plus(string)
|
url = "http://www.seekacover.com/cd/" + urllib.parse.quote_plus(search)
|
||||||
hdr = {
|
soup = BeautifulSoup(requests.get(url).text, 'html.parser')
|
||||||
'User-Agent':'Mozilla/5.0',
|
done = False
|
||||||
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
for img in soup.findAll('img'):
|
||||||
}
|
if done == False:
|
||||||
texts = BeautifulSoup(urlopen(Request(filename, headers=hdr)).read(), 'html.parser')\
|
try:
|
||||||
.findAll(text=True)
|
if search.lower() in img['title'].lower():
|
||||||
|
urllib.request.urlretrieve(img['src'], "%s/cover.jpg" % location)
|
||||||
|
done = True
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
visible_texts = list(filter(visible, texts))
|
def strip_special_chars(string):
|
||||||
return visible_texts
|
special_chars = "\ / : * ? \" < > | - ( )".split(" ")
|
||||||
except Exception as e:
|
for char in special_chars:
|
||||||
print ("%s There was an error with Auto-parsing." % output("e"))
|
string.replace(char, "")
|
||||||
return
|
return string
|
||||||
|
|
||||||
def get_album(album_name, artist, what_to_do, search, tried=False):
|
def color(text, type):
|
||||||
visible_texts = search_google(album_name, artist, search)
|
types = {'HEADER': '\033[95m', 'OKBLUE': '\033[94m', 'OKGREEN': '\033[92m',
|
||||||
|
'WARNING': '\033[93m','FAIL': '\033[91m','ENDC': '\033[0m','BOLD': '\033[1m'
|
||||||
|
,'UNDERLINE': '\033[4m'}
|
||||||
|
return types[type] + text + types['ENDC']
|
||||||
|
|
||||||
|
def find_mp3(song, artist):
|
||||||
|
search_terms = song + " " + artist
|
||||||
|
print ("\"%s\" by %s" % (song, artist))
|
||||||
|
query_string = urllib.parse.urlencode({"search_query" : (search_terms)})
|
||||||
|
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())
|
||||||
|
in_title = False
|
||||||
|
i = -1
|
||||||
|
given_up_score = 0
|
||||||
|
while in_title == False:
|
||||||
|
i += 1
|
||||||
|
given_up_score += 1
|
||||||
|
if given_up_score >= 10:
|
||||||
|
in_title = True
|
||||||
|
audio_url = ("http://www.youtube.com/watch?v=" + search_results[i])
|
||||||
|
title = strip_special_chars((BeautifulSoup(urllib.request.urlopen(audio_url), 'html.parser')).title.string.lower())
|
||||||
|
song_title = song.lower().split("/")
|
||||||
|
for song in song_title:
|
||||||
|
if strip_special_chars(song) in strip_special_chars(title):
|
||||||
|
in_title = True
|
||||||
|
return search_results[i]
|
||||||
|
|
||||||
|
def rip_album(album, artist, tried=False, search="album"):
|
||||||
|
visible_texts = search_google(album, artist, search)
|
||||||
try:
|
try:
|
||||||
songs = []
|
songs = []
|
||||||
num = True
|
num = True
|
||||||
|
@ -225,225 +153,60 @@ def get_album(album_name, artist, what_to_do, search, tried=False):
|
||||||
num = False
|
num = False
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
if what_to_do == "download":
|
|
||||||
for i, j in enumerate(songs):
|
for i, j in enumerate(songs):
|
||||||
rip_mp3(j, artist, album_name, i + 1)
|
rip_mp3(j, artist, part_of_album=True, album=album, tracknum=i + 1)
|
||||||
elif what_to_do == "stream":
|
|
||||||
for i in songs:
|
|
||||||
a = find_mp3(i, artist)
|
|
||||||
command = 'mpv "%s" --no-video' % a
|
|
||||||
os.system(command)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if str(e) == "local variable 'indexed' referenced before assignment" or str(e) == 'list index out of range':
|
if str(e) == "local variable 'indexed' referenced before assignment" or str(e) == 'list index out of range':
|
||||||
if tried != True:
|
if tried != True:
|
||||||
print ("%s Trying to find album ..." % output("s"))
|
print ("%s Trying to find album ..." % color('[*]','OKBLUE'))
|
||||||
get_album(album_name, artist, what_to_do, "", True)
|
rip_album(album, artist, tried=True, search="")
|
||||||
else:
|
else:
|
||||||
print ("%s Could not find album %s" % (output("e"), album_))
|
print ("%s Could not find album '%s'" % (color('[-]','FAIL'), album))
|
||||||
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'" % (color('[-]','FAIL'), album))
|
||||||
|
|
||||||
|
def rip_mp3(song, artist, part_of_album=False, album="", tracknum=""):
|
||||||
|
audio_code = find_mp3(song, artist)
|
||||||
|
filename = strip_special_chars(song) + ".mp3"
|
||||||
|
ydl_opts = {
|
||||||
|
'format': 'bestaudio/best',
|
||||||
|
#'quiet': True,
|
||||||
|
'postprocessors': [{
|
||||||
|
'key': 'FFmpegExtractAudio',
|
||||||
|
'preferredcodec': 'mp3',
|
||||||
|
}],
|
||||||
|
}
|
||||||
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
ydl.download(["http://www.youtube.com/watch?v=" + audio_code])
|
||||||
|
|
||||||
def get_torrent_url(args, category):
|
artist_folder = artist
|
||||||
try:
|
if not os.path.isdir(artist_folder):
|
||||||
search_url = 'http://kickass.mx/search.php?q=' + urllib.parse.quote_plus((" ".join(args) + \
|
os.makedirs(artist_folder)
|
||||||
" category:" + category))
|
if not part_of_album:
|
||||||
search_request_response = requests.get(search_url, verify=True)
|
location = artist_folder
|
||||||
soup = BeautifulSoup(search_request_response.text, 'html.parser')
|
|
||||||
results, ran_out = 0, False
|
|
||||||
i = 0
|
|
||||||
print ("")
|
|
||||||
while True:
|
|
||||||
movie_page = soup.find_all("a", class_="cellMainLink")
|
|
||||||
for number in range(0,10):
|
|
||||||
try:
|
|
||||||
print ("%s. " % (number + 1) + movie_page[number].string)
|
|
||||||
results += 1
|
|
||||||
except Exception:
|
|
||||||
ran_out = True
|
|
||||||
pass
|
|
||||||
if ran_out == True:
|
|
||||||
if results == 0:
|
|
||||||
print (output('e') + " No results.\n")
|
|
||||||
exit(0)
|
|
||||||
else:
|
|
||||||
print (output('e') + " End of results.")
|
|
||||||
if results != 0:
|
|
||||||
|
|
||||||
try: a = int(str(input("\n%s What torrent would you like? " % output("q")))) - 1
|
if album != "" and part_of_album:
|
||||||
except Exception: a = 100; pass
|
album_folder = artist + "/" + album
|
||||||
# This code is either hyper-efficient, or completely against every ettiquite.
|
if not os.path.isdir(album_folder):
|
||||||
|
os.makedirs(album_folder)
|
||||||
|
location = album_folder
|
||||||
|
|
||||||
if a in tuple(range(0, 10)):
|
for file in os.listdir("."):
|
||||||
search_url = requests.get('https://kat.cr' + movie_page[a].get('href'), verify=True)
|
if audio_code in file:
|
||||||
soup = BeautifulSoup(search_url.text, 'html.parser')
|
os.rename(file, location + "/" + filename)
|
||||||
torrent_url = 'https:' + soup.find_all('a', class_='siteButton')[0].get('href')
|
|
||||||
return torrent_url
|
|
||||||
except Exception as e:
|
|
||||||
print ("%s There was an error getting the torrent url with '%s'" % (output("e"), " ".join(args)))
|
|
||||||
|
|
||||||
def rip_playlist(file_name, what_to_do):
|
parse_metadata(song, artist, location, filename, tracknum=tracknum, album=album)
|
||||||
txt_file = open(file_name, 'r')
|
|
||||||
things_that_went_wrong = []
|
|
||||||
something_went_wrong = False
|
|
||||||
for line in txt_file:
|
|
||||||
try:
|
|
||||||
arr = line.strip("\n").split(": ")
|
|
||||||
song = arr[0]
|
|
||||||
artist = arr[1]
|
|
||||||
if what_to_do == "download":
|
|
||||||
rip_mp3(song, artist, "", "")
|
|
||||||
elif what_to_do == "stream":
|
|
||||||
os.system("mpv '%s' --no-video" % find_mp3(song, artist))
|
|
||||||
except Exception as e:
|
|
||||||
something_went_wrong = True
|
|
||||||
things_that_went_wrong.append(line)
|
|
||||||
pass
|
|
||||||
if something_went_wrong == True:
|
|
||||||
print ("%s Something was wrong with the formatting of the following lines:" % output("e"))
|
|
||||||
for i in things_that_went_wrong: print ("\t%s" % i)
|
|
||||||
|
|
||||||
def download_link(link, title, artist):
|
|
||||||
print ("'%s' by '%s' from '%s'\n" % (title, artist, link))
|
|
||||||
try:
|
|
||||||
os.system('youtube-dl --metadata-from-title "%(title)s" --extract-audio \
|
|
||||||
--audio-format mp3 --add-metadata ' + link)
|
|
||||||
except Exception as e:
|
|
||||||
print ('%s Error with given link:\n' % output("e") + e)
|
|
||||||
exit(0)
|
|
||||||
mp3file = MP3(title + '.mp3', ID3=EasyID3)
|
|
||||||
googled = search_google(title, artist, "")
|
|
||||||
try:
|
|
||||||
mp3file['title'] = title
|
|
||||||
print ("\n%s Metadata parsing:")
|
|
||||||
print ('\t%s Title parsed: %s' % (output("g"), mp3file['title']))
|
|
||||||
mp3file['artist'] = artist
|
|
||||||
print ('\t%s Author parsed: %s' % (output("g"), mp3file['artist']))
|
|
||||||
mp3file.save()
|
|
||||||
except Exception as e:
|
|
||||||
print ("%s Error with parsing title/author for '%s'" % (output('e'), title))
|
|
||||||
try:
|
|
||||||
for i, j in enumerate(googled):
|
|
||||||
if "Album:" in j:
|
|
||||||
album = (googled[i + 1])
|
|
||||||
try:
|
|
||||||
mp3file['album'] = album
|
|
||||||
mp3file.save()
|
|
||||||
except Exception:
|
|
||||||
mp3file['album'] = ""
|
|
||||||
mp3file.save()
|
|
||||||
except Exception as e:
|
|
||||||
print ("%s Error with Auto-parsing '%s'" % (output('e'), title))
|
|
||||||
|
|
||||||
def rip_soundtrack(movie, what_to_do):
|
|
||||||
try:
|
|
||||||
search = search_google("", "", movie + " soundtrack")
|
|
||||||
songs = []
|
|
||||||
|
|
||||||
for i, j in enumerate(search):
|
|
||||||
if j.replace("\n", "") == ',':
|
|
||||||
songs.append(search[i - 1])
|
|
||||||
|
|
||||||
if what_to_do == 'download':
|
|
||||||
for i in songs:
|
|
||||||
rip_mp3(i, movie, "", "", soundtrack=True)
|
|
||||||
elif what_to_do == 'stream':
|
|
||||||
for i in songs:
|
|
||||||
command = "mpv '%s' --no-video" % find_mp3(i, movie, soundtrack=True)
|
|
||||||
os.system(command)
|
|
||||||
except Exception as e:
|
|
||||||
print ("%s There was an error finding the soundtrack for '%s':\n%s" % (output('e'), movie, e))
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
media = sys.argv[1]
|
||||||
i = 0
|
args = " ".join(sys.argv[2:]).split(" by ")
|
||||||
args = sys.argv
|
|
||||||
del args[i]
|
|
||||||
what_to_do = args[i]
|
|
||||||
del args[i]
|
|
||||||
|
|
||||||
if what_to_do not in ("download", "stream"): raise Exception("no what-to-do")
|
|
||||||
|
|
||||||
media = args[i]
|
|
||||||
del args[i]
|
|
||||||
|
|
||||||
if media == "song":
|
if media == "song":
|
||||||
song = (" ".join(args)).split(" by ")
|
rip_mp3(args[0], args[1])
|
||||||
if what_to_do == "stream":
|
|
||||||
command = 'mpv "%s" --no-video' % find_mp3(song[0], song[1])
|
|
||||||
os.system(command)
|
|
||||||
elif what_to_do == "download":
|
|
||||||
rip_mp3(song[0], song[1], "", "")
|
|
||||||
|
|
||||||
elif media == "album":
|
elif media == "album":
|
||||||
album_name = (" ".join(args)).split(" by ")
|
rip_album(args[0], args[1])
|
||||||
get_album(album_name[0], album_name[1], what_to_do, "album")
|
|
||||||
|
|
||||||
elif media == "playlist":
|
|
||||||
rip_playlist(args[-1], what_to_do)
|
|
||||||
|
|
||||||
elif media in ("comic", "book"):
|
|
||||||
if what_to_do == "download":
|
|
||||||
os.system("rtorrent '%s'" % get_torrent_url(args, media + "s"))
|
|
||||||
exit(0)
|
|
||||||
elif what_to_do == "stream":
|
|
||||||
print ("\n%s Streaming is unavailable for comics and books.\n" % output("e"))
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
elif media == "movie":
|
|
||||||
if what_to_do == "stream":
|
|
||||||
os.system('peerflix "%s" -a -d --mpv' % get_torrent_url(args, 'movie'))
|
|
||||||
exit(0)
|
|
||||||
elif what_to_do == "download":
|
|
||||||
os.system("rtorrent '%s'" % get_torrent_url(args, 'movie'))
|
|
||||||
exit(0)
|
|
||||||
|
|
||||||
elif media == "tv":
|
|
||||||
if what_to_do == "stream":
|
|
||||||
os.system('peerflix "%s" -a -d --mpv' % get_torrent_url(args, 'tv'))
|
|
||||||
exit(0)
|
|
||||||
elif what_to_do == "download":
|
|
||||||
os.system("rtorrent '%s'" % get_torrent_url(args, 'tv'))
|
|
||||||
exit(0)
|
|
||||||
elif media == 'link':
|
|
||||||
if what_to_do == 'stream':
|
|
||||||
os.system('mpv "%s" --no-video' % args[0])
|
|
||||||
exit(0)
|
|
||||||
elif what_to_do == 'download':
|
|
||||||
download_link(args[0], args[1], args[2])
|
|
||||||
elif media == 'soundtrack':
|
|
||||||
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 ...
|
|
||||||
print ("Usage:")
|
|
||||||
print (""" irs (stream | download) movie <movie-name>
|
|
||||||
irs (stream | download) tv <tv-show> <episode>
|
|
||||||
irs (stream | download) (song | album) <title> by <artist>
|
|
||||||
irs (stream | download) playlist <txt-file-name>
|
|
||||||
irs (stream | download) '<link>' <title> <author>
|
|
||||||
irs (stream | download) soundtrack <movie-name>
|
|
||||||
irs download (comic <title> <run> | book <title> by <author>)
|
|
||||||
""")
|
|
||||||
print ("Examples:")
|
|
||||||
print (""" irs download book I, Robot by Isaac Asimov
|
|
||||||
irs stream song Where Is My Mind by The Pixies
|
|
||||||
irs download album A Night At The Opera by Queen
|
|
||||||
irs stream movie Fight Club
|
|
||||||
irs download tv mr.robot s01e01
|
|
||||||
irs stream playlist "Rock Save The Queen.txt"
|
|
||||||
irs download comic Paper Girls 001
|
|
||||||
irs stream soundtrack Super 8
|
|
||||||
irs download link 'https://www.youtube.com/watch?v=5sy2qLtrQQQ' "Stranger Things OST" "Kyle Dixon and Michael Stein"
|
|
||||||
""")
|
|
||||||
print ("\nFor more info see: https://github.com/kepoorhampond/IngeniousRedistributionSystem")
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
mutagen == 1.31
|
mutagen==1.31
|
||||||
requests == 2.10.0
|
requests==2.11.1
|
||||||
beautifulsoup4 == 4.4.1
|
youtube_dl==2016.7.7
|
||||||
termcolor == 1.1.0
|
beautifulsoup4==4.5.1
|
||||||
youtube_dl == 2016.7.7
|
|
||||||
|
|
Loading…
Reference in a new issue