Ejemplo n.º 1
0
 def load_active_event(self, name):
   db_connection=sqlite3.connect(SETTINGS.SCHEDULE_PATH)
   db_cursor=db_connection.cursor()
 
   table_name = name.replace(' ', '_').lower()
 
   #now_utc = datetime.now(timezone('UTC'))
   #tz_ro = timezone('Europe/Bucharest')
   #dt_ro = tz_ro.normalize(now_utc.astimezone(tz_ro))
 
   event = None
 
   try:
     sql="SELECT event_time, title FROM `%s` WHERE event_time <= ? ORDER BY event_time DESC LIMIT 1" % \
         (table_name,)
     #db_cursor.execute(sql, ( time.mktime(dt_ro.timetuple()), ) )
     db_cursor.execute(sql, ( int(time.time()), ) )
     rec=db_cursor.fetchone()
     if rec:
       event = self.add_event(rec[0], rec[1])
       schedule.append(event)
   except Exception as inst:
     addon_log(inst)
 
   #addon_log(event)
 
   return event
Ejemplo n.º 2
0
  def migrateDb(self):
    addon_log("""Run database migrations.""")

    def get_script_version(path):
        return int(path.split('_')[0])

    db = sqlite3.connect(SETTINGS.CHANNELS_DB)
    current_version = db.cursor().execute('pragma user_version').fetchone()[0]

    addon_log(current_version)

    migrations_path = os.path.join(SETTINGS.ADDON_PATH, 'resources/streams/migrations/')
    migration_files = list(os.listdir(migrations_path))
    for migration in sorted(migration_files):
        scriptFile = "{0}".format(migration)
        migration_version = get_script_version(scriptFile)
        scriptPath = os.path.join(SETTINGS.ADDON_PATH, 'resources/streams/migrations/', scriptFile)

        if migration_version > current_version:
            addon_log("applying migration {0}".format(migration_version))
            with open(scriptPath, mode='r') as f:
                 db.cursor().executescript(f.read())
                 addon_log("database now at version {0}".format(migration_version))
        else:
            addon_log("migration {0} already applied".format(migration_version))
Ejemplo n.º 3
0
 def mark_offline(self):
     channelData = {
         "idChannel": self.ch_id,
         "status": -1,
     }
     addon_log(json.dumps(channelData))
     self.send_request(channelData)
Ejemplo n.º 4
0
  def send(self):
    if(not os.path.isfile(self.exportFile)):
      return

    msg = MIMEMultipart()
    #msg = EmailMessage()
    #msg['Subject'] = 'Export %s' % datetime.now().isoformat()
    msg['Subject'] = 'Export plugin.video.streams'
    msg['From'] = addon.getSetting('smtpUsername')
    msg['To'] = SETTINGS.EXPORT_EMAIL
    #msg.set_content(fp.read())
        
    fp=open(self.exportFile,"rb")
    attach = MIMEBase('application', 'json')
    attach.set_payload(fp.read())
    fp.close()
    # Encode the payload using Base64
    #encoders.encode_base64(msg)
    attach.add_header('Content-Disposition', 'attachment', filename='streams.json')
    msg.attach(attach)
    #msg.add_attachment(f.read(),
    #                   maintype='application',
    #                   subtype='json',
    #                   filename='export.json')
    
    try:  
      self.smtp.sendmail(addon.getSetting('smtpUsername'), SETTINGS.EXPORT_EMAIL, msg.as_string())
      #s.send_message(msg)
    except Exception as inst:
      addon_log(inst)
      xbmcgui.Dialog().ok(addon.getLocalizedString(30300), addon.getLocalizedString(30409), str(inst))
Ejemplo n.º 5
0
  def __init__( self , *args, **kwargs):
    self.name=kwargs.get('name')
    self.protocol=kwargs.get('protocol')
    self.ch_id=kwargs.get('ch_id')
    self.callback = None

    self.stream_online = None
    self.player_status = None
    addon_log('INIT PLAYER')
Ejemplo n.º 6
0
 def stop_spsc( self ):
   if(self.spsc_pid != None) :
     addon_log('KILL PID = '+str(self.spsc_pid))
     os.kill(self.spsc_pid, 9)
   else :
     addon_log('KILL ALL SOPCAST')
     if(ARM) :
       os.system("killall -9 "+SETTINGS.QEMU)
     else :
       os.system("killall -9 "+SETTINGS.SPSC_BINARY)
Ejemplo n.º 7
0
 def stop_spsc(self):
     if (self.spsc_pid != None):
         addon_log('KILL PID = ' + str(self.spsc_pid))
         os.kill(self.spsc_pid, 9)
     else:
         addon_log('KILL ALL SOPCAST')
         if (ARM):
             os.system("killall -9 " + SETTINGS.QEMU)
         else:
             os.system("killall -9 " + SETTINGS.SPSC_BINARY)
Ejemplo n.º 8
0
 def mark_online(self):
   channelData = { "idChannel": self.ch_id,
                   "status":    1,
                   "res":       xbmc.getInfoLabel('VideoPlayer.VideoResolution'),
                   "aspect":    xbmc.getInfoLabel('VideoPlayer.VideoAspect'),
                   "vCodec":    xbmc.getInfoLabel('VideoPlayer.VideoCodec'),
                   "aCodec":    xbmc.getInfoLabel('VideoPlayer.AudioCodec')
                 }
   addon_log(json.dumps(channelData))
   self.send_request(channelData)
Ejemplo n.º 9
0
Archivo: default.py Proyecto: teosan5/0
def CAT_LIST(force=False, mode=None):
    if force == False:
        if not os.path.isfile(SETTINGS.CHAN_LIST):
            addon_log('channels first download')
            Downloader(
                SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST,
                addon.getLocalizedString(30053),
                addon.getLocalizedString(30054))  #Downloading Channel list
            parse_ch_data()
        else:
            now_time = time.mktime(datetime.now().timetuple())
            time_created = os.stat(
                SETTINGS.CHAN_LIST)[8]  # get local play list modified date
            if SETTINGS.CHAN_LIST_EXPIRE > 0 and now_time - time_created > SETTINGS.CHAN_LIST_EXPIRE:
                addon_log('channels update')
                Downloader(
                    SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST,
                    addon.getLocalizedString(30053),
                    addon.getLocalizedString(30054))  #Downloading Channel list
                parse_ch_data()
    else:
        Downloader(SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST,
                   addon.getLocalizedString(30053),
                   addon.getLocalizedString(30054))  #Downloading Channel list
        parse_ch_data()

    rec = []
    try:
        sql = "SELECT id, name \
           FROM categories"

        db_cursor.execute(sql)
        rec = db_cursor.fetchall()
    except Exception as inst:
        #addon_log(inst)
        #cannot parse the channel list
        xbmcgui.Dialog().ok(addon.getLocalizedString(30300),
                            addon.getLocalizedString(30301),
                            str(inst))  #Cannot parse channel list !

    if len(rec) > 0:
        for id, name in rec:
            channelsListMode = 1
            if (mode != None):
                name = "[COLOR red]" + name + "[/COLOR]"
                channelsListMode = 101
            addDir(name, str(id), SETTINGS.CHAN_LIST, channelsListMode)

    #unverified category
    if ((SETTINGS.SHOW_UNVERIFIED == 'true') and (mode == None)):
        addDir("[COLOR red]" + addon.getLocalizedString(30066) + "[/COLOR]",
               str(-1), SETTINGS.CHAN_LIST, 100)

    #xbmc.executebuiltin("Container.SetViewMode(500)")
    xbmc.executebuiltin("Container.SetViewMode(51)")
 def keep_allive(self, url):
     #KEEP SCRIPT ALLIVE
     time = 0
     interval = 500
     while (self.player_status == 'play'):
         addon_log('ALLIVE')
         xbmc.sleep(500)
         time += interval
         if (time > 60 * 1000):
             time = 0
             self.digiFakeRequest(url)
Ejemplo n.º 11
0
  def __init__( self , *args, **kwargs):
    self.player=kwargs.get('player')
    url=kwargs.get('url')
    self.listitem=kwargs.get('listitem')

    self.player_started = None

    self.pid = url.replace('acestream://', '')
    self.pid = self.pid.replace('/', '')

    addon_log('INIT ACESTREAM')
Ejemplo n.º 12
0
    def __init__(self, *args, **kwargs):
        self.player = kwargs.get('player')
        url = kwargs.get('url')
        self.listitem = kwargs.get('listitem')

        self.player_started = None

        self.pid = url.replace('acestream://', '')
        self.pid = self.pid.replace('/', '')

        addon_log('INIT ACESTREAM')
 def digiFakeRequest(self, url):
     if (self.deviceId and self.DOSESSV3PRI):
         digi = Digi(deviceId=self.deviceId, DOSESSV3PRI=self.DOSESSV3PRI)
         m3u = digi.getPage(
             url
         )  # needed for android devices to be accessed as browser before play otherwise we get 401 error
         addon_log(m3u)
     else:
         if (self.fakeRequest):
             response = requests.get(url)
             addon_log(response.text)
Ejemplo n.º 14
0
  def keep_allive(self):
    xbmc.sleep(500)

    #KEEP SCRIPT ALLIVE
    #while (addon.getSetting('player_status')=='play'):
    while (self.player_status=='play'):
      addon_log('ALLIVE')
      xbmc.sleep(500)

    #try: xbmc.executebuiltin("Dialog.Close(all,true)")
    #except: pass
Ejemplo n.º 15
0
 def send_request(self, channelData):
     try:
         opener = urllib2.build_opener(urllib2.HTTPHandler)
         request = urllib2.Request(self.url, data=json.dumps(channelData))
         request.add_header('Content-Type', 'application/json')
         request.get_method = lambda: 'PUT'
         response = opener.open(request)
         addon_log('Response :')
         addon_log(response.read())
     except:
         pass
Ejemplo n.º 16
0
 def checkSmtp(self):
   try:  
     self.smtp = smtplib.SMTP(addon.getSetting('smtp'), addon.getSetting('smtpPort'))
     self.smtp.ehlo()
     self.smtp.starttls()
     #if((addon.getSetting('smtpUsername') != "") and (addon.getSetting('smtpPasswd') != "")):
     self.smtp.login(addon.getSetting('smtpUsername'), addon.getSetting('smtpPasswd'))
     return True
   except Exception as inst:
     addon_log(inst)
     #xbmc.executebuiltin("Notification(%s,%s,%d)" % (addon.getLocalizedString(30409), "", 30000))
     xbmcgui.Dialog().ok(addon.getLocalizedString(30300), addon.getLocalizedString(30409), str(inst))
Ejemplo n.º 17
0
 def delete(self, softDelete=False):
   addon_log(self.my)
   if(self.my):
     sql = "DELETE FROM channels \
           WHERE id = ?"
     st = self.db_cursor.execute(sql, (self.id, ))
     self.db_connection.commit()
     return st
   else:
     sql = "UPDATE channels \
           SET deleted = 1 \
           WHERE id = ?"
     st = self.db_cursor.execute(sql, (self.id, ))
     self.db_connection.commit()
     return st
Ejemplo n.º 18
0
    def engine_connect(self):
        try:
            self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.sock.connect((SETTINGS.ACE_HOST, SETTINGS.ACE_PORT))
        except Exception as inst:
            addon_log(inst)
            try:
                xbmc.executebuiltin("Dialog.Close(all,true)")
            except:
                pass
            DEBUG = addon.getSetting('debug')
            if DEBUG == 'true':
                xbmc.executebuiltin("Notification(%s,%s,%i)" %
                                    (str(type(inst)), str(inst), 5))
            return False

        self.send("HELLOBG version=3")
        self.ace_read()
Ejemplo n.º 19
0
  def onPlayBackEnded(self):
    addon_log('----------------------->END')
    addon_log(self.stream_online);

    #xbmc.executebuiltin('Container.Refresh()')
    try:
      if(self.callback != None):
        self.callback()
    except: pass

    if(self.stream_online!=True) :
      #online notif
      mark = mark_stream(ch_id=self.ch_id)
      mark.mark_offline()
      self.stream_online = False

    #addon.setSetting('player_status', 'end')
    self.player_status = 'end';
Ejemplo n.º 20
0
  def sop_sleep(self, time):
    counter = 0
    increment = 5000
    #path="/proc/%s" % str(spsc_pid)

    #addon_log('proc exists')
    #addon_log(os.path.exists(path))
    try:
      #while counter < time and spsc_pid>0 and not xbmc.abortRequested and os.path.exists(path):
      while counter < time and self.spsc_pid>0 and not xbmc.abortRequested and self.sop_pid_exists():
        counter += increment
        xbmc.sleep(increment)
    except Exception as inst:
      addon_log(inst)
      DEBUG = addon.getSetting('debug')
      if DEBUG == 'true': xbmc.executebuiltin("Notification(%s,%s,%i)" % (str(type(inst)), str(inst), 5))
      return True
    if counter < time: return False
    else: return True
Ejemplo n.º 21
0
    def downloadEPG(self):
        if (self.loaded):
            return

        now = time.time()
        try:
            for filename in glob.glob(os.path.join(SETTINGS.ADDON_PATH,
                                                   "epg*")):
                if (os.stat(filename).st_mtime <
                        now - 86400):  #remove files older than 1 day
                    os.remove(filename)
        except:
            pass
        now_utc = datetime.now(timezone('UTC'))
        tz_ro = timezone('Europe/Bucharest')
        dt_ro = tz_ro.normalize(now_utc.astimezone(tz_ro))

        #https://web-api-salt.horizon.tv/oesp/v2/RO/ron/web/channels
        urlBase = "https://web-api-salt.horizon.tv/oesp/v2/RO/ron/web/programschedules/"

        for day in range(0, 2):
            dt_ro = dt_ro + timedelta(days=day)
            urlDate = urlBase + dt_ro.strftime('%Y%m%d') + '/'

            for section in range(1, 5):  #every day EPG is splitted in 3
                url = urlDate + str(section)
                #addon_log(url)
                epgFile = os.path.join(
                    SETTINGS.ADDON_PATH, "epg_" + dt_ro.strftime('%Y%m%d') +
                    "_" + str(section) + ".json")
                if (not os.path.isfile(epgFile)):
                    try:
                        Downloader(url, epgFile,
                                   addon.getLocalizedString(30061),
                                   addon.getLocalizedString(
                                       30062))  #Downloading Schedule
                        f = open(epgFile)
                        f.close()
                    except Exception as inst:
                        addon_log("error downloading epg file")
                        addon_log(inst)

            self.loaded = True
Ejemplo n.º 22
0
 def load_schedule(self, name):
   addon_log('load schedule ' + name)
   schedule = []
 
   db_connection=sqlite3.connect(SETTINGS.SCHEDULE_PATH)
   db_cursor=db_connection.cursor()
 
   table_name = name.replace(' ', '_').lower()
   
   #now_utc = datetime.now(timezone('UTC'))
   #tz_ro = timezone('Europe/Bucharest')
   #dt_ro = tz_ro.normalize(now_utc.astimezone(tz_ro))
 
   try:
     active_event = self.load_active_event(name)
     if active_event:
       schedule.append(active_event)
 
     sql="SELECT event_time, title FROM `%s` WHERE event_time > ? ORDER BY event_time ASC LIMIT 10" % \
          (table_name,)
     #addon_log(sql)
     #db_cursor.execute(sql, (time.mktime(dt_ro.timetuple()),) )
     db_cursor.execute(sql, (int(time.time()),) )
     rec=db_cursor.fetchall()
 
     if len(rec)>0:
       for event_time, title in rec:
         event = self.add_event(event_time, title)
         schedule.append(event)
 
   except Exception as inst:
     #addon_log(inst)
     pass
 
   if len(schedule)>=2:
     schedule_txt = ' - '.join(schedule)
   else:
     schedule_txt = '( [I]'+addon.getLocalizedString(30064)+'[/I] )'
   #addon_log(schedule_txt)
 
   return schedule_txt
Ejemplo n.º 23
0
    def sop_sleep(self, time):
        counter = 0
        increment = 200
        #path="/proc/%s" % str(spsc_pid)

        #addon_log('proc exists')
        #addon_log(os.path.exists(path))
        try:
            #while counter < time and spsc_pid>0 and not xbmc.abortRequested and os.path.exists(path):
            while counter < time and self.spsc_pid > 0 and not xbmc.abortRequested and self.sop_pid_exists(
            ):
                counter += increment
                xbmc.sleep(increment)
        except Exception as inst:
            addon_log(inst)
            DEBUG = addon.getSetting('debug')
            if DEBUG == 'true':
                xbmc.executebuiltin("Notification(%s,%s,%i)" %
                                    (str(type(inst)), str(inst), 5))
            return True
        if counter < time: return False
        else: return True
Ejemplo n.º 24
0
  def engine_connect(self):
    with busy_dialog():
      try:
        self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.sock.connect((SETTINGS.ACE_HOST, SETTINGS.ACE_PORT))
      except Exception as inst:
        addon_log(inst)
        # try: xbmc.executebuiltin("Dialog.Close(all,true)")
        # except: pass
        DEBUG = addon.getSetting('debug')
        if DEBUG == 'true': xbmc.executebuiltin("Notification(%s,%s,%i)" % (str(type(inst)), str(inst), 5))
        return False

      self.send("HELLOBG version=3")
      player_url = self.ace_read()

    if(player_url != None):
      addon_log (player_url)
      self.player.callback = self.shutdown
      self.listitem.setInfo('video', {'Title': self.filename})
      self.player.play(player_url, self.listitem)
      self.player_started = True
Ejemplo n.º 25
0
def CAT_LIST(force=False, mode=None):
  channels = Channels()
  channels.migrateDb()

  exp = export()
  if(exp.export() != True) :
    return

  if force==False:
    if not os.path.isfile(SETTINGS.CHAN_LIST):
      addon_log('channels first download')
      Downloader(SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054))  #Downloading Channel list
      channels.importChannels()
    else:
      now_time = time.mktime(datetime.now().timetuple())
      time_created = os.stat(SETTINGS.CHAN_LIST)[8]  # get local play list modified date
      if SETTINGS.CHAN_LIST_EXPIRE>0 and now_time - time_created > SETTINGS.CHAN_LIST_EXPIRE:
        addon_log('channels update')
        Downloader(SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054)) #Downloading Channel list
        channels.importChannels()
  else:
    Downloader(SETTINGS.CHAN_LIST_URL, SETTINGS.CHAN_LIST, addon.getLocalizedString(30053), addon.getLocalizedString(30054)) #Downloading Channel list
    channels.importChannels()
  
  ch = Channels()
  arrCategories = ch.loadCategories()
  for cat in arrCategories:
    channelsListMode = 1
    name = cat.name
    if(mode != None):
      name="[COLOR red]"+cat.name+"[/COLOR]"
      channelsListMode=101
    
    addDir(name, str(cat.id), SETTINGS.CHAN_LIST, channelsListMode)

  #unverified category
  if ((SETTINGS.SHOW_UNVERIFIED == 'true') and (mode==None)):
    addDir("[COLOR red]"+addon.getLocalizedString(30066)+"[/COLOR]", str(-1), SETTINGS.CHAN_LIST, 100)
Ejemplo n.º 26
0
  def onPlayBackStopped(self):
    addon_log('----------------------->STOP')
    addon_log(self.stream_online);

    #xbmc.executebuiltin('Container.Refresh()')
    addon_log(self.callback)
    try:
      if(self.callback != None):
        self.callback()
    except: pass

    #online notif
    if(self.stream_online!=True) :
      mark = mark_stream(ch_id=self.ch_id)
      mark.mark_offline()
      self.stream_online = False
      xbmc.executebuiltin( "Dialog.Close(busydialog)" )
      if SETTINGS.NOTIFY_OFFLINE == "true": xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30057), "",1))  #Channel is offline

    #addon.setSetting('player_status', 'stop')
    self.player_status = 'stop';
Ejemplo n.º 27
0
  def onPlayBackStarted(self):
    addon_log('START')
    addon_log(xbmc.getInfoLabel('VideoPlayer.VideoCodec'))
    addon_log(xbmc.getInfoLabel('VideoPlayer.AudioCodec'))

    ## this will kill the sopcast if we changed the media
    #if xbmc.Player(xbmc.PLAYER_CORE_AUTO).getPlayingFile() != SETTINGS.LOCAL_URL:
    #  try: stop_spsc(self.spsc_pid)
    #  except: pass
    xbmc.executebuiltin( "Dialog.Close(busydialog)" )

    #online notif
    mark = mark_stream(ch_id=self.ch_id)
    mark.mark_online()
    self.stream_online = True

    if SETTINGS.DISABLE_SCHEDULE!='true':
      #display schedule active event
      epgObj = epg()
      active_event = epgObj.load_active_event(self.name)
      if active_event:
        active_event = active_event.encode('utf8')
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (active_event, "", 10000))
Ejemplo n.º 28
0
def CHANNEL_LIST(name, cat_id, mode=None, schedule=False):
  if (SETTINGS.DISABLE_SCHEDULE != 'true'):
    epgObj = epg()

  addon_log(name);
  rec = []
  try:
    sql = 'SELECT id, name, language, status, \
           address, thumbnail, protocol, \
           schedule_id, unverified \
           FROM channels \
           WHERE id_cat = ?'
    if((mode!=None) and (int(mode)==101)):
      sql += ' and unverified = 1'
    else:
      sql += ' and unverified IS NULL'
    sql += ' ORDER BY name'
    db_cursor.execute( sql, (cat_id,) )
    rec=db_cursor.fetchall()
  except Exception as inst:
    addon_log(inst)
    xbmcgui.Dialog().ok(addon.getLocalizedString(30300), addon.getLocalizedString(30301), str(inst))  #Cannot parse channel list !

  if len(rec)>0:
    for id, name, language, status, \
        address, thumbnail, protocol, \
        schedule_id, unverified in rec:

      #filter by country and language
      #if( (((country != '') and (addon.getSetting('country_'+country) == 'true')) or
           #((country == '') and (addon.getSetting('country_none') == 'true')) ) and
           #(((language != '') and (addon.getSetting('lang_'+language) == 'true')) or
           #((language == '') and (addon.getSetting('lang_none') == 'true')) )
        #):

      chan_name = name
      chan_url = address.strip()

      protocol = protocol.strip()
      #if protocol=='sop':
      #  protocol_color = '[COLOR lightgreen]'+protocol+'[/COLOR]'
      #else:
      #  protocol_color = '[COLOR yellow]'+protocol+'[/COLOR]'

      chan_thumb = thumbnail.strip()
      #addon_log(chan_thumb)
      chan_status = status

      if (((SETTINGS.SHOW_OFFLINE_CH=='true') and (int(chan_status)==1)) or (int(chan_status)!=1)): #if we show or not offline channels based on settings
        logo_name = chan_name.replace(' ', '').lower()
        logo_name = logo_name.encode('utf8')

        chan_name_formatted ="[B]"+chan_name+"[/B]"
        chan_name_formatted += " [[COLOR yellow]"+protocol+"[/COLOR]]"

        if int(chan_status)==1: chan_name_formatted += " [COLOR red]"+addon.getLocalizedString(30063)+"[/COLOR]"  #Offline

        thumb_path=""
        if chan_thumb and chan_thumb != "":
          fileName, fileExtension = os.path.splitext(chan_thumb)
          fileName=fileName.split("/")[-1]

          logoDir = os.path.join(SETTINGS.ADDON_PATH,"logos");
          #create logos directory if does not exists
          if(not os.path.isdir(logoDir)):
            os.makedirs(logoDir)

          if fileName != "":
            #thumb_path=os.path.join(ADDON_PATH,"logos",fileName+fileExtension)
            fileExtension = fileExtension.encode('utf8')
            thumb_path=os.path.join(logoDir,logo_name+fileExtension)

          if not os.path.isfile(thumb_path):
            if fileName != "":
              try:
                Downloader(chan_thumb, thumb_path, fileName+fileExtension, addon.getLocalizedString(30055)) #Downloading Channel Logo
              except Exception as inst:
                pass;

        #schedule
        if (schedule_id != 0) and \
            (schedule or (addon.getSetting('schedule_ch_list') == 'true')) \
            and (SETTINGS.DISABLE_SCHEDULE != 'true'):
          if (schedule): #update all by context menu
            update_all = True
          elif(addon.getSetting('schedule_ch_list') == 'true'): #update all when we display channel list
            update_all = False
          #addon_log('grab_schedule')
          epgObj.grab_schedule(schedule_id, chan_name, update_all=update_all)

        if (SETTINGS.DISABLE_SCHEDULE != 'true') and (int(cat_id) < 200):
          schedule_txt = epgObj.load_schedule(chan_name)
          chan_name_formatted += "   " + schedule_txt

        addLink(id, chan_name_formatted, chan_name, chan_url, protocol, str(schedule_id),
                name, cat_id, 2, thumb_path, "", len(rec))

  xbmc.executebuiltin("Container.SetViewMode(51)")
