Created
January 17, 2013 10:46
-
-
Save navinpai/4555171 to your computer and use it in GitHub Desktop.
Download complete anime season from AnimeSeed. Written as simple as possible so that a Baka friend can understand it! :)
Note: Works only on AnimeSeed, and for video links from auengine.com. For other sites, just modify the get_episode function
This file contains hidden or 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
| from urllib2 import Request, urlopen, URLError, HTTPError | |
| from bs4 import BeautifulSoup | |
| import requests | |
| import re | |
| import urllib | |
| import sys | |
| episodeArray=[] | |
| animeTitle="" | |
| def download_file(file_name,filetype,url): | |
| try: | |
| print "downloading " + url | |
| response = urllib.request.urlopen(url).read() | |
| outpath = os.path.join(os.getcwd(), animeTitle+"_"+file_name+filetype) | |
| videofile = open(outpath , 'wb') | |
| videofile.write(response) | |
| videofile.close() | |
| except HTTPError, e: | |
| print "HTTP Error:",e.code , url | |
| except URLError, e: | |
| print "URL Error:",e.reason , url | |
| def get_episode(episodenumber,link): | |
| r = requests.get(link) | |
| videolink=re.findall(r'url: \'(.*?)\'',str(r.text)) | |
| download_file('episode_'+str(episodenumber),'.mp4',urllib.unquote(videolink[-1])) | |
| def get_title(soup): | |
| global animeTitle | |
| pagetitle=soup.find('title') | |
| title=re.findall(r'Watch (.*?) Online',str(pagetitle)) | |
| animeTitle=title[0].replace (" ", "_") | |
| def download_season(): | |
| i=1 | |
| for episode in episodeArray: | |
| r = requests.get(episode[0]) | |
| soup=BeautifulSoup(r.text) | |
| for iframe in soup("iframe"): | |
| x=soup.iframe.extract() | |
| iframelink=re.findall(r'src="(.*?)"',str(x)) | |
| get_episode(i,iframelink[0]) | |
| i+=1 | |
| def main(): | |
| r = requests.get(sys.argv[1]) | |
| soup=BeautifulSoup(r.text) | |
| get_title(soup) | |
| episodeListDiv=soup.find('div', attrs={'id':'linkinfo'}) | |
| table=episodeListDiv.findAll('td') | |
| for row in table[1:]: | |
| link=row.find('a') | |
| linksrc=re.findall(r'href="(.*?)"',str(link)) | |
| #print linksrc | |
| episodeArray.append(linksrc) | |
| download_season(); | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment