Skip to content

Commit

Permalink
Add gimmepeers torrent provider (#6635)
Browse files Browse the repository at this point in the history
* Create gimmepeers.py

* Update __init__.py

* Update __init__.py

* Add files via upload

* Add files via upload

* Update gimmepeers.py

* run isort

* Update gimmepeers.py

* Update gimmepeers.py

* make pep8 compliant for flake8 check

* Update gimmepeers.py

* pep8 fixes

* Update gimmepeers.py

* pep8 fixes

* pep8 fix import order

* revert isort

* revert isort

* Add files via upload

* pr fixes

* pr fix minseed

* fix logger

* remove logger since unused

* Update gimmepeers.py

* remove whitespace

* replace format with urljoin

* pr fixes + add pubdate

* pep8 whitespace fix

* pep8 whitespace fix

* fix size

* whitespace fix

* remove trailing whitespace

* Small changes

* Optimize icon

* Update gimmepeers.py

* Update CHANGELOG.md
  • Loading branch information
mystycs authored and medariox committed May 3, 2019
1 parent ad3ae4f commit ecbfe45
Show file tree
Hide file tree
Showing 7 changed files with 179 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#### New Features
- Added nCore torrent provider ([#6537](https://github.com/pymedusa/Medusa/pull/6537))
- Added Gimmepeers torrent provider (credits to @mystycs) ([#6635](https://github.com/pymedusa/Medusa/pull/6635))

#### 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 @@ -28,6 +28,7 @@
cinemaz,
danishbits,
elitetracker,
gimmepeers,
hdbits,
hdspace,
hdtorrents,
Expand Down Expand Up @@ -69,7 +70,7 @@
'abnormal', 'scenetime', 'nebulance', 'tvchaosuk', 'bitcannon', 'torrentz2', 'pretome', 'anizb',
'hdspace', 'nordicbits', 'danishbits', 'limetorrents', 'norbits', 'bithdtv', 'ncore',
'zooqle', 'animebytes', 'animetorrents', 'anidex', 'shanaproject', 'torrenting',
'yggtorrent', 'elitetracker', 'archetorrent', 'privatehd', 'cinemaz', 'avistaz', 'bjshare'
'yggtorrent', 'elitetracker', 'archetorrent', 'privatehd', 'cinemaz', 'avistaz', 'bjshare', 'gimmepeers'
]


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 @@ -14,6 +14,7 @@
bjshare,
cinemaz,
elitetracker,
gimmepeers,
hdspace,
hdtorrents,
hebits,
Expand Down Expand Up @@ -69,5 +70,5 @@
'torrentbytes', 'torrentleech', 'nebulance', 'tvchaosuk', 'xthor', 'zooqle', 'bitcannon', 'btn',
'hdbits', 'norbits', 'rarbg', 'torrentday', 'nyaa', 'rsstorrent', 'shazbat', 'hebits',
'torrentz2', 'animetorrents', 'anidex', 'shanaproject', 'torrenting', 'yggtorrent',
'elitetracker', 'privatehd', 'cinemaz', 'avistaz', 'bjshare', 'ncore'
'elitetracker', 'privatehd', 'cinemaz', 'avistaz', 'bjshare', 'ncore', 'gimmepeers'
]
174 changes: 174 additions & 0 deletions medusa/providers/torrent/html/gimmepeers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# coding=utf-8

"""Provider code for GimmePeers."""

from __future__ import unicode_literals

import logging
import re

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 GimmePeersProvider(TorrentProvider):
"""GimmePeers Torrent provider."""

def __init__(self):
"""Initialize the class."""
super(GimmePeersProvider, self).__init__('GimmePeers')

self.username = None
self.password = None

self.url = 'https://www.gimmepeers.com'
self.urls = {
'login': urljoin(self.url, 'takelogin.php'),
'search': urljoin(self.url, 'browse.php'),
}

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

self.cache = tv.Cache(self)

def search(self, search_strings, age=0, ep_obj=None, **kwargs):
"""
Search a provider and parse the results.
:param search_strings: A dict with mode (key) and the search value (value)
:param age: Not used
:param ep_obj: Not used
:returns: A list of search results (structure)
"""
results = []
if not self.login():
return results

search_params = {
'c20': 1,
'c21': 1,
'c25': 1,
'c24': 1,
'c23': 1,
'c22': 1,
'c1': 1,
}

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

for search_string in search_strings[mode]:

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

search_params['search'] = search_string

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
"""
items = []

with BS4Parser(data, 'html5lib') as html:
torrent_table = html.find('table', class_='browsetable')
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()
if not all([title, download_url]):
continue

seeders = int(cells[10].get_text().replace(',', ''))
leechers = int(cells[11].get_text().replace(',', ''))

# 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].get_text(' ')
size = convert_size(torrent_size) or -1

pubdate_raw = cells[6].get_text()
pubdate = self.parse_pubdate(pubdate_raw)

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

login_params = {
'username': self.username,
'password': self.password,
'ssl': 'yes',
}

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

if re.search('Username or password incorrect!', response.text):
log.debug('Invalid username or password. Check your settings')
return False

return True


provider = GimmePeersProvider()
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/dark/assets/img/providers/gimmepeers.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/gimmepeers.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ecbfe45

Please sign in to comment.