Ejemplo n.º 29
0
def parse_ch_data():
  with open(SETTINGS.CHAN_LIST) as json_file:
    data = json.loads(json_file.read())
    json_file.close()

    sql = "CREATE TABLE IF NOT EXISTS categories (id INTEGER, name TEXT)"
    db_cursor.execute(sql);
    sql="DELETE FROM categories"
    db_cursor.execute(sql)

    sql = "CREATE TABLE IF NOT EXISTS channels \
          (id INTEGER, id_cat INTEGER, name TEXT, language TEXT, status INTEGER, \
           video_resolution TEXT, video_aspect REAL, audio_codec TEXT, video_codec TEXT, \
           address TEXT, thumbnail TEXT, protocol TEXT, \
           schedule_id INTEGER, unverified INTEGER)"
    db_cursor.execute(sql)
    sql="DELETE FROM channels"
    db_cursor.execute(sql)

    addon_log(data['date'])

    for group in data['groups']:
      addon_log(str(group['id']) + " " + group['name'])
      db_cursor.execute("INSERT INTO categories \
                         VALUES (?, ?)",
                         (group['id'], group['name']))

      for channel in group['channels']:
        #addon_log(str(channel['id'])+" "+unicode(channel['name'])+" "+ str(channel['language'])+" "+str(channel['status']))
        if ((not channel['unverified']) or (SETTINGS.SHOW_UNVERIFIED=='true')):

          addon_log(channel['name'].encode('utf8'))

          schedule_id = 0
          thumbnail = ""
          video_resolution = ""
          video_aspect = 0
          audio_codec = ""
          video_codec = ""

          stream_type = channel['stream_type']
          if 'schedule' in channel:
            schedule = channel['schedule']
            schedule_id = schedule['ch_id']
          if 'thumbnail' in channel:
            thumbnail = channel['thumbnail']
          if 'video_resolution' in stream_type:
            video_resolution = stream_type['video_resolution']
          if 'video_aspect' in stream_type:
            video_aspect = stream_type['video_aspect']
          if 'audio_codec' in stream_type:
            audio_codec = stream_type['audio_codec']
          if 'video_codec' in stream_type:
            video_codec = stream_type['video_codec']

          db_cursor.execute( \
                "INSERT INTO channels \
                 VALUES (?, ?, ?, ?, ?, \
                         ?, ?, ?, ?, \
                         ?, ?, ?, \
                         ?, ?)" ,
                 ( channel['id'], group['id'], channel['name'], channel['language'], channel['status'], \
                   video_resolution, video_aspect, audio_codec, video_codec, \
                   channel['address'], thumbnail, channel['protocol'], \
                   schedule_id, channel['unverified']) )

    db_connection.commit()
Ejemplo n.º 30
0
#    # check if player stoped and restart it
#    if not xbmc.Player(xbmc.PLAYER_CORE_AUTO).isPlaying():
#      if not sop_sleep(1000 , spsc_pid): break
#      if not xbmc.Player(xbmc.PLAYER_CORE_AUTO).isPlaying():
#        player = streamplayer(xbmc.PLAYER_CORE_AUTO , spsc_pid=spsc_pid, name=name)
#        player.play(LOCAL_URL, listitem)
#        addon_log("RESTART PLAYER")
#
#      sop_sleep(2000 , spsc_pid)
#    sop_sleep(300 , spsc_pid)

#######################################################################################################################
#######################################################################################################################
#######################################################################################################################

addon_log('------------- START -------------')

db_connection=sqlite3.connect(SETTINGS.CHANNELS_DB)
db_cursor=db_connection.cursor()

addon_log(SETTINGS.CHAN_LIST_URL)
addon_log(SETTINGS.CHAN_LIST)

#read params
params=get_params()
try:
  mode=int(params["mode"])
except:
  mode=None
try:
  name=urllib.unquote_plus(params["name"].decode('utf8').encode('utf8'))
Ejemplo n.º 31
0
 def send(self, cmd):
     try:
         self.sock.send(cmd + "\r\n")
     except Exception as inst:
         addon_log(inst)
Ejemplo n.º 32
0
  def importChannels(self):
    # self.createDb()
    # self.migrateDb()
    
    with open(SETTINGS.CHAN_LIST) as json_file:
      data = json.loads(json_file.read())
      json_file.close()

      self.cleanCategories()

      parsedIds = []

      for group in data['groups']:
        addon_log(str(group['id']) + " " + group['name'])
        cat = Category(id = group['id'], name=group['name'])
        cat.insert()
        
        for channel in group['channels']:
          #addon_log(str(channel['id'])+" "+unicode(channel['name'])+" "+ str(channel['language'])+" "+str(channel['status']))
          if ((not channel['unverified']) or (SETTINGS.SHOW_UNVERIFIED=='true')):

            #addon_log(channel['name'].encode('utf8'))

            # schedule_id = 0
            # thumbnail = ""
            # video_resolution = ""
            # video_aspect = 0
            # audio_codec = ""
            # video_codec = ""

            # stream_type = channel['stream_type']
            # if 'schedule' in channel:
            #   schedule = channel['schedule']
            #   schedule_id = schedule['ch_id']
            # if 'thumbnail' in channel:
            #   thumbnail = channel['thumbnail']
            # if 'video_resolution' in stream_type:
            #   video_resolution = stream_type['video_resolution']
            # if 'video_aspect' in stream_type:
            #   video_aspect = stream_type['video_aspect']
            # if 'audio_codec' in stream_type:
            #   audio_codec = stream_type['audio_codec']
            # if 'video_codec' in stream_type:
            #   video_codec = stream_type['video_codec']
            if(channel['status'] == 2): 
              status = Channel.STATUS_ONLINE 
            else: 
              status = Channel.STATUS_OFFLINE

            ch = Channel(id = str(channel['id']),
                         id_cat = group['id'],
                         name = channel['name'],
                         address = channel['address'], 
                         protocol = channel['protocol'],
                         language = channel['language'],
                         status = status,
                         unverified = channel['unverified']
                        )
            if((ch.checkExist() == False) and (ch.checkAddrExist() == False)):
              ch.insert()
            else:
              if(ch.checkIsMy() == False):
                ch.update(id_cat = group['id'],
                          name = channel['name'],
                          address = channel['address'], 
                          protocol = channel['protocol'],
                          language = channel['language'],
                          status = status,
                          unverified = channel['unverified'])
            
            if(ch.checkIsMy() == False):
              parsedIds.append(ch.id)
      
      addon_log('parsed %d channels' % len(parsedIds))
      self.cleanChannels(parsedIds)
