Created
August 16, 2014 20:19
-
-
Save anonymous/266713ce5ce535f517b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import readline | |
import subprocess | |
import urllib | |
import urllib2 | |
from sys import exit | |
from bs4 import BeautifulSoup as bs | |
def get_titles(): | |
soup = bs((urllib2.urlopen("https://animetwist.net"))) | |
titles = [t.text.replace(" ","_") for t in soup.select("li a") if t.text != "ONGOING"] | |
links = ["https://animetwist.net%s" % t.get('href') for t in soup.select("li a") if t.text != "ONGOING"] | |
AnimeDict = dict(zip(titles,links)) | |
return titles,links,AnimeDict | |
def complete(text, state): | |
global matches | |
options = titles | |
if state == 0: # on first trigger, build possible matches | |
if text: # cache matches (entries that start with entered text) | |
matches = [s for s in options if s and s.startswith(text)] | |
else: # no text entered, all matches possible | |
matches = options[:] | |
try: | |
return matches[state] | |
except IndexError: | |
return None | |
global matches | |
readline.set_completer(complete) | |
readline.parse_and_bind('tab: complete') | |
titles,links,AnimeDict = get_titles() | |
show = raw_input("What show do you want to watch ") | |
soup = bs((urllib2.urlopen(AnimeDict[show]))) | |
eps = [ep.text for ep in soup.select("li a")] | |
match = 0 | |
for ep in eps: | |
possibles = [ | |
("/%s/%s%05d.mp4" % (show.lower().replace("_",""),show.lower().replace("_",""),int(ep))), | |
(urllib.quote(("/%s/[HorribleSubs] %s - %02d [1080p].mp4" % (show.lower().replace("_",""),(show.replace("_"," ")),int(ep))),"[]/")), | |
("/%s/%s%05d.mp4" % (show.split("_")[0],show.split("_")[0],int(ep))), | |
(urllib.quote(("/%s/[HorribleSubs] %s! - %02d [1080p].mp4" % (show.lower().replace("_",""),(show.replace("_"," ")),int(ep))),"[]/!")) | |
] | |
for p in possibles: | |
try: | |
r = urllib2.urlopen("https://animetwist.net/mount%s" % p) | |
match = p | |
break | |
except urllib2.HTTPError, e: | |
pass | |
if match == 0: | |
print "Couldn't find match Exiting..." | |
exit(0) | |
mpv = subprocess.Popen(["mpv","https://animetwist.net/mount%s" % match]) | |
while 1: | |
if mpv.poll() is 0: | |
break | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment