From 2a3bddc568f62073f324c69fce89e238c3d50ff4 Mon Sep 17 00:00:00 2001 From: Kepoor Hampond Date: Sat, 9 Jul 2016 14:53:56 -0700 Subject: [PATCH] Wrote more of the readme and added some error catching functionality --- README.md | 17 ++++++++++++++--- irs.py | 37 +++++++++++++++++++------------------ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index d4db11e..8e9aadd 100644 --- a/README.md +++ b/README.md @@ -15,11 +15,14 @@ First, actually install python and pip: Then install `requirements.txt` from the repository: ```bash -python install -r requirements.txt +$ python install -r requirements.txt ``` There are some more external command-line programs that are essential to movies, tv-shows, and streaming: - - rTorrent: [Windows](https://rtwi.jmk.hu/wiki/rTorrentOnWindows), [OSX](http://macappstore.org/rtorrent/), Ubuntu: `sudo apt-get install rtorrent` + - rTorrent: [Windows](https://rtwi.jmk.hu/wiki/rTorrentOnWindows), [OSX](http://macappstore.org/rtorrent/), Ubuntu: + ```bash + $ 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: @@ -28,8 +31,14 @@ There are some more external command-line programs that are essential to movies, ``` - 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. + - VLC: Just download and install it [here](http://www.videolan.org/vlc/index.html). -And that should be it! Eventually it'll be put up on pip, to make it much easier to install. +### Install + +```bash +$ git clone https://github.com/kepoorhampond/IngeniousRedistributionSystem.git +``` +And that should be it! Eventually it'll be put up on pip, to make it much, much easier to install. ### Overview @@ -49,6 +58,8 @@ When downloading music, the system will fill out the specific meta-data so that \* Album art is slightly buggy, and tracknumber only works when downloading complete album. +On a personal judgement, we would judge that the complete meta-data parsing works ~90% of the time. + ### Usage ```bash $ IRS (stream | download) movie diff --git a/irs.py b/irs.py index 8e33f71..8aed0b2 100644 --- a/irs.py +++ b/irs.py @@ -1,3 +1,4 @@ +#!/usr/bin/python3 import os, sys, time, re, select, requests, subprocess import urllib.request, urllib.parse from termcolor import colored @@ -42,7 +43,7 @@ def embed_mp3(art_location, song_path): def find_mp3(song, author): print ("'%s' by '%s'\n" % (song, author)) - query_string = urllib.parse.quote_plus({"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) search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode()) audio_url = ("http://www.youtube.com/watch?v=" + search_results[0]) @@ -125,7 +126,7 @@ def output(string): elif string == "g": return colored("[+]", "green") elif string == "s": - return colored("[*]", "yellow") + return colored("[*]", "blue") def visible(element): if element.parent.name in ['style', 'script', '[document]', 'head', 'title']: @@ -199,7 +200,7 @@ def main(): what_to_do = args[i] del args[i] - if what_to_do not in ("download", "stream"): raise Exception + if what_to_do not in ("download", "stream"): raise Exception("no what-to-do") media = args[i] del args[i] @@ -220,7 +221,7 @@ def main(): query = 'https://kat.cr/usearch/' + urllib.parse.quote_plus((" ".join(args) + " category:movies")) if what_to_do == "stream": torrent_url = get_torrent_url(query) - os.system('peerflix "%s" -a --mpv' % torrent_url) + os.system('peerflix "%s" -a -d --vlc' % torrent_url) exit(0) elif what_to_do == "download": os.system("rtorrent '%s'" % get_torrent_url(query)) @@ -230,19 +231,19 @@ def main(): query = 'https://kat.cr/usearch/' + urllib.parse.quote_plus((" ".join(args) + " category:tv")) if what_to_do == "stream": torrent_url = get_torrent_url(query) - os.system('peerflix "%s" -a --vlc' % torrent_url) + os.system('peerflix "%s" -a -d --vlc' % torrent_url) exit(0) elif what_to_do == "download": os.system("rtorrent '%s'" % get_torrent_url(query)) exit(0) else: - raise Exception + raise Exception("no media") except Exception as e: - if str(e) == "list index out of range": - print ("%s Invalid format\n" % output("e")) + if str(e) in ("list index out of range", "no what-to-do", "no media"): + print ("%s Either you used an invalid format, or a special character.\n" % output("e")) invalid_format() else: - print ("%s Something went wrong:\n" % output("e") + e + "\n") + print ("%s Something went wrong:\n" % output("e") + repr(e) + "\n") def columns(columns): for row in columns: @@ -250,16 +251,16 @@ def columns(columns): 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 - IRS (stream | download) tv - IRS (stream | download) song by - IRS (stream | download) album by """) + print (""" irs (stream | download) movie + irs (stream | download) tv + irs (stream | download) song by + irs (stream | download) album by """) print ("Examples:") - print (""" IRS stream movie Fight Club - IRS download album A Night At The Opera by Queen - IRS stream song Where Is My Mind by The Pixies - IRS download tv mr.robot s01e01 - IRS stream album A Day At The Races by Queen""") + print (""" irs stream movie Fight Club + irs download album A Night At The Opera by Queen + irs stream song Where Is My Mind by The Pixies + irs download tv mr.robot s01e01 + irs stream album A Day At The Races by Queen""") if __name__ == '__main__': main()