Ejemplo n.º 33
0
    def start(self):
        if xbmc.getCondVisibility('System.Platform.Android'):
            xbmc.executebuiltin(
                'XBMC.StartAndroidActivity("com.devaward.soptohttp","android.intent.action.VIEW","",'
                + self.sopurl + ')')
        else:
            try:
                if (SETTINGS.ARM):
                    self.spsc = subprocess.Popen(self.cmd,
                                                 shell=False,
                                                 bufsize=SETTINGS.BUFER_SIZE,
                                                 stdin=None,
                                                 stdout=None,
                                                 stderr=None)
                else:
                    env = os.environ
                    env['LD_LIBRARY_PATH'] = SETTINGS.SPSC_LIB
                    self.spsc = subprocess.Popen(self.cmd,
                                                 shell=False,
                                                 bufsize=SETTINGS.BUFER_SIZE,
                                                 stdin=None,
                                                 stdout=None,
                                                 stderr=None,
                                                 env=env)

                self.spsc_pid = self.spsc.pid

                xbmc.sleep(int(addon.getSetting('wait_time')))

                res = False
                counter = 50
                #while counter > 0 and os.path.exists("/proc/"+str(spsc.pid)):
                while counter > 0 and self.sop_pid_exists():
                    xbmc.executebuiltin("ActivateWindow(busydialog)")
                    xbmc.sleep(400)
                    counter -= 1
                    try:
                        addon_log(SETTINGS.LOCAL_URL)
                        urllib2.urlopen(SETTINGS.LOCAL_URL)
                        counter = 0
                        res = self.sop_sleep(200)
                        break
                    except Exception as inst:
                        addon_log(inst)

                addon_log(res)
                offline = None
                if res:

                    #START PLAY
                    self.player.callback = self.stop_spsc
                    self.player.play(SETTINGS.LOCAL_URL, self.listitem)

                elif not self.sop_pid_exists():
                    try:
                        xbmc.executebuiltin("Dialog.Close(all,true)")
                    except:
                        pass
                    try:
                        urllib2.urlopen(SETTINGS.TEST_URL)
                        if SETTINGS.NOTIFY_OFFLINE == "true":
                            xbmc.executebuiltin(
                                "Notification(%s,%s,%i)" %
                                (addon.getLocalizedString(30057), "",
                                 1))  #Channel is offline
                        offline = True
                    except:
                        if SETTINGS.NOTIFY_OFFLINE == "true":
                            xbmc.executebuiltin(
                                "Notification(%s,%s,%i)" %
                                (addon.getLocalizedString(30058), "",
                                 1))  #Network is offline
                elif SETTINGS.NOTIFY_OFFLINE == "true":
                    try:
                        xbmc.executebuiltin("Dialog.Close(all,true)")
                    except:
                        pass
                    xbmc.executebuiltin("Notification(%s,%s,%i)" %
                                        (addon.getLocalizedString(30059), "",
                                         1))  #Channel initialization failed
                    offline = True
                    try:
                        self.stop_spsc()
                    except:
                        pass

                if offline:
                    mark = mark_stream(ch_id=self.player.ch_id)
                    mark.mark_offline()

            except Exception as inst:
                xbmcgui.Dialog().ok(addon.getLocalizedString(30060),
                                    str(type(inst)), str(inst), "")
                addon_log(str(inst))
                try:
                    stop_spsc()
                except:
                    pass
                try:
                    xbmc.executebuiltin("Dialog.Close(all,true)")
                except:
                    pass
 def onPlayBackStopped(self):
     addon_log('----------------------->STOP PLAY')
     self.player_status = 'stop'
Ejemplo n.º 35
0
import xbmc, xbmcgui
import os, os.path, re
import glob
from common import addon_log, Downloader, message, addon
from datetime import datetime, timedelta
import json

from settings import SETTINGS

try:
  import pytz
  from pytz import timezone
except ImportError as err:
  addon_log( str(err) )
  message(addon.getLocalizedString(30300), str(err) + "\n" + addon.getLocalizedString(30302))

import time
import sys
import sqlite3
#import random

#reload(sys)
#sys.setdefaultencoding('utf-8')
class epg():
  
  loaded = False

  def grab_schedule(self, id_channel_port, name, force=False, update_all=False):
    addon_log('grab schedule')
  
    #nr_days = 5
 def onPlayBackEnded(self):
     addon_log('----------------------->END PLAY')
     self.player_status = 'end'
Ejemplo n.º 37
0
def STREAM(name, iconimage, url, protocol, sch_ch_id, ch_id):
  addon_log("stream")
  if(url == None):
    # try: xbmc.executebuiltin("Dialog.Close(all,true)")
    # except: pass
    return False

  # if (sch_ch_id != None) and (SETTINGS.DISABLE_SCHEDULE != 'true'):
  #   epgObj = epg()
  #   epgObj.grab_schedule(sch_ch_id, name)

  #addon_log(name)
  #addon_log(iconimage)

  if not iconimage or iconimage == "": iconimage="DefaultVideo.png"
  listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  #listitem.setLabel(name)
  listitem.setInfo('video', {'Title': name})

  player = streamplayer(name=name, protocol=protocol, ch_id=ch_id)

  #play sopcast stream
  if protocol == "sop":
    addon_log("sop")
    if(SETTINGS.USE_PLEXUS_SOP == 'true'):
      addon_log("sop play plexus")
      try:
        addon_log('plexus')
        xbmc.executebuiltin('XBMC.RunPlugin(plugin://program.plexus/?mode=2&url='+url+'&name='+name+'&iconimage='+iconimage+')')
      except Exception as inst:
        addon_log(inst)
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30303), "", 10000))
    else:
      addon_log("sop play")
      sop = sopcast(player=player, url=url, listitem=listitem)
      sop.start()

  #play acestream
  elif protocol=='acestream':
    if(SETTINGS.ACE_ENGINE_TYPE == 1): #use plexus
      try:
        addon_log('plexus')
        xbmc.executebuiltin('XBMC.RunPlugin(plugin://program.plexus/?mode=1&url='+url+'&name='+name+'&iconimage='+iconimage+')')
      except Exception as inst:
        addon_log(inst)
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30303), "", 10000))
    elif(SETTINGS.ACE_ENGINE_TYPE == 0): #use external
      #play with acestream engine started on another machine or on the localhost
      ace = acestream(player=player, url=url, listitem=listitem)
      ace.engine_connect()
  else: #play direct stream
    try:
      player.play(url, listitem)
    except Exception as inst:
      xbmcgui.Dialog().ok(addon.getLocalizedString(30060), str(type(inst)),str(inst),"")
