Skip to content
This repository has been archived by the owner on Feb 16, 2020. It is now read-only.

Commit

Permalink
Switch to requests and certifi for http reqs
Browse files Browse the repository at this point in the history
  • Loading branch information
piplongrun committed Feb 17, 2018
1 parent e34653b commit 8d82109
Show file tree
Hide file tree
Showing 109 changed files with 35,799 additions and 37 deletions.
43 changes: 21 additions & 22 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
VERSION = '2.11'
import certifi
import requests

VERSION = '3.0'
API_URL = 'https://api.tadata.me/imdb2ta/v2/?imdb_id=%s'
TAC_URL = 'https://traileraddict.cache.tadata.me/%s'

TYPE_ORDER = ['trailer', 'feature_trailer', 'theatrical_trailer', 'behind_the_scenes', 'interview', 'deleted_scene']
TYPE_MAP = {
'trailer': TrailerObject,
'feature_trailer': TrailerObject,
'theatrical_trailer': TrailerObject,
'behind_the_scenes': BehindTheScenesObject,
'interview': InterviewObject,
'deleted_scene': DeletedSceneObject
"trailer": TrailerObject,
"feature_trailer": TrailerObject,
"theatrical_trailer": TrailerObject,
"behind_the_scenes": BehindTheScenesObject,
"interview": InterviewObject,
"deleted_scene": DeletedSceneObject
}

HTTP_HEADERS = {
"User-Agent": "Trailer Addict/%s (%s %s; Plex Media Server %s)" % (VERSION, Platform.OS, Platform.OSVersion, Platform.ServerVersion)
}

####################################################################################################
def Start():

HTTP.CacheTime = CACHE_1WEEK
HTTP.Headers['User-Agent'] = 'Trailer Addict/%s (%s %s; Plex Media Server %s)' % (VERSION, Platform.OS, Platform.OSVersion, Platform.ServerVersion)
pass

####################################################################################################
class TrailerAddictAgent(Agent.Movies):
Expand Down Expand Up @@ -57,24 +63,17 @@ def search(self, results, media, lang):

def update(self, metadata, media, lang):

try:
json_obj = JSON.ObjectFromURL(API_URL % (metadata.id))
except:
Log("*** Failed retrieving data from %s ***" % (API_URL % (metadata.id)))
return None
r = requests.get(API_URL % (metadata.id), headers=HTTP_HEADERS, verify=certifi.where())

if 'error' in json_obj:
Log("*** An error occurred: %s ***" % (json_obj['error']))
if 'error' in r.json():
Log("*** An error occurred: %s ***" % (r.json()['error']))
return None

poster = json_obj['image'] if 'image' in json_obj else None
poster = r.json()['image'] if 'image' in r.json() else None
extras = []

try:
html = HTML.ElementFromURL(TAC_URL % (json_obj['url'].split('/')[-1]), sleep=5.0)
except:
Log("*** HTTP GET request failed; plugin version %s ***" % (VERSION))
return None
r = requests.get(TAC_URL % (r.json()['url'].split('/')[-1]), headers=HTTP_HEADERS, verify=certifi.where())
html = HTML.ElementFromString(r.text)

for video in html.xpath('//a[@class="m_title"]'):

Expand Down
3 changes: 3 additions & 0 deletions Contents/Libraries/Shared/certifi/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .core import where, old_where

__version__ = "2018.01.18"
2 changes: 2 additions & 0 deletions Contents/Libraries/Shared/certifi/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from certifi import where
print(where())
4,433 changes: 4,433 additions & 0 deletions Contents/Libraries/Shared/certifi/cacert.pem

Large diffs are not rendered by default.

37 changes: 37 additions & 0 deletions Contents/Libraries/Shared/certifi/core.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
certifi.py
~~~~~~~~~~
This module returns the installation location of cacert.pem.
"""
import os
import warnings


class DeprecatedBundleWarning(DeprecationWarning):
"""
The weak security bundle is being deprecated. Please bother your service
provider to get them to stop using cross-signed roots.
"""


def where():
f = os.path.dirname(__file__)

return os.path.join(f, 'cacert.pem')


def old_where():
warnings.warn(
"The weak security bundle has been removed. certifi.old_where() is now an alias "
"of certifi.where(). Please update your code to use certifi.where() instead. "
"certifi.old_where() will be removed in 2018.",
DeprecatedBundleWarning
)
return where()

if __name__ == '__main__':
print(where())
39 changes: 39 additions & 0 deletions Contents/Libraries/Shared/chardet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
######################## BEGIN LICENSE BLOCK ########################
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library 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
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################


from .compat import PY2, PY3
from .universaldetector import UniversalDetector
from .version import __version__, VERSION


def detect(byte_str):
"""
Detect the encoding of the given byte string.
:param byte_str: The byte sequence to examine.
:type byte_str: ``bytes`` or ``bytearray``
"""
if not isinstance(byte_str, bytearray):
if not isinstance(byte_str, bytes):
raise TypeError('Expected object of type bytes or bytearray, got: '
'{0}'.format(type(byte_str)))
else:
byte_str = bytearray(byte_str)
detector = UniversalDetector()
detector.feed(byte_str)
return detector.close()
Loading

0 comments on commit 8d82109

Please sign in to comment.