Пример #1
0
    def __init__(self, tableservice: TableService, **kwargs):
        """ constructor """

        self._tableservice = tableservice
        self._existsinstorage = None
        self._tablename = self.__class__._tablename
        self._dateformat = self.__class__._dateformat
        self._datetimeformat = self.__class__._datetimeformat
        """ parse **kwargs into instance var """
        self._PartitionKey = kwargs.get('PartitionKey', '')
        self._RowKey = kwargs.get('RowKey', '')

        for key, default in vars(self.__class__).items():
            if not key.startswith('_') and key != '':
                if key in kwargs:

                    value = kwargs.get(key)
                    to_type = type(default)

                    if to_type is StorageTableCollection:
                        setattr(self, key, value)

                    elif to_type is datetime.datetime:
                        setattr(
                            self, key,
                            safe_cast(value, to_type, default,
                                      self._datetimeformat))

                    elif to_type is datetime.date:
                        setattr(
                            self, key,
                            safe_cast(value, to_type, default,
                                      self._dateformat))

                    else:
                        setattr(self, key, safe_cast(value, to_type, default))

                else:
                    setattr(self, key, default)
        """ set primary keys from data"""
        if self._PartitionKey == '':
            self.__setPartitionKey__()

        if self._RowKey == '':
            self.__setRowKey__()
        """ init Storage Table Collections in Instance """
        self.__setcollections__()
        pass
Пример #2
0
 def getgenrefromid(self, id):
     """ has to be overwritten """
     for genre in self._collection:
         if genre['Genre_Id'] == safe_cast(id, int, 0):
             return genre['Genre']
             break
     return 'Sonstiges'
Пример #3
0
def update_torrents(startdate:date):
    """
        rufe alle torrents der letzten 8 Tage ab und ordne diese einem top recording zu
        https://www.onlinetvrecorder.com/v2/?go=tracker&search=&order=ctime%20DESC&start=0
    """
    log.debug('try to update torrents webcontent...')
    stopflag = False
    start = 0

    torrentlist = []

    while not stopflag:

        """ download webcontent into content"""
        with urllib.request.urlopen('https://www.onlinetvrecorder.com/v2/?go=tracker&search=&order=ctime%20DESC&start=' + str(start)) as response:
            content = response.read()
        
        """ für jeden Eintrag in ID= searchrow """
        content = str(content.decode('utf-8', 'ignore')).split(' class="bordertable">')[1].split('</table>')[0].split('</tr>')
        for index in range(1, len(content)-1):
            lines = content[index].split('</td>')
            
            """ parse data from entry """
            torrentlink = lines[1].split("href='")[1].split("'")[0]
            torrentfile = lines[1].split(torrentlink + "'>")[1].split('</a>')[0]
            finished = safe_cast(lines[2].split('>')[1].split('</td>')[0],int,0)
            loading = safe_cast(lines[3].split('>')[1].split('</td>')[0],int,0)
            loaded = safe_cast(lines[4].split('>')[1].split('</td>')[0],int,0)
            
            fileparts = torrentfile.split(' ')     
            beginn = safe_cast(fileparts[len(fileparts)-4] + ' ' + fileparts[len(fileparts)-3] + '-00', datetime, None, '%y.%m.%d %H-%M-%S')
            sender = fileparts[len(fileparts)-2]
            
            if beginn.date() >= startdate:
                
                """ update list """
                torrent = {}
                torrent['TorrentLink'] = torrentlink
                torrent['TorrentFile'] = torrentfile
                torrent['finished'] = finished
                torrent['loading'] = loading
                torrent['loaded'] = loaded
                torrent['beginn'] = beginn
                torrent['sender'] = sender.replace(' ', '').lower()
                
                resolution = ''
                resolution = torrentlink.split('TVOON_DE')[1].split('otrkey.torrent')[0] 

                if resolution == ('.mpg.HD.avi.'):
                    """ TVOON_DE.mpg.HD.avi.otrkey.torrent"""
                    resolution = 'HD'
                    
                elif resolution == ('.mpg.HQ.avi.'):
                    """ _TVOON_DE.mpg.HQ.avi.otrkey.torrent"""
                    resolution = 'HQ'
                    
                elif resolution == ('.mpg.avi.'):
                    """ DIVX _TVOON_DE.mpg.avi.otrkey.torrent """
                    resolution = 'DIVX'
                    
                elif resolution == ('.mpg.mp4.'):
                    """ MP4  0_TVOON_DE.mpg.mp4.otrkey.torrent """
                    resolution = 'MP4'
                    
                elif resolution == ('.mpg.HD.ac3.'):
                    """ f1_130_TVOON_DE.mpg.HD.ac3.otrkey.torrent """
                    resolution = 'HD.AC3'
                    
                else:
                    resolution = 'AVI'
                    
                torrent['Resolution'] = resolution


                torrentlist.append(torrent)
                #log.debug('parsed torrent: {} in {} recorded at {!s} on {}'.format(torrentfile, resolution, beginn, sender))

            else:
                stopflag = True
                break
                
        start = start + 50

    log.info('{!s} torrents successfully retrieved...'.format(len(torrentlist)))

    """ retrieve epg id from top recordings """
    for top in db.tableservice.query_entities('recordings', filter="PartitionKey eq 'top'", select='PartitionKey, RowKey, Id, beginn, sender, titel'):
        
        torrents = [item for item in torrentlist if item['beginn'].strftime('%y.%m.%d %H-%M-%S') == top.beginn.strftime('%y.%m.%d %H-%M-%S') and item['sender'] == top.sender.replace(' ', '').lower()]
        log.debug('filterded {!s} torrents for top recording {}'.format(len(torrents),top.titel))

        if len(torrents) >= 1:
            for torrent in torrents:
                Torrent(db.tableservice, Id = top.Id, **torrent).save()
        else:
            Torrent(db.tableservice, Id = top.Id, **torrent).delete()
            Recording(db.tableservice, **top).delete()
    pass
Пример #4
0
""" imports & globals """
import os
from sys import stderr, stdout, stdin

import logging
import logging.handlers

from server.helper import safe_cast
""" Main configuration """
config = {}
""" import configuration depending on environment """
config['APPLICATION_ENVIRONMENT'] = safe_cast(
    os.environ.get('APPLICATION_ENVIRONMENT'), str, 'Production')

if config['APPLICATION_ENVIRONMENT'] == 'Development':
    from config.application import dev as configs
elif config['APPLICATION_ENVIRONMENT'] == 'Test':
    from config.application import test as configs
elif config['APPLICATION_ENVIRONMENT'] == 'Production':
    from config.application import prod as configs
else:
    from config.application import prod as configs

tmpconfig = {}
for (key, value) in vars(configs).items():
    if key != '' and key[:2] != '__':
        tmpconfig[key] = value

config.update(tmpconfig)
""" import secret configuration depending if module secrets exists """
try: