Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Radiotechniman/Anorak
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: Fursje/Anorak
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 3 files changed
  • 1 contributor

Commits on Oct 18, 2014

  1. Add ugly newznab support

    plex update changed to only notify lib that is called Anime
    Fursje committed Oct 18, 2014
    Copy the full SHA
    61980a7 View commit details
Showing with 71 additions and 7 deletions.
  1. +8 −5 anorak/downloader.py
  2. +61 −0 anorak/newznab.py
  3. +2 −2 anorak/notify.py
13 changes: 8 additions & 5 deletions anorak/downloader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from anorak import fanzub, regex, sabnzbd
from anorak import fanzub, regex, sabnzbd, newznab

class Downloader:

@@ -12,19 +12,22 @@ def download(self):
# reset matched
self.matched = []
# Strip symbols from anime name making it easier to get more relevant search results
symbols = '[.!,;?]'
symbols = '[.!,;?\-]'
# check for x-jat title override
if self.anime.alternativeTitle != None and len(self.anime.alternativeTitle) > 0:
friendlyName = re.sub(symbols, '', self.anime.alternativeTitle)
else:
friendlyName = re.sub(symbols, '', self.anime.title)

search = fanzub.search(self.anime.subber, friendlyName, self.episode)
#search = fanzub.search(self.anime.subber, friendlyName, self.episode)
search = newznab.search(self.anime.subber, friendlyName, self.episode, self.anime.quality)

for item in search:
#print "%s, %s" % (item.name, item.url)
regexParser = self.regexParser.parse(item.name)
# match the series name case insensitively
#print "1 s: [%s] db:[%s]" % (regexParser.series_name.lower(), self.anime.title.lower())
#print "2 s: [%s] db:[%s]" % (regexParser.series_name.lower(), self.anime.alternativeTitle.lower())
if regexParser.series_name.lower() != self.anime.title.lower() and regexParser.series_name.lower() != self.anime.alternativeTitle.lower():
continue
# match the episode number & convert to int first because we might have left hand zeroes
@@ -34,7 +37,7 @@ def download(self):
if self.anime.quality == 0:
self.matched.append(item)
continue
# match the quality
# match the quality - need a None match fix
if str(self.anime.quality) in regexParser.extra_info:
self.matched.append(item)

@@ -45,4 +48,4 @@ def download(self):
name = self.matched[0].name
return sabnzbd.SABnzbd(name, url)
except IndexError:
return False
return False
61 changes: 61 additions & 0 deletions anorak/newznab.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# This plugin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This plugin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses/.

import lib.anidb.requests as requests
import re
import xml.etree.ElementTree as ET

class Download:
def __init__(self):
self.url = None
self.name = None
self.size = None
self.external_id = None

def search(group, anime, episode, quality):
payload = {
"cat": "5070",
"apikey": "_API_KEY_",
"t": "tvsearch",
"max": 100
}
downloads = []
if quality != 0:
payload['q'] = "%s %s %s %sp" % (group, anime, episode, quality)
else:
payload['q'] = "%s %s %s" % (group, anime, episode)

r = requests.get("http://_HOST_/api", params=payload)
print("newznab final search for term %s url %s" % (payload['q'], r.url))
try:
xml = ET.fromstring(r.text)
items = xml.findall("channel/item")
except Exception:
print("Error trying to load newznab feed")

for item in items:
title = item.find("title").text
if "- {:>02}".format(episode) not in title:
continue
url = item.find("link").text
ex_id = 0
curSize = int(item.find("enclosure").attrib["length"])
print("Found on newznab; name:[%s] size:[%s] id:[%s] url:[%s]" % (title, curSize, ex_id, url))
d = Download()
d.url = url
d.name = title
d.size = curSize
d.external_id = ex_id
downloads.append(d)

return downloads
4 changes: 2 additions & 2 deletions anorak/notify.py
Original file line number Diff line number Diff line change
@@ -32,12 +32,12 @@ def update_plex():
return False

for s in sections:
if s.getAttribute('type') == "show":
if s.getAttribute('type') == "show" and s.getAttribute('title') == "Anime":
url = "%slibrary/sections/%s/refresh" % (host, s.getAttribute('key'))
try:
urllib.urlopen(url)
except Exception, e:
print("Error updating library section for Plex Media Server: " + ex(e))
return False

return True
return True