Example #1
0
    def updateSession(self, url, delay=10):
        scraper = CloudScraper.create_scraper(delay=delay)
        scraper.headers.update({'User-Agent': user_agent})
        self.cookies = scraper.get(url).cookies.get_dict()
        if not helper.has_file_path('phimbathu.bin'):
            helper.write_file('phimbathu.bin', '')

        with open(helper.get_file_path('phimbathu.bin'), 'wb+') as f:
            pickle.dump(self.cookies, f)
Example #2
0
 def updateSession(self, url, delay=10):
     try:
         scraper = CloudScraper.create_scraper(delay=delay)
         scraper.headers.update({'User-Agent': user_agent})
         self.cookies = scraper.get(url).cookies.get_dict()
         with open(helper.get_file_path('phimmedia.bin'), 'wb') as f:
             pickle.dump(self.cookies, f)
     except:
         pass
Example #3
0
def request(url,
            close=True,
            redirect=True,
            error=False,
            verify=True,
            proxy=None,
            post=None,
            headers=None,
            mobile=False,
            XHR=False,
            limit=None,
            referer=None,
            cookie=None,
            compression=True,
            output='',
            timeout='20'):
    try:
        if not url:
            return

        handlers = []

        if proxy is not None:
            handlers += [
                urllib.request.ProxyHandler({'http': '%s' % (proxy)}),
                urllib.request.HTTPHandler
            ]
            opener = urllib.request.build_opener(*handlers)
            opener = urllib.request.install_opener(opener)

        if output == 'cookie' or output == 'extended' or not close:
            cookies = cookielib.LWPCookieJar()
            handlers += [
                urllib.request.HTTPHandler(),
                urllib.request.HTTPSHandler(),
                urllib.request.HTTPCookieProcessor(cookies)
            ]
            opener = urllib.request.build_opener(*handlers)
            opener = urllib.request.install_opener(opener)

        try:
            import platform
            node = platform.node().lower()
        except BaseException:
            node = ''

        if verify == False and sys.version_info >= (2, 7, 12):
            try:
                import ssl
                ssl_context = ssl._create_unverified_context()
                handlers += [urllib.request.HTTPSHandler(context=ssl_context)]
                opener = urllib.request.build_opener(*handlers)
                opener = urllib.request.install_opener(opener)
            except BaseException:
                pass

        if verify and ((2, 7, 8) < sys.version_info <
                       (2, 7, 12) or platform.uname()[1] == 'XboxOne'):
            try:
                import ssl
                ssl_context = ssl.create_default_context()
                ssl_context.check_hostname = False
                ssl_context.verify_mode = ssl.CERT_NONE
                handlers += [urllib.request.HTTPSHandler(context=ssl_context)]
                opener = urllib.request.build_opener(*handlers)
                opener = urllib.request.install_opener(opener)
            except BaseException:
                pass

        if url.startswith('//'):
            url = 'http:' + url

        _headers = {}

        try:
            _headers.update(headers)
        except BaseException:
            pass

        if 'User-Agent' in _headers:
            pass
        elif mobile:
            _headers['User-Agent'] = cache.get(randommobileagent, 1)
        else:
            _headers['User-Agent'] = cache.get(randomagent, 1)

        if 'Referer' in _headers:
            pass
        elif referer is not None:
            _headers['Referer'] = referer
        if 'Accept-Language' not in _headers:
            _headers['Accept-Language'] = 'en-US'
        if 'X-Requested-With' in _headers:
            pass
        elif XHR:
            _headers['X-Requested-With'] = 'XMLHttpRequest'
        if 'Cookie' in _headers:
            pass
        elif cookie is not None:
            _headers['Cookie'] = cookie
        if 'Accept-Encoding' in _headers:
            pass
        elif compression and limit is None:
            _headers['Accept-Encoding'] = 'gzip'

        if not redirect:

            class NoRedirectHandler(urllib.request.HTTPRedirectHandler):
                def http_error_302(self, req, fp, code, msg, headers):
                    infourl = addinfourl(fp, headers, req.get_full_url())
                    infourl.status = code
                    infourl.code = code
                    return infourl

                http_error_300 = http_error_302
                http_error_301 = http_error_302
                http_error_303 = http_error_302
                http_error_307 = http_error_302

            opener = urllib.request.build_opener(NoRedirectHandler())
            urllib.request.install_opener(opener)

            try:
                del _headers['Referer']
            except BaseException:
                pass

        url = utils.byteify(url)
        request = urllib.request.Request(url)

        if post is not None:
            if isinstance(post, dict):
                post = utils.byteify(post)
                post = urlencode(post)
            if len(post) > 0:
                request = urllib.request.Request(url, data=post)
            else:
                request.get_method = lambda: 'POST'
                request.has_header = lambda header_name: (
                    header_name == 'Content-type' or urllib.request.Request.
                    has_header(request, header_name))

        if limit == '0':
            request.get_method = lambda: 'HEAD'

        _add_request_header(request, _headers)
        response = urllib.request.urlopen(request, timeout=int(timeout))

        try:
            response = urllib.request.urlopen(request, timeout=int(timeout))
        except urllib.error.HTTPError as response:
            if response.code == 503:
                cf_result = response.read()
                try:
                    encoding = response.info().getheader('Content-Encoding')
                except BaseException:
                    encoding = None
                if encoding == 'gzip':
                    cf_result = gzip.GzipFile(
                        fileobj=BytesIO(cf_result)).read()

                if 'cf-browser-verification' in cf_result:
                    from cloudscraper2 import CloudScraper as cfscrape
                    _cf_lim = 0
                    while 'cf-browser-verification' in cf_result and _cf_lim <= 1:
                        _cf_lim += 1
                        netloc = '%s://%s/' % (urlparse(url).scheme,
                                               urlparse(url).netloc)
                        ua = _headers['User-Agent']

                        try:
                            cf = cache.get(cfscrape.get_cookie_string, 1,
                                           netloc, ua)[0]
                        except BaseException:
                            try:
                                cf = cfscrape.get_cookie_string(url, ua)[0]
                            except BaseException:
                                cf = None
                        finally:
                            _headers['Cookie'] = cf

                        request = urllib.request.Request(url, data=post)
                        _add_request_header(request, _headers)

                        try:
                            response = urllib.request.urlopen(
                                request, timeout=int(timeout))
                            cf_result = 'Success'
                        except urllib.error.HTTPError as response:
                            cache.remove(cfscrape.get_cookie_string, netloc,
                                         ua)
                            cf_result = response.read()
                else:
                    xbmc.log(
                        'Request-Error (%s): %s' % (str(response.code), url),
                        xbmc.LOGDEBUG)
                    if not error:
                        return
            else:
                xbmc.log('Request-Error (%s): %s' % (str(response.code), url),
                         xbmc.LOGDEBUG)
                if not error:
                    return

        if output == 'cookie':
            try:
                result = '; '.join(
                    ['%s=%s' % (i.name, i.value) for i in cookies])
            except BaseException:
                pass
            try:
                result = cf
            except BaseException:
                pass
            if close:
                response.close()
            return result

        elif output == 'geturl':
            result = response.geturl()
            if close:
                response.close()
            return result

        elif output == 'headers':
            result = response.headers
            if close:
                response.close()
            return result

        elif output == 'location':
            result = response.headers
            if close:
                response.close()
            return result['Location']

        elif output == 'chunk':
            try:
                content = int(response.headers['Content-Length'])
            except BaseException:
                content = (2049 * 1024)
            if content < (2048 * 1024):
                return
            result = response.read(16 * 1024)
            if close:
                response.close()
            return result

        elif output == 'file_size':
            try:
                content = int(response.headers['Content-Length'])
            except BaseException:
                content = '0'
            response.close()
            return content

        if limit == '0':
            result = response.read(1 * 1024)
        elif limit is not None:
            result = response.read(int(limit) * 1024)
        else:
            result = response.read(5242880)

        try:
            encoding = response.headers['Content-Encoding']
        except BaseException:
            encoding = None
        if encoding == 'gzip':
            result = gzip.GzipFile(fileobj=BytesIO(result)).read()

        if b'sucuri_cloudproxy_js' in result:
            su = sucuri().get(result)

            _headers['Cookie'] = su

            request = urllib.request.Request(url, data=post)
            _add_request_header(request, _headers)

            response = urllib.request.urlopen(request, timeout=int(timeout))

            if limit == '0':
                result = response.read(224 * 1024)
            elif limit is not None:
                result = response.read(int(limit) * 1024)
            else:
                result = response.read(5242880)

            try:
                encoding = response.info().getheader('Content-Encoding')
            except BaseException:
                encoding = None
            if encoding == 'gzip':
                result = gzip.GzipFile(fileobj=BytesIO(result)).read()

        if six.PY3 and isinstance(result, bytes):
            result = result.decode('utf-8')

        if output == 'extended':
            try:
                response_headers = dict([(item[0].title(), item[1])
                                         for item in response.info().items()])
            except BaseException:
                response_headers = response.headers
            response_code = str(response.code)
            try:
                cookie = '; '.join(
                    ['%s=%s' % (i.name, i.value) for i in cookies])
            except BaseException:
                pass
            try:
                cookie = cf
            except BaseException:
                pass
            if close:
                response.close()
            return (result, response_code, response_headers, _headers, cookie)
        else:
            if close:
                response.close()
            return result
    except Exception as e:
        xbmc.log('Request-Error: (%s) => %s' % (str(e), url), xbmc.LOGDEBUG)
        return
Example #4
0
import requests
import re
import xbmcgui
import xbmc
import xbmcaddon
dialog = xbmcgui.Dialog()
from bs4 import BeautifulSoup
Headers = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
}
from cloudscraper2 import CloudScraper
CF = CloudScraper.create_scraper()

class Scraper:
    def __init__(self):
        self.Base = 'https://eztv.io/'
        self.Search = 'search/%s'
        self.links = []
    def Index(self, type, term, year, imdb, torrents):
        try:
            year = year.strip()
            MovieTitle = term
            if type == 'TV':
                term = term.replace(' ', '-')
                try:
                    found = 0
                    Term = term.replace(' ', '+').replace(':', '')
                    link = CF.get(self.Base + self.Search % Term,
                                  headers=Headers).content
Example #5
0
import re, requests
from bs4 import BeautifulSoup
import xbmcgui
import xbmc
import resolveurl
import xbmcaddon
from cloudscraper2 import CloudScraper
CF = CloudScraper.create_scraper()
dialog = xbmcgui.Dialog()
Headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36' }
GoodFiles = ['.mp4', '.mkv']


class Scraper:
	def __init__(self):
		self.Base = 'https://api.ocloud.stream/cmovieshd//movie/search/%s?link_web=https://www1.cmovieshd.bz/'
		self.Search = ('%s')
		self.links = []
		self.servermain = 'https://www2.cmovieshd.bz/'
	def Index(self,type,term,year,imdb,torrents):

		if type == 'MOVIE':
			try:
				filmname = ('%s %s' % (term.title(), year))
				term = term.replace(' ','-')
				link = requests.get(self.Base % term, headers=Headers).content
				soup = BeautifulSoup(link, 'html5lib')
				for links in content:
					if term.lower() in links['href']:
						Movietitle = links.img['alt']
						followlink = links['href'] + '/watching.html'
import requests
import re
import xbmcgui
import xbmc
import xbmcaddon
dialog = xbmcgui.Dialog()
Headers = {
    'User-Agent':
    'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'
}
from cloudscraper2 import CloudScraper
CF = CloudScraper.create_scraper()

class Scraper:
    def __init__(self):
        self.Base = (
            'https://yts.unblockit.me/api/v2/list_movies.json?query_term=%s')
        self.Search = ('')
        self.links = []
    def Index(self, type, term, year, imdb, torrents):
        year = year.strip()
        if type == 'MOVIE':
            try:
                found = 0
                Checker = term
                Term = term.replace(' ', '+').replace(':', '')
                link = CF.get(self.Base % Term, headers=Headers).json()
                for i in link['data']['movies']:
                    title = i['title_long']
                    movieyear = i['year']
Example #7
0
import requests
Example #8
0
def Search_bb(url):
    from cloudscraper2 import CloudScraper as cfscrape
    scraper = cfscrape.create_scraper()
    if 'new' == url:
        keyboard = xbmc.Keyboard()
        keyboard.setHeading(control.lang(32002).encode('utf-8'))
        keyboard.doModal()
        if keyboard.isConfirmed():
            _query = keyboard.getText()
            query = _query.encode('utf-8')
            try:
                query = quote_plus(query)
                referer_link = 'http://search.proxybb.com?s={0}'.format(query)

                url = 'http://search.proxybb.com/Home/GetPost?phrase={0}&pindex=1&content=true&type=Simple&rad=0.{1}'
                url = url.format(query, random.randint(33333333333333333, 99999999999999999))
                #########save in Database#########
                term = unquote_plus(query).decode('utf-8')
                dbcon = database.connect(control.searchFile)
                dbcur = dbcon.cursor()
                dbcur.execute("DELETE FROM Search WHERE search = ?", (term,))
                dbcur.execute("INSERT INTO Search VALUES (?,?)", (url, term))
                dbcon.commit()
                dbcur.close()

                #########search in website#########
                headers = {'Referer': referer_link,
                           'X-Requested-With': 'XMLHttpRequest'}
                first = scraper.get(referer_link, headers=headers).text
                xbmc.sleep(10)
                html = scraper.get(url, headers=headers).text
                posts = json.loads(html)['results']
                posts = [(i['post_name'], i['post_title'], i['post_content'], i['domain']) for i in posts if i]
                for movieUrl, title, infos, domain in posts:
                    base = BASE_URL if 'old' not in domain else OLD_URL
                    movieUrl = urlparse.urljoin(base, movieUrl) if not movieUrl.startswith('http') else movieUrl
                    title = title.encode('utf-8')
                    infos = infos.replace('\\', '')
                    try:
                        img = client.parseDOM(infos, 'img', ret='src')[0]
                        img = img.replace('.ru', '.to')
                    except:
                        img = ICON

                    try:
                        fan = client.parseDOM(infos, 'img', ret='src')[1]
                    except:
                        fan = FANART

                    try:
                        desc = re.search(r'Plot:(.+?)</p><p> <img', infos, re.DOTALL).group(0)
                    except:
                        desc = 'N/A'

                    desc = Sinopsis(desc)
                    name = '[B][COLORgold]{0}[/COLOR][/B]'.format(title.encode('utf-8'))

                    mode = 'GetPack' if re.search(r'\s+S\d+\s+', name) else 'GetLinks'
                    addon.add_directory(
                        {'mode': mode, 'url': movieUrl, 'img': img, 'plot': desc},
                        {'title': name, 'plot': desc},
                        [(control.lang(32007).encode('utf-8'),
                          'RunPlugin(plugin://plugin.video.rlshub/?mode=settings)',),
                         (control.lang(32008).encode('utf-8'),
                          'RunPlugin(plugin://plugin.video.rlshub/?mode=ClearCache)',),
                         (control.lang(32009).encode('utf-8'),
                          'RunPlugin(plugin://plugin.video.rlshub/?mode=setviews)',)],
                        img=img, fanart=fan)

                # if 'olderEntries' in ref_html:
                pindex = int(re.search('pindex=(\d+)&', url).group(1)) + 1
                np_url = re.sub(r'&pindex=\d+&', '&pindex={0}&'.format(pindex), url)
                rand = random.randint(33333333333333333, 99999999999999999)
                np_url = re.sub(r'&rand=0\.\d+$', '&rand={}'.format(rand), np_url)
                addon.add_directory(
                    {'mode': 'search_bb', 'url': np_url + '|Referer={0}|nextpage'.format(referer_link)},
                    {'title': control.lang(32010).encode('utf-8')},
                    img=IconPath + 'next_page.png', fanart=FANART)


            except BaseException:
                control.infoDialog(control.lang(32022).encode('utf-8'), NAME, ICON, 5000)

    elif '|nextpage' in url:
        url, referer_link, np = url.split('|')
        referer_link = referer_link.split('=', 1)[1]
        headers = {'Referer': referer_link,
                   'X-Requested-With': 'XMLHttpRequest'}
        first = scraper.get(referer_link, headers=headers).text
        xbmc.sleep(10)
        html = scraper.get(url, headers=headers).content
        # xbmc.log('NEXT HTMLLLLL: {}'.format(html))
        posts = json.loads(html)['results']
        posts = [(i['post_name'], i['post_title'], i['post_content'], i['domain']) for i in posts if i]
        for movieUrl, title, infos, domain in posts:
            base = BASE_URL if 'old' not in domain else OLD_URL
            movieUrl = urlparse.urljoin(base, movieUrl) if not movieUrl.startswith('http') else movieUrl
            title = title.encode('utf-8')
            infos = infos.replace('\\', '')
            try:
                img = client.parseDOM(infos, 'img', ret='src')[0]
                img = img.replace('.ru', '.to')
            except:
                img = ICON

            try:
                fan = client.parseDOM(infos, 'img', ret='src')[1]
            except:
                fan = FANART

            try:
                desc = re.search(r'Plot:(.+?)</p><p> <img', infos, re.DOTALL).group(0)
            except:
                desc = 'N/A'

            desc = Sinopsis(desc)
            name = '[B][COLORgold]{0}[/COLOR][/B]'.format(title.encode('utf-8'))
            mode = 'GetPack' if re.search(r'\s+S\d+\s+', name) else 'GetLinks'
            addon.add_directory(
                {'mode': mode, 'url': movieUrl, 'img': img, 'plot': desc},
                {'title': name, 'plot': desc},
                [(control.lang(32007).encode('utf-8'),
                  'RunPlugin(plugin://plugin.video.rlshub/?mode=settings)',),
                 (control.lang(32008).encode('utf-8'),
                  'RunPlugin(plugin://plugin.video.rlshub/?mode=ClearCache)',),
                 (control.lang(32009).encode('utf-8'),
                  'RunPlugin(plugin://plugin.video.rlshub/?mode=setviews)',)],
                img=img, fanart=fan)

        # if 'olderEntries' in ref_html:
        pindex = int(re.search('pindex=(\d+)&', url).groups()[0]) + 1
        np_url = re.sub('&pindex=\d+&', '&pindex={0}&'.format(pindex), url)
        rand = random.randint(33333333333333333, 99999999999999999)
        np_url = re.sub(r'&rand=0\.\d+$', '&rand={}'.format(rand), np_url)
        addon.add_directory(
            {'mode': 'search_bb', 'url': np_url + '|Referer={0}|nextpage'.format(referer_link)},
            {'title': control.lang(32010).encode('utf-8')},
            img=IconPath + 'next_page.png', fanart=FANART)

    else:
        try:
            from cloudscraper2 import CloudScraper as cfscrape
            scraper = cfscrape.create_scraper()
            url = quote_plus(url)
            referer_link = 'http://search.proxybb.com?s={0}'.format(url)
            headers = {'Referer': referer_link,
                       'X-Requested-With': 'XMLHttpRequest'}
            # first = scraper.get('http://rlsbb.ru', headers=headers).text
            xbmc.sleep(10)
            s_url = 'http://search.proxybb.com/Home/GetPost?phrase={0}&pindex=1&content=true&type=Simple&rad=0.{1}'
            s_url = s_url.format(url, random.randint(33333333333333333, 99999999999999999))
            html = scraper.get(s_url, headers=headers).text
            posts = json.loads(html)['results']
            posts = [(i['post_name'], i['post_title'], i['post_content'], i['domain']) for i in posts if i]
            for movieUrl, title, infos, domain in posts:
                base = BASE_URL if 'old' not in domain else OLD_URL
                movieUrl = urlparse.urljoin(base, movieUrl) if not movieUrl.startswith('http') else movieUrl
                title = title.encode('utf-8')
                infos = infos.replace('\\', '')
                try:
                    img = client.parseDOM(infos, 'img', ret='src')[0]
                    img = img.replace('.ru', '.to')
                except:
                    img = ICON

                try:
                    fan = client.parseDOM(infos, 'img', ret='src')[1]
                except:
                    fan = FANART

                try:
                    desc = re.search(r'Plot:(.+?)</p><p> <img', infos, re.DOTALL).group(0)
                except:
                    desc = 'N/A'

                desc = Sinopsis(desc)
                name = '[B][COLORgold]{0}[/COLOR][/B]'.format(title.encode('utf-8'))

                mode = 'GetPack' if re.search(r'\s+S\d+\s+', name) else 'GetLinks'
                addon.add_directory(
                    {'mode': mode, 'url': movieUrl, 'img': img, 'plot': desc},
                    {'title': name, 'plot': desc},
                    [(control.lang(32007).encode('utf-8'),
                      'RunPlugin(plugin://plugin.video.rlshub/?mode=settings)',),
                     (control.lang(32008).encode('utf-8'),
                      'RunPlugin(plugin://plugin.video.rlshub/?mode=ClearCache)',),
                     (control.lang(32009).encode('utf-8'),
                      'RunPlugin(plugin://plugin.video.rlshub/?mode=setviews)',)],
                    img=img, fanart=fan)

            pindex = int(re.search('pindex=(\d+)&', s_url).groups()[0]) + 1
            np_url = re.sub('&pindex=\d+&', '&pindex={0}&'.format(pindex), s_url)
            rand = random.randint(33333333333333333, 99999999999999999)
            np_url = re.sub(r'&rand=0\.\d+$', '&rand={}'.format(rand), np_url)
            addon.add_directory(
                {'mode': 'search_bb', 'url': np_url + '|Referer={0}|nextpage'.format(referer_link)},
                {'title': control.lang(32010).encode('utf-8')},
                img=IconPath + 'next_page.png', fanart=FANART)

        except BaseException:
            control.infoDialog(control.lang(32022).encode('utf-8'), NAME, ICON, 5000)

    control.content(int(sys.argv[1]), 'videos')
    control.directory(int(sys.argv[1]))
    view.setView('videos', {'skin.estuary': 55, 'skin.confluence': 500})