Ejemplo n.º 38
0
 def send(self, cmd):
   try:
     self.sock.send(cmd + "\r\n")
   except Exception as inst:
     addon_log(inst)
Ejemplo n.º 39
0
 def ch_open(self):
   request_id = random.randint(1, 100)
   cmd = 'LOADASYNC ' + str(request_id) + ' PID ' + self.pid
   self.send(cmd)
   addon_log(cmd)
   return request_id
Ejemplo n.º 40
0
  def start( self ):
    if xbmc.getCondVisibility('System.Platform.Android'):
      xbmc.executebuiltin('XBMC.StartAndroidActivity("com.devaward.soptohttp","android.intent.action.VIEW","",'+self.sopurl+')')
    else:
      try:
        with busy_dialog():
          # addon_log(self.cmd)
          self.spsc = subprocess.Popen(self.cmd, shell=False, bufsize=SETTINGS.BUFER_SIZE, stdin=None, stdout=None, stderr=None)
          # if(SETTINGS.ARM):
          #   self.spsc = subprocess.Popen(self.cmd, shell=False, bufsize=SETTINGS.BUFER_SIZE, stdin=None, stdout=None, stderr=None)
          # else:
          #   env = os.environ
          #   env['LD_LIBRARY_PATH'] = SETTINGS.SPSC_LIB
          #   addon_log(self.cmd)
          #   self.spsc = subprocess.Popen(self.cmd, shell=False, bufsize=SETTINGS.BUFER_SIZE, stdin=None, stdout=None, stderr=None, env=env)
            
          self.spsc_pid = self.spsc.pid

          xbmc.sleep(int(addon.getSetting('wait_time')))

          res=False
          counter=50
          #while counter > 0 and os.path.exists("/proc/"+str(spsc.pid)):
        
          while counter > 0 and self.sop_pid_exists():
            # xbmc.executebuiltin( "ActivateWindow(busydialog)" )
            xbmc.sleep(400)
            counter -= 1
            try:
              addon_log(SETTINGS.LOCAL_URL);
              urllib2.urlopen(SETTINGS.LOCAL_URL)
              counter=0
              res=self.sop_sleep(200)
              break
            except Exception as inst:
              addon_log(inst)

        addon_log(res)
        offline = None
        if res:

          #START PLAY
          self.player.callback = self.stop_spsc
          self.player.play(SETTINGS.LOCAL_URL, self.listitem)

        elif not self.sop_pid_exists():
          # try: xbmc.executebuiltin("Dialog.Close(all,true)")
          # except: pass
          try:
            urllib2.urlopen(SETTINGS.TEST_URL)
            if SETTINGS.NOTIFY_OFFLINE == "true": xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30057), "",1))  #Channel is offline
            offline = True
          except:
            if SETTINGS.NOTIFY_OFFLINE == "true": xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30058), "",1)) #Network is offline
        elif SETTINGS.NOTIFY_OFFLINE == "true":
          # try: xbmc.executebuiltin("Dialog.Close(all,true)")
          # except: pass
          xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30059), "", 1)) #Channel initialization failed
          offline = True
          try: self.stop_spsc()
          except: pass
        
        if offline:
          ch = Channels();
          ch.markStream(chId = self.player.ch_id, status=Channel.STATUS_OFFLINE) #offline

      except Exception as inst:
        xbmcgui.Dialog().ok(addon.getLocalizedString(30060), str(type(inst)),str(inst),"")
        addon_log(str(inst))
        try:
          stop_spsc()
        except: pass
Ejemplo n.º 41
0
def STREAM(name, iconimage, url, protocol, sch_ch_id, ch_id):
  if(url == None):
    try: xbmc.executebuiltin("Dialog.Close(all,true)")
    except: pass
    return False

  if (sch_ch_id != None) and (SETTINGS.DISABLE_SCHEDULE != 'true'):
    epgObj = epg()
    epgObj.grab_schedule(sch_ch_id, name)

  #addon_log(name)
  #addon_log(iconimage)

  if not iconimage or iconimage == "": iconimage="DefaultVideo.png"
  listitem = xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  #listitem.setLabel(name)
  listitem.setInfo('video', {'Title': name})

  player = streamplayer(name=name, protocol=protocol, ch_id=ch_id)

  #play sopcast stream
  if protocol == "sop":
    if(SETTINGS.USE_PLEXUS_SOP == 'true'):
      try:
        addon_log('plexus')
        xbmc.executebuiltin('XBMC.RunPlugin(plugin://program.plexus/?mode=2&url='+url+'&name='+name+'&iconimage='+iconimage+')')
      except Exception as inst:
        addon_log(inst)
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30303), "", 10000))
    else:
      sop = sopcast(player=player, url=url, listitem=listitem)
      sop.start()

  #play acestream
  elif protocol=='acestream':
    if(SETTINGS.ACE_ENGINE_TYPE == 2): #use plexus
      try:
        addon_log('plexus')
        xbmc.executebuiltin('XBMC.RunPlugin(plugin://program.plexus/?mode=1&url='+url+'&name='+name+'&iconimage='+iconimage+')')
      except Exception as inst:
        addon_log(inst)
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30303), "", 10000))
    elif(SETTINGS.ACE_ENGINE_TYPE == 1): #use external
      #play with acestream engine started on another machine or on the localhost
      ace = acestream(player=player, url=url, listitem=listitem)
      ace.engine_connect()
    # else: #use internal
    #   if xbmc.getCondVisibility('System.Platform.Android'):
    #       #xbmc.executebuiltin("Notification(%s,%s,%i)" % ("android", "", 3000))
    #       ace = acestream(player=player, url=url, listitem=listitem)
    #       ace.engine_connect()
    #   elif xbmc.getCondVisibility('system.platform.linux'):
    #       #xbmc.executebuiltin("Notification(%s,%s,%i)" % ("linux", "", 3000))
    #       addon_log('linux')
    #       addon_log(os.uname())
    #       if "aarch" in os.uname()[4]:
    #           addon_log('aarch')
    #           #xbmc.executebuiltin("Notification(%s,%s,%i)" % ("aarch", "", 3000))
    #           if not os.path.isfile(os.path.join(fileslist,"acestream","chroot")):
    #               arch = '64' if sys.maxsize > 2**32 else '32'
    #               acestream_pack = "https://raw.githubusercontent.com/viorel-m/kingul-repo/master/acestream/acestream_arm%s.tar.gz" % arch
    #               acekit(acestream_pack)
    #           import acestream as ace
    #           ace.acestreams_builtin(name,iconimage,url)
    #       elif "arm" in os.uname()[4]:
    #           addon_log('arm')
    #           if not os.path.isfile(os.path.join(fileslist,"acestream","chroot")):
    #               acestream_pack = "https://raw.githubusercontent.com/viorel-m/kingul-repo/master/acestream/acestream_arm32.tar.gz"
    #               acekit(acestream_pack)
    #           import acestream as ace
    #           ace.acestreams_builtin(name,iconimage,url)

  #play direct stream
  else:
    try:
      player.play(url, listitem)
    except Exception as inst:
      xbmcgui.Dialog().ok(addon.getLocalizedString(30060), str(type(inst)),str(inst),"")
      try: xbmc.executebuiltin("Dialog.Close(all,true)")
      except: pass
