Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #By Remi_Scarlet aka 7h3d4rkw0lf
- from HTMLParser import HTMLParser
- from htmlentitydefs import name2codepoint
- import urllib2
- import re
- import string
- import os.path
- import subprocess
- from time import strftime, gmtime
- import time
- #insert first couple of words of group+show you want
- listOfAnimes = ["", "", "", "", "", "", ""]
- listOfAnimes[0] = "[FTW]_Watashi_ga_Motenai"
- listOfAnimes[1] = "[Vivid] Kamisama no Inai"
- listOfAnimes[2] = "[UTW]_Fate_Kaleid_Liner"
- listOfAnimes[3] = "[Vivid] Stella Jogakuin"
- listOfAnimes[4] = "[Commie] Love Lab"
- listOfAnimes[5] = ""
- listOfAnimes[6] = ""
- #insert search terms for each show.
- url = ["","","","","","",""]
- url[0] = "ftw watashi ga motenai"
- url[1] = "vivid kamisama no inai"
- url[2] = "utw fate kaleid liner"
- url[3] = "vivid stella jogakuin"
- url[4] = "commie love lab"
- url[5] = "Blank!"
- url[6] = "Blank!"
- for i in range(len(listOfAnimes)):
- listOfAnimes[i] = string.replace(listOfAnimes[i],"[","\[")
- listOfAnimes[i] = string.replace(listOfAnimes[i],"]","\]")
- print listOfAnimes[i]
- dataArray = ["", "", ""]
- for i in range(len(url)):
- if url[i] != "Blank!":
- temp = url[i].split(" ")
- url[i] = "http://www.nyaa.se/?page=search&cats=0_0&filter=0&term="
- for x in range(len(temp)):
- url[i] = url[i]+temp[x]
- if x != len(temp)-1:
- url[i] = url[i]+"+"
- print url[i]
- def animeDirectory(nameOfShow, data):
- if nameOfShow == listOfAnimes[0]:
- torrentLoc = "D:\\Anime Torrents\\Watamote\\torrents\\"+data+".torrent"
- if nameOfShow == listOfAnimes[1]:
- torrentLoc = "D:\\Anime Torrents\\Kamisama no Inai\\torrents\\"+data+".torrent"
- if nameOfShow == listOfAnimes[2]:
- torrentLoc = "D:\\Anime Torrents\\Fate Kaleid\\torrents\\"+data+".torrent"
- if nameOfShow == listOfAnimes[3]:
- torrentLoc = "D:\\Anime Torrents\\Stella Jogakuin\\torrents\\"+data+".torrent"
- if nameOfShow == listOfAnimes[4]:
- torrentLoc = ""
- if nameOfShow == listOfAnimes[5]:
- torrentLoc = ""
- if nameOfShow == listOfAnimes[6]:
- torrentLoc = ""
- return torrentLoc
- def doesExist(torrentLoc):
- if os.path.isfile(torrentLoc) == True:
- return True
- if os.path.isfile(torrentLoc) == False:
- return False
- def openTorrent(torrentLoc, animeLoc, data):
- bittorrentPath = r'G:\\BitTorrent\\BitTorrent.exe'
- subprocess.call([bittorrentPath, "/directory", animeLoc, torrentLoc])
- print "@@@@@@@@@@@@@@"
- print "@@@Success!@@@"
- print "@@@@@@@@@@@@@@"
- print "Downloading", data, "to", animeLoc+data
- class NyaaParser(HTMLParser):
- def handle_starttag(self, tag, attrs):
- #print "Start tag: ", tag
- for attr in attrs:
- #print "--attr:", attr
- if tag == 'a' and re.match("\('href',", str(attr)) != None:
- attribute = str(attr)
- #print "link for anime desu --------------", attribute[11:-2]
- dataArray[0] = attribute[11:-2]
- dataArray[0] = string.replace(dataArray[0],"view","download")
- def handle_data(self, data):
- for i in listOfAnimes:
- if i == "":
- break
- torrentLoc = animeDirectory(i, data)
- if re.match(i, str(data)) != None and re.search(".mkv", str(data)) != None:
- print "Torrent Name: ", data
- print "Match found!"
- if doesExist(torrentLoc) == False:
- print "!!!!!!Downloading file!!!!!!"
- print "Downloaded to: "+torrentLoc
- urlFile = urllib2.urlopen(dataArray[0]+"&txt=1")
- print "Torrent downloaded from: "+dataArray[0]+"&txt=1"
- localFile = open(torrentLoc, 'wb')
- localFile.write(urlFile.read())
- localFile.close()
- animeLoc = string.replace(torrentLoc,"\\torrents\\"+data+".torrent","")
- if doesExist(animeLoc+data) == False:
- openTorrent(torrentLoc, animeLoc, data)
- else:
- print "Weird. Seems like you didn't have the torrent file but DID have the mkv file already! Bittorrent not opened."
- print "------------------------------------"
- print "------------------------------------"
- else:
- print "Oops! Already exists on local drive. Not downloading", data + ".torrent"
- print "------------------------------------"
- print "------------------------------------"
- lastTime = ""
- while 1:
- if strftime("%H:%M:%S", gmtime()) == "03:59:59":
- for i in url:
- if i != "Blank!":
- print i
- data = urllib2.urlopen(i)
- source = data.read()
- parser = NyaaParser()
- parser.feed(source)
- print "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
- else:
- print "No more animes to search! We're done!"
- break
- else:
- if lastTime != strftime("%H:%M:%S", gmtime()):
- print "Will check for new episodes at 03:59:59PM UTC. Current time is: "+strftime("%H:%M:%S", gmtime()), "UTC"
- lastTime = strftime("%H:%M:%S", gmtime())
- time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement