Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added provider Beyond-HD #6802

Merged
merged 8 commits into from
Jun 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Unreleased

#### New Features
- Added new provider Beyond-hd ([#6802](https://github.com/pymedusa/Medusa/pull/6802))

#### Improvements

Expand Down
3 changes: 2 additions & 1 deletion medusa/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
animetorrents,
archetorrent,
avistaz,
beyondhd,
bitcannon,
bithdtv,
bjshare,
Expand Down Expand Up @@ -72,7 +73,7 @@
'danishbits', 'limetorrents', 'norbits', 'bithdtv', 'ncore', 'zooqle',
'animebytes', 'animetorrents', 'anidex', 'shanaproject', 'torrenting',
'yggtorrent', 'elitetracker', 'archetorrent', 'privatehd', 'cinemaz',
'avistaz', 'bjshare', 'gimmepeers', 'btdb'
'avistaz', 'bjshare', 'gimmepeers', 'btdb', 'beyondhd'
]


Expand Down
3 changes: 2 additions & 1 deletion medusa/providers/torrent/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
animetorrents,
archetorrent,
avistaz,
beyondhd,
bithdtv,
bjshare,
btdb,
Expand Down Expand Up @@ -72,5 +73,5 @@
'norbits', 'rarbg', 'torrentday', 'nyaa', 'rsstorrent', 'shazbat',
'hebits', 'torrentz2', 'animetorrents', 'anidex', 'shanaproject',
'torrenting', 'yggtorrent', 'elitetracker', 'privatehd', 'cinemaz',
'avistaz', 'bjshare', 'ncore', 'gimmepeers', 'btdb'
'avistaz', 'bjshare', 'ncore', 'gimmepeers', 'btdb', 'beyondhd'
]
186 changes: 186 additions & 0 deletions medusa/providers/torrent/html/beyondhd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
# coding=utf-8

"""Provider code for Beyond-hd."""

from __future__ import unicode_literals

import logging

from medusa import tv
from medusa.bs4_parser import BS4Parser
from medusa.helper.common import convert_size
from medusa.logger.adapters.style import BraceAdapter
from medusa.providers.torrent.torrent_provider import TorrentProvider

from requests.compat import urljoin
from requests.utils import dict_from_cookiejar

log = BraceAdapter(logging.getLogger(__name__))
log.logger.addHandler(logging.NullHandler())


class BeyondHDProvider(TorrentProvider):
"""Beyond-hd Torrent provider."""

def __init__(self):
"""Initialize the class."""
super(BeyondHDProvider, self).__init__('Beyond-HD')

self.username = None
self.password = None

self.url = 'https://beyond-hd.me'
self.urls = {
'login': urljoin(self.url, 'login'),
'search': urljoin(self.url, 'torrents'),
}

# Proper Strings
self.proper_strings = ['PROPER', 'REPACK', 'REAL', 'RERIP']

# Miscellaneous Options

# Cache
self.cache = tv.Cache(self)

def search(self, search_strings, *args, **kwargs):
"""
Search a provider and parse the results.

:param search_strings: A dict with mode (key) and the search value (value)
:returns: A list of search results (structure)
"""
results = []
if not self.login():
return results

for mode in search_strings:
log.debug('Search mode: {0}', mode)

for search_string in search_strings[mode]:

search_params = {
'categories[]': 2,
'sorting': 'created_at',
'qty': '100',
'direction': 'desc',
'doSearch': 'Search'
}

if mode != 'RSS':
log.debug('Search string: {search}',
{'search': search_string})
search_params['search'] = search_string

if mode == 'season':
search_params['pack'] = 1

response = self.session.get(self.urls['search'], params=search_params)
if not response or not response.text:
log.debug('No data returned from provider')
continue

results += self.parse(response.text, mode)

return results

def parse(self, data, mode):
"""
Parse search results for items.

:param data: The raw response from a search
:param mode: The current mode used to search, e.g. RSS

:return: A list of items found
"""
# Units
units = ['B', 'KIB', 'MIB', 'GIB', 'TIB', 'PIB']

items = []

with BS4Parser(data, 'html5lib') as html:
torrent_table = html.find('table', class_='table-striped')
torrent_rows = torrent_table('tr') if torrent_table else []

# Continue only if one release is found
if len(torrent_rows) < 2:
log.debug('Data returned from provider does not contain any torrents')
return items

for result in torrent_rows[1:]:
cells = result('td')

try:
link = cells[1].find('a')
download_url = urljoin(self.url, cells[2].find('a')['href'])
title = link.get_text(strip=True)
if not all([title, download_url]):
continue

seeders = int(cells[6].find('span').get_text())
leechers = int(cells[7].find('span').get_text())

# Filter unseeded torrent
if seeders < self.minseed:
if mode != 'RSS':
log.debug("Discarding torrent because it doesn't meet the"
' minimum seeders: {0}. Seeders: {1}',
title, seeders)
continue

torrent_size = cells[5].find('span').get_text()
size = convert_size(torrent_size, units=units) or -1

pubdate_raw = cells[4].find('span').get_text()
pubdate = self.parse_pubdate(pubdate_raw, human_time=True)

item = {
'title': title,
'link': download_url,
'size': size,
'seeders': seeders,
'leechers': leechers,
'pubdate': pubdate,
}
if mode != 'RSS':
log.debug('Found result: {0} with {1} seeders and {2} leechers',
title, seeders, leechers)

items.append(item)
except (AttributeError, TypeError, KeyError, ValueError, IndexError):
log.exception('Failed parsing provider.')

return items

def login(self):
"""Login method used for logging in before doing search and torrent downloads."""
if any(dict_from_cookiejar(self.session.cookies).values()):
return True

if 'pass' in dict_from_cookiejar(self.session.cookies):
return True

login_html = self.session.get(self.urls['login'])
with BS4Parser(login_html.text, 'html5lib') as html:
token = html.find('input', attrs={'name': '_token'}).get('value')

login_params = {
'_token': token,
'username': self.username,
'password': self.password,
'remember': 'on',
}

response = self.session.post(self.urls['login'], data=login_params)
if not response or not response.text:
log.warning('Unable to connect to provider')
return False

if 'These credentials do not match our records.' in response.text:
log.warning('Invalid username or password. Check your settings')
return False

return True


provider = BeyondHDProvider()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file added themes/dark/assets/img/providers/beyond_hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added themes/light/assets/img/providers/beyond_hd.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.