Ejemplo n.º 42
0
 def grab_schedule(self, id_channel_port, name, force=False, update_all=False):
   addon_log('grab schedule')
 
   #nr_days = 5
 
   db_connection=sqlite3.connect(SETTINGS.SCHEDULE_PATH)
   db_cursor=db_connection.cursor()
 
   table_name = name.replace(' ', '_').lower()
   sql = "CREATE TABLE IF NOT EXISTS `%s` (event_time REAL, title TEXT)" % \
         (table_name)
   db_cursor.execute(sql);
 
   now_utc = datetime.now(timezone('UTC'))
   tz_ro = timezone('Europe/Bucharest')
   dt_ro = tz_ro.normalize(now_utc.astimezone(tz_ro))
 
   if force == False:
     #sql="SELECT event_time FROM `%s` ORDER BY event_time ASC LIMIT 1" % \
     sql="SELECT event_time FROM `%s` ORDER BY event_time DESC LIMIT 1" % \
         (table_name)
     db_cursor.execute(sql)
     rec = db_cursor.fetchone()
     if rec:
       #addon_log(rec[0]);
       #addon_log(time.mktime(dt_ro.timetuple()));
       #if ((time.mktime(now_utc.timetuple()) - rec[0]) < (60*60*24*2)): #update only if schedule is older than 2 days
       if ((rec[0]) and (time.mktime(now_utc.timetuple()) - rec[0]) < -(3600*2)): #update only if last entry is about to expire in 2 hours
         addon_log('schedule is up to date')
         if update_all:
           xbmc.executebuiltin("Notification(%s,%s,%i)" % (name, addon.getLocalizedString(30056), 1000))  #Schedule is up to date
         return True
 
   addon_log('update schedule')
 
   # month_name_to_no={"Ianuarie" : "01",
   #                   "Februarie" : "02",
   #                   "Martie" : "03",
   #                   "Aprilie" : "04",
   #                   "Mai" : "05",
   #                   "Iunie" : "06",
   #                   "Iulie" : "07",
   #                   "August" : "08",
   #                   "Septembrie" : "09",
   #                   "Octombrie" : "10",
   #                   "Noiembrie" : "11",
   #                   "Decembrie" : "12"}
   # 
   #event_year = dt_ro.year
   #start_date=dt_ro
   #end_date = start_date + timedelta(days=nr_days)
   #end_date = start_date
   #url="http://port.ro/pls/w/tv.channel?i_xday="+str(nr_days)+"&i_date=%i-%02i-%02i&i_ch=%s" % (start_date.year , start_date.month , start_date.day , id_channel_port)
   
   #i_datetime_from = start_date.strftime('%Y-%m-%d')
   #i_datetime_to = end_date.strftime('%Y-%m-%d')
   #url="http://port.ro/pls/w/tv_api.event_list?i_channel_id=%s&i_datetime_from=%s&i_datetime_to=%s" % (id_channel_port, i_datetime_from, i_datetime_to)
   
   sql="DELETE FROM `%s`" % \
        (table_name)
   db_cursor.execute(sql)
   
   self.downloadEPG()
   
   lastEventTimestamp = None
   for day in range(0,2):
     dt_ro = dt_ro + timedelta(days=day)
         
     for section in range(1,5): #every day EPG is splitted in 3
       epgFile = os.path.join(SETTINGS.ADDON_PATH,"epg_" + dt_ro.strftime('%Y%m%d') + "_" + str(section)+".json")
       try:
         f = open(epgFile)
         schedule_txt = f.read()
         f.close()
         #os.remove(temp)
       except Exception as inst:
         addon_log("error opening epg file")
         addon_log(inst)
         schedule_txt = ""
       #addon_log(schedule_txt)
       
       try:
         schedule_json = json.loads(schedule_txt, encoding='utf-8')
       except Exception as inst:
         db_connection.commit()
         db_connection.close()
         addon_log("error parsing json file")
         return False
           
       #addon_log(schedule_json['entries'])
       #addon_log(id_channel_port)
       for entry in schedule_json['entries']:
         if(str(entry['o']) == str(id_channel_port)):
           for l in entry['l']:
             event_timestamp=l['s']/1000
             event_title = l['t']
             
             #convert from timezone ro to timezone utc
             #startTime=datetime.fromtimestamp(event_timestamp)
             #startTime=timezone('Europe/Bucharest').localize(startTime)
             #startTime=startTime.astimezone(timezone('UTC'))
             #event_timestamp = time.mktime(startTime.timetuple())
             
             if(lastEventTimestamp<event_timestamp):
               sql="INSERT INTO `%s` VALUES (?, ?)" % \
                    (table_name)
               st = db_cursor.execute(sql, (event_timestamp, event_title))
               lastEventTimestamp = event_timestamp
               
               #startTime=datetime.fromtimestamp(event_timestamp)
               #startTime=timezone('UTC').localize(startTime)
               #startTime=startTime.astimezone(timezone('Europe/Bucharest'))
               
               #endTime=l['e']/1000
               #endTime=datetime.fromtimestamp(endTime)
               #endTime=timezone('UTC').localize(endTime)
               #endTime=endTime.astimezone(tz_ro)
               
               #addon_log('starttt = '+str(event_timestamp))
               #addon_log('start = '+startTime.strftime('%Y-%m-%d %H:%M:%S'))
               
               startTime = datetime.fromtimestamp(event_timestamp, timezone('UTC'))
               
               addon_log(startTime.strftime('%Y-%m-%d %H:%M:%S'))
               #addon_log('end = '+endTime.strftime('%Y-%m-%d %H:%M:%S'))
               #addon_log(event_timestamp)
               addon_log(l['t'])
               
               
   
   # for k in schedule_json: #for every day
   #   if(len(schedule_json[k]['channels'])>0):
   #     for program in schedule_json[k]['channels'][0]["programs"]: #every program in a day
   #       event_title = program['title']
   #       start_datetime = re.sub('[\+-]+\d+:\d+$', '', program['start_datetime'])
   #       event_timestamp = time.mktime(time.strptime(start_datetime, "%Y-%m-%dT%H:%M:%S"))
   #       sql="INSERT INTO `%s` VALUES (?, ?)" % \
   #            (table_name)
   #       #st = db_cursor.execute(sql, (event_timestamp, unicode(event_title.replace("'", ""), 'iso-8859-2')))
   #       st = db_cursor.execute(sql, (event_timestamp, event_title))
 
 
 
 
   # match=re.compile(r'class="begin_time">(?P<time>.*?)</p>').search(schedule_txt)
   # if match:
   #   now_time=match.group('time')
   # else:
   #   now_time=""
   # #addon_log(now_time)
   # 
   # next_year = None
   # 
   # match_days=re.compile('<td style="vertical-align:top;text-align:center">\n*\s*<p class="date_box" style="margin-bottom:0px">\n*\s*<span>\n(?P<date>.*?)\n*\s*</span><br/>(?P<content>.*?)\n*\s*</table>\n*\s*</td>',re.DOTALL).findall(schedule_txt)
   # if match_days:
   #   i=1
   #   prev_event_day = None
   #   prev_event_month = None
   #   for date,content in match_days:
   #     date_obj = re.match( '.*? \((.*) (.*)\)', date)
   # 
   #     event_day=date_obj.group(1).zfill(2)
   #     event_month=month_name_to_no[date_obj.group(2)]
   #     event_year = dt_ro.year
   # 
   #     if (event_day == '01') and (event_month == '01') and (((i > 1) and (i < nr_days)) or (i > nr_days + 1)):
   #       next_year = event_year+1
   #     elif i == (nr_days + 1):
   #       next_year = None
   # 
   #     if next_year != None :
   #       event_year = next_year
   # 
   #     #addon_log(event_day + " " + event_month)
   # 
   #     if content:
   #       match_events_re=re.compile('btxt\" style=\"width:40px;margin:0px;padding:0px\">(?P<event_time>.*?)<.*?btxt\">(?P<event_title>.*?)</(?P<event_details>.*?)</td></tr>',re.DOTALL)
   #       match_events = match_events_re.findall(content)
   #     else:
   #       return False
   # 
   #     prev_event_hour = None
   #     if match_events:
   #       for event_time , event_title , event_details in match_events:
   #         if event_time == '':
   #           event_time=now_time
   # 
   #         event_hour=event_time.split(":")[0].zfill(2)
   #         event_minutes=event_time.split(":")[1]
   # 
   #         if (event_hour < prev_event_hour): #what is after midnight is moved to the next day
   #           next_day = datetime(int(event_year), int(event_month), int(event_day)) + timedelta(days = 1)
   #           #addon_log(next_day)
   #           prev_event_day = event_day
   #           prev_event_month = event_month
   #           event_day = next_day.strftime('%d')
   #           event_month = next_day.strftime('%m')
   # 
   # 
   #         #addon_log(event_day+" "+event_month+" "+str(prev_event_day)+" "+str(prev_event_month))
   #         if (event_day == '01') and (event_month == '01') and (prev_event_day == '31') and (prev_event_month=='12') and (event_year == dt_ro.year):
   #           event_year += 1
   #           prev_event_day = None
   #           prev_event_month = None
   # 
   #         event_timestamp = time.mktime(time.strptime(event_day+"-"+event_month+"-"+str(event_year)+" "+event_hour+":"+event_minutes, "%d-%m-%Y %H:%M"))
   # 
   #         #addon_log(event_time)
   #         #addon_log(event_day+" "+event_month+" "+str(event_year)+" "+event_hour+":"+event_minutes + " " + event_title)
   #         #addon_log(event_time + "  " + str(event_timestamp) + " " + event_title)
   # 
   #         sql="INSERT INTO `%s` VALUES (?, ?)" % \
   #              (table_name)
   #         st = db_cursor.execute(sql, (event_timestamp, unicode(event_title.replace("'", ""), 'iso-8859-2')))
   #         #addon_log(sql)
   # 
   #         prev_event_hour = event_hour
   # 
   #     prev_event_day = event_day
   #     prev_event_month = event_month
   # 
   #     i+=1
 
   db_connection.commit()
   db_connection.close()
