<commit_before>from tools.page import *
from tools.stream import extract_stream
from tools.url import UrlMgr
from tools.helper import *
from lxml import html
from lxml import etree
import re
import sys
import json

class Kinox(Page):
    def __init__(self):
        self.name = 'kinox.to'
        self.url = 'http://kinox.to'
        Page.__init__(self)

    def getAllPages(self):
        allPages = []
        pageTypeToTag = {
            'Series': ['serie'],
            'Documentations': ['documentation'],
        }
        pageTypeToParam = {
            'Series':'series',
            'Documentations':'documentations',
        }
        for pageType in ('Series', 'Documentations'):
            url = UrlMgr({'url':'http://kinox.to/'+pageType+'.html', 'log':log})
            maxItems = int(textextract(url.data, 'span class="Count">', '</span>'))
            for i in range(0, maxItems, 25):
                link = ['http://kinox.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart='+str(i),
                    '&iDisplayLength=25',
                    '&iSortingCols=1',
                    '&iSortCol_0=2',
                    '&sSortDir_0=asc',
                    #'&bSortable_0=true',
                    #'&bSortable_1=true',
                    #'&bSortable_2=true',
                    #'&bSortable_3=false',
                    #'&bSortable_4=false',
                    #'&bSortable_5=false',
                    #'&bSortable_6=true',
                    '&additional=%7B%22fType%22%3A%22'+pageTypeToParam[pageType]+'%22%2C%22fLetter%22%3A%22%22%7D']
                link = ''.join(link)
                url = UrlMgr({'url':link, 'log':log})
                data = json.loads(url.data)
                for item in data['aaData']:
                    lang = item[0] # 1=ger, 2=eng, 15=ger/eng 'http://kinox.to//gr/sys/lng/'+lang+'.png'
                    cat = item[1]
                    streamData = item[2]
                    unk1 = item[3]
                    unk2 = item[4]
                    unk3 = item[5]
                    unk4 = item[6]
                    streamLink = 'http://kinox.to/'+textextract(streamData, 'href="', '"')
                    media = self.extract(streamLink)
                    allPages.append(media)
        return allPages

    def checkPage(self, url, part):
        if not url.data.find(part) > 0:
            url.clear_connection()
            url.setCacheWriteOnly()
            if not url.data.find(part) > 0:
                self.log.error('download problem?')
                import time
                self.log.error("sleeping 10 seconds")
                time.sleep(10)
                url.clear_connection()
                url.setCacheWriteOnly()
                if not url.data.find(part) > 0:
                    self.log.error('download problem!')
                    self.log.error(url.url)
                    self.log.error(url.data)
        return url

    def extract(self, link):
        url = self.checkPage(UrlMgr({'url': link, 'log': self.log}), 'Stream online')
        origName = textextract(url.data, '<title>', ' Stream online anschauen und downloaden auf Kino</title>')
        log.info("Extract: "+origName)
        name = origName
        if not origName:<commit_msg>dont start with pagedownload at kinox cause of the ipblock<commit_after>from tools.page import *
from tools.stream import extract_stream
from tools.url import UrlMgr
from tools.helper import *
from lxml import html
from lxml import etree
import re
import sys
import json

class Kinox(Page):
    def __init__(self):
        self.name = 'kinox.to'
        self.url = 'http://kinox.to'
        Page.__init__(self)

    def getAllPages(self):
        allPages = []
        pageTypeToTag = {
            'Series': ['serie'],
            'Documentations': ['documentation'],
        }
        pageTypeToParam = {
            'Series':'series',
            'Documentations':'documentations',
        }
        for pageType in ('Series', 'Documentations'):
            url = self.checkPage(UrlMgr({'url':'http://kinox.to/'+pageType+'.html', 'log':log}), 'span class="Count">')
            maxItems = int(textextract(url.data, 'span class="Count">', '</span>'))
            for i in range(0, maxItems, 25):
                link = ['http://kinox.to/aGET/List/?sEcho=2&iColumns=7&sColumns=&iDisplayStart='+str(i),
                    '&iDisplayLength=25',
                    '&iSortingCols=1',
                    '&iSortCol_0=2',
                    '&sSortDir_0=asc',
                    #'&bSortable_0=true',
                    #'&bSortable_1=true',
                    #'&bSortable_2=true',
                    #'&bSortable_3=false',
                    #'&bSortable_4=false',
                    #'&bSortable_5=false',
                    #'&bSortable_6=true',
                    '&additional=%7B%22fType%22%3A%22'+pageTypeToParam[pageType]+'%22%2C%22fLetter%22%3A%22%22%7D']
                link = ''.join(link)
                url = UrlMgr({'url':link, 'log':log})
                data = json.loads(url.data)
                for item in data['aaData']:
                    lang = item[0] # 1=ger, 2=eng, 15=ger/eng 'http://kinox.to//gr/sys/lng/'+lang+'.png'
                    cat = item[1]
                    streamData = item[2]
                    unk1 = item[3]
                    unk2 = item[4]
                    unk3 = item[5]
                    unk4 = item[6]
                    streamLink = 'http://kinox.to/'+textextract(streamData, 'href="', '"')
                    #media = self.extract(streamLink)
                    #allPages.append(media)
        return allPages

    def checkPage(self, url, part):
        if not url.data.find(part) > 0:
            url.clear_connection()
            url.setCacheWriteOnly()
            if not url.data.find(part) > 0:
                self.log.error('download problem?')
                import time
                self.log.error("sleeping 10 seconds")
                time.sleep(10)
                url.clear_connection()
                url.setCacheWriteOnly()
                if not url.data.find(part) > 0:
                    self.log.error('download problem!')
                    self.log.error(url.url)
                    self.log.error(url.data)
        return url

    def extract(self, link):
        url = self.checkPage(UrlMgr({'url': link, 'log': self.log}), 'Stream online')
        origName = textextract(url.data, '<title>', ' Stream online anschauen und downloaden auf Kino</title>')
        log.info("Extract: "+origName)
        name = origName
        if not origName:
{'fraction_non_alphanumeric': 0.13797276853252646, 'fraction_numerical': 0.018456883509833585, 'mean_word_length': 1.6244541484716157, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4763309', 'n_tokens_mistral': 2083, 'n_tokens_neox': 1938, 'n_words': 368}