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

Eztv #267

Closed
wants to merge 4 commits into from
Closed

Eztv #267

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
80 changes: 77 additions & 3 deletions nova3/engines/eztv.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,66 @@
#VERSION: 1.14
#VERSION: 1.15
# AUTHORS: nindogo
# CONTRIBUTORS: Diego de las Heras ([email protected])

from html.parser import HTMLParser

import secrets
import http.cookiejar
import urllib.request
import urllib.parse

from novaprinter import prettyPrinter
from helpers import retrieve_url

policy = http.cookiejar.DefaultCookiePolicy()
global_cookie_jar = http.cookiejar.CookieJar(policy)


def random_user_agent():

_USER_AGENT_TPL = '''Mozilla/5.0 (Windows NT 10.0; Win64; x64)\
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/%s \
Safari/537.36'''
_CHROME_VERSIONS = (
'90.0.4430.212',
'90.0.4430.24',
'90.0.4430.70',
'90.0.4430.72',
'90.0.4430.85',
'90.0.4430.93',
'91.0.4472.101',
'91.0.4472.106',
'91.0.4472.114',
'91.0.4472.124',
'91.0.4472.164',
'91.0.4472.19',
'91.0.4472.77',
'92.0.4515.107',
'92.0.4515.115',
'92.0.4515.131',
'92.0.4515.159',
'92.0.4515.43',
'93.0.4556.0',
'93.0.4577.15',
'93.0.4577.63',
'93.0.4577.82',
'94.0.4606.41',
'94.0.4606.54',
'94.0.4606.61',
'94.0.4606.71',
'94.0.4606.81',
'94.0.4606.85',
'95.0.4638.17',
'95.0.4638.50',
'95.0.4638.54',
'95.0.4638.69',
'95.0.4638.74',
'96.0.4664.18',
'96.0.4664.45',
'96.0.4664.55',
'96.0.4664.93',
'97.0.4692.20',
)
return _USER_AGENT_TPL % secrets.choice(_CHROME_VERSIONS)


class eztv(object):
Expand Down Expand Up @@ -59,9 +114,28 @@ def handle_endtag(self, tag):
prettyPrinter(self.current_item)
self.in_table_row = False

def retrieve_url(self, url, data=None):
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(global_cookie_jar))
opener.addheaders = [('User-Agent', random_user_agent())]
if not data:
req = urllib.request.Request(url)
else:
req = urllib.request.Request(url, data=data)

with opener.open(req) as response:
parsed = urllib.parse.urlparse(response.url)
self.url = parsed.scheme + "://" + parsed.hostname
return response.read().decode('utf-8')

def search(self, what, cat='all'):

_ = self.retrieve_url(self.url)

data = {'layout': 'def_wlinks'}
data = urllib.parse.urlencode(data).encode('utf-8')

query = self.url + '/search/' + what.replace('%20', '-')
eztv_html = retrieve_url(query)
eztv_html = self.retrieve_url(query, data)

eztv_parser = self.MyHtmlParser(self.url)
eztv_parser.feed(eztv_html)
Expand Down
2 changes: 1 addition & 1 deletion nova3/engines/versions.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
eztv: 1.14
eztv: 1.15
jackett: 4.0
limetorrents: 4.7
piratebay: 3.2
Expand Down