Ejemplo n.º 43
0
 def ch_open(self):
     request_id = random.randint(1, 100)
     cmd = 'LOADASYNC ' + str(request_id) + ' PID ' + self.pid
     self.send(cmd)
     addon_log(cmd)
     return request_id
Ejemplo n.º 44
0
  def ace_read(self):
    for line in self.read_lines(self.sock):

      if ((self.start_time!=None) and ((time.time() - self.start_time) > self.timeout)):
        self.shutdown()
        xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30057), "", 10000))

      addon_log(line)
      if line.startswith("HELLOTS"):
        self.auth(line)
      elif line.startswith("AUTH"):
        self.request_id = self.ch_open()
      elif line.startswith("LOADRESP"):
        response = line.split()[2:]
        response = ' '.join(response)
        response = json.loads(response)

        if response.get('status') == 100:
          addon_log("LOADASYNC returned error with message: %s" % response.get('message'))
          xbmc.executebuiltin("Notification(%s,%s,%i)" % (response.get('message'), "", 10000))
          return False

        infohash = response.get('infohash')
        #self.sock.send('GETADURL width = 1328 height = 474 infohash = ' + infohash + ' action = load'+"\r\n")
        #self.sock.send('GETADURL width = 1328 height = 474 infohash = ' + infohash + ' action = pause'+"\r\n")

        self.filename = urllib.unquote(response.get('files')[0][0].encode('ascii')).decode('utf-8')
        addon_log(self.filename)
        self.ch_start()

      elif line.startswith("START"):
        self.start_time = None

        # try: xbmc.executebuiltin("Dialog.Close(all,true)")
        # except: pass

        try:
          player_url = line.split()[1]
          return player_url
          # addon_log (player_url)
          # self.player.callback = self.shutdown
          # self.listitem.setInfo('video', {'Title': self.filename})
          # self.player.play(player_url, self.listitem)
          # self.player_started = True
        except IndexError as e:
          player_url = None

        #p = re.compile('(http://)[\w\W]+?(\:[0-9]+/)')
        #player_url = url
        #player_url = p.sub(r"\1" + self.ace_host + r"\2", url)
        #addon_log (player_url)
        #self.player.play(player_url, self.listitem)

        #self.sock.send("PAUSE"+"\r\n")
        #self.sock.send("RESUME"+"\r\n")
        #self.sock.send("STOP"+"\r\n")
        #self.sock.send("SHUTDOWN"+"\r\n")

      elif line.startswith("SHUTDOWN"):
        self.sock.close()

        #offline notif
        #if player was not started
        #addon_log('player_started=');
        #addon_log(self.player_started);
        if(self.player_started != True):
          ch = Channels();
          ch.markStream(chId = self.player.ch_id, status=Channel.STATUS_OFFLINE) #offline

        break

      #INFO 1;Cannot find active peers
      elif line.startswith("INFO"):
        tmp = line.split(';')
        info_status = tmp[0].split()[1]
        if(info_status == '1'): #INFO 1;Cannot find active peers
          info_msg = tmp[1]
          self.shutdown()
          xbmc.executebuiltin("Notification(%s,%s,%i)" % (info_msg, "", 10000))

      elif line.startswith("EVENT"):
        #print line
        pass
Ejemplo n.º 45
0
      #play with acestream engine started on another machine or on the localhost
      ace = acestream(player=player, url=url, listitem=listitem)
      ace.engine_connect()
  else: #play direct stream
    try:
      player.play(url, listitem)
    except Exception as inst:
      xbmcgui.Dialog().ok(addon.getLocalizedString(30060), str(type(inst)),str(inst),"")
      # try: xbmc.executebuiltin("Dialog.Close(all,true)")
      # except: pass

#######################################################################################################################
#######################################################################################################################
#######################################################################################################################

addon_log('------------- START -------------')
# addon_log(SETTINGS.CHAN_LIST_URL)
# addon_log(SETTINGS.CHAN_LIST)

#read params
params=get_params()
try:
  mode=int(params["mode"])
except:
  mode=None
try:
  name=urllib.unquote_plus(params["name"].decode('utf8').encode('utf8'))
except:
  name=None
try:
  cat_id=urllib.unquote_plus(params["cat_id"].decode('utf8').encode('utf8'))
Ejemplo n.º 46
0
def grab_vk_stream(name, url):
    addon_log("play vk")
    temp = os.path.join(SETTINGS.ADDON_PATH, "temp.htm")
    addon_log(url)

    try:
        opener = urllib2.build_opener()
        opener.addheaders = [('User-agent', 'Mozilla/5.0')]
        response = opener.open(url)
        source_txt = response.read()
    except Exception as inst:
        source_txt = ""

    #Downloader(url, temp, addon.getLocalizedString(30065), name)  #Downloading page for parsing stream url
    #f = open(temp)
    #source_txt = f.read()
    #f.close()
    #os.remove(temp)

    #addon_log(source_txt)
    match = re.compile('url720=(http:\/\/[\w\W]+?.mp4?[\w\W]+?)&').search(
        source_txt)
    if match:
        stream_url = match.group(1)
        addon_log('720 = ' + stream_url)
        return stream_url

    match = re.compile('url480=(http:\/\/[\w\W]+?.mp4?[\w\W]+?)&').search(
        source_txt)
    if match:
        stream_url = match.group(1)
        addon_log('480 = ' + stream_url)
        return stream_url

    match = re.compile('url360=(http:\/\/[\w\W]+?.mp4?[\w\W]+?)&').search(
        source_txt)
    if match:
        stream_url = match.group(1)
        addon_log('360 = ' + stream_url)
        return stream_url

    match = re.compile('url240=(http:\/\/[\w\W]+?.mp4?[\w\W]+?)&').search(
        source_txt)
    if match:
        stream_url = match.group(1)
        addon_log('240 = ' + stream_url)
        return stream_url

    return None