Soundtracks for movies

This commit is contained in:
Kepoor Hampond 2016-08-16 12:24:51 -07:00
parent 6ea0e4f68f
commit b386df5368
2 changed files with 95 additions and 70 deletions

View file

@ -45,13 +45,15 @@ And that should be it! Eventually it'll be put up on `pip`, to make it much, muc
Currently the system can stream or download the following: Currently the system can stream or download the following:
- Specific songs. - Specific songs.
- Complete albums. - Complete albums.
- Movies. - Movies. **
- TV shows. - TV shows. **
- Playlists. - Playlists.
- Links - Links.
- Comics and books.* - Soundtracks.
- Comics and books.* **
<sup>\* Limited only to downloading.<sup> <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: 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. - Title.
@ -71,7 +73,8 @@ $ irs (stream | download) movie <movie-name>
$ irs (stream | download) tv <tv-show> <episode> $ irs (stream | download) tv <tv-show> <episode>
$ irs (stream | download) (song | album) <title> by <artist> $ irs (stream | download) (song | album) <title> by <artist>
$ irs (stream | download) playlist <txt-file-name> $ irs (stream | download) playlist <txt-file-name>
irs (stream | download) '<link>' <title> <author> $ irs (stream | download) '<link>' <title> <author>
$ irs (stream | download) soundtrack <movie>
$ irs download (comic <title> <run> | book <title> by <author>) $ irs download (comic <title> <run> | book <title> by <author>)
``` ```
@ -84,6 +87,7 @@ $ irs stream movie Fight Club
$ irs download tv mr.robot s01e01 $ irs download tv mr.robot s01e01
$ irs stream playlist "Rock Save The Queen.txt" $ irs stream playlist "Rock Save The Queen.txt"
$ irs download comic Paper Girls 001 $ 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" $ irs download link 'https://www.youtube.com/watch?v=5sy2qLtrQQQ' "Stranger Things OST" "Kyle Dixon and Michael Stein"
``` ```

151
irs.py
View file

@ -60,10 +60,15 @@ def embed_mp3(art_location, song_path):
) )
music.save() music.save()
def find_mp3(song, author): def find_mp3(song, author, soundtrack=False):
try: try:
print ("'%s' by '%s'\n" % (song, author)) operator = 'by'
query_string = urllib.parse.urlencode({"search_query" : ("%s %s lyrics" % (song, author))}) 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) 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())
in_song = False in_song = False
@ -85,8 +90,8 @@ def find_mp3(song, author):
except Exception as e: except Exception as e:
print ("%s There was an error finding the url of '%s'" % (output("e"), song) ) print ("%s There was an error finding the url of '%s'" % (output("e"), song) )
def rip_mp3(song, author, album, tracknum): def rip_mp3(song, author, album, tracknum, soundtrack=False):
audio_url = find_mp3(song, author) audio_url = find_mp3(song, author, soundtrack=soundtrack)
song = song.replace("/", "\\") song = song.replace("/", "\\")
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
@ -324,71 +329,85 @@ def download_link(link, title, artist):
except Exception as e: except Exception as e:
print ("%s Error with Auto-parsing '%s'" % (output('e'), title)) print ("%s Error with Auto-parsing '%s'" % (output('e'), title))
def main(): def rip_soundtrack(movie, what_to_do):
try: try:
i = 0 search = search_google("", "", movie + " soundtrack")
args = sys.argv songs = []
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") for i, j in enumerate(search):
if j.replace("\n", "") == ',':
songs.append(search[i - 1])
media = args[i] if what_to_do == 'download':
del args[i] for i in songs:
rip_mp3(i, movie, "", "", soundtrack=True)
if media == "song": elif what_to_do == 'stream':
song = (" ".join(args)).split(" by ") for i in songs:
if what_to_do == "stream": command = "mpv '%s' --no-video" % find_mp3(i, movie, soundtrack=True)
command = 'mpv "%s" --no-video' % find_mp3(song[0], song[1])
os.system(command) os.system(command)
elif what_to_do == "download":
rip_mp3(song[0], song[1], "", "")
elif media == "album":
album_name = (" ".join(args)).split(" by ")
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])
else:
raise Exception("no media")
except Exception as e: except Exception as e:
if str(e) in ("list index out of range", "no what-to-do", "no media"): print ("%s There was an error finding the soundtrack for '%s':\n%s" % (output('e'), movie, e))
print ("%s Either you used an invalid format, or a special character.\n" % output("e"))
invalid_format() def main():
else: i = 0
print ("%s Something went wrong:\n" % output("e") + repr(e) + "\n") 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":
song = (" ".join(args)).split(" by ")
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":
album_name = (" ".join(args)).split(" by ")
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")
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 ...
@ -398,6 +417,7 @@ def invalid_format():
irs (stream | download) (song | album) <title> by <artist> irs (stream | download) (song | album) <title> by <artist>
irs (stream | download) playlist <txt-file-name> irs (stream | download) playlist <txt-file-name>
irs (stream | download) '<link>' <title> <author> irs (stream | download) '<link>' <title> <author>
irs (stream | download) soundtrack <movie-name>
irs download (comic <title> <run> | book <title> by <author>) irs download (comic <title> <run> | book <title> by <author>)
""") """)
print ("Examples:") print ("Examples:")
@ -408,6 +428,7 @@ def invalid_format():
irs download tv mr.robot s01e01 irs download tv mr.robot s01e01
irs stream playlist "Rock Save The Queen.txt" irs stream playlist "Rock Save The Queen.txt"
irs download comic Paper Girls 001 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" 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") print ("\nFor more info see: https://github.com/kepoorhampond/IngeniousRedistributionSystem")