import requests
import re
import xbmc
import xbmcgui
from cloudscraper2 import CloudScraper
from bs4 import BeautifulSoup
dialog = xbmcgui.Dialog()
CF = CloudScraper.create_scraper()
ua = {
    "User-Agent":
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
}

class Scraper:
    def __init__(self):
        self.Base = 'https://www.magnetdl.com/'
        self.Search = ('')
        self.links = []
    def Index(self, type, term, year, imdb, torrents):
        try:
            if type == 'TV':
                MovieName = term
                term = term.replace(' ', '-')
                t1 = term[0]
                fulllink = (self.Base + '%s/%s/se/desc/' % (t1, term)).lower()
                link = CF.get(fulllink, headers=ua).content
                soup = BeautifulSoup(link, 'html.parser')
                data = soup.find('table', class_={'download'})
                for i in data.select("a[href*=magnet]"):
                    link = i['href']
Example #10
0
def cloudflare_mode(url):
    from cloudscraper2 import CloudScraper as cfscrape
    scraper = cfscrape.create_scraper()
    result = scraper.get(url).text
    # xbmc.log('RESULTTTTT: %s' % result)
    return result
import requests
import re
import xbmc
import xbmcgui
import time
from random import randint
dialog = xbmcgui.Dialog()
from cloudscraper2 import CloudScraper
CF = CloudScraper.create_scraper()
ua = {
    "User-Agent":
    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36",
    "Referer": "https://www.limetorrents.info/"
}

class Scraper:
    def __init__(self):
        self.Base = 'https://www.limetorrents.info/'
        self.Search = ('search/movies/%s/seeds/1/')
        self.SearchTv = ('search/tv/%s/seeds/1/')
        self.links = []
    def Index(self, type, term, year, imdb, torrents):
        try:
            if type == 'TV':
                MovieName = term
                term = term.replace(' ', '-')
                link = CF.get(self.Base + self.SearchTv % term,
                              headers=ua).content
                match = re.findall(
                    'Torrent Name</span>(.*?)<div id="rightbar">',