Ejemplo n.º 1
0
def CHANNEL_LIST(name, cat_id, mode=None, schedule=False):
  if(mode == 1):
    #add new channel link
    liz=xbmcgui.ListItem('[B][COLOR green]'+addon.getLocalizedString(30402)+'[/COLOR][/B]', iconImage="DefaultVideo.png", thumbnailImage=iconimage)
    liz.setInfo( type="Video", infoLabels={ "Title": name } )
    liz.setProperty('IsPlayable', 'false')
    url = sys.argv[0] + "?mode=6&cat_id=" + cat_id
    xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=url,listitem=liz)

  loadUnverified = False 
  if((mode!=None) and (int(mode)==101)):
    loadUnverified = True

  channels = Channels(catId = cat_id)
  arrChannels = channels.loadChannels(loadUnverified)
  for ch in arrChannels:
    if (((SETTINGS.SHOW_OFFLINE_CH=='true') and (int(ch.status)==ch.STATUS_OFFLINE)) or (int(ch.status)!=ch.STATUS_OFFLINE)): #if we show or not offline channels based on settings
      if (ch.my == 1): 
        name_formatted = "[I]%s[/I]" % ch.name
      else:
        name_formatted = "[B]%s[/B]" % ch.name
      name_formatted += " [[COLOR yellow]%s[/COLOR]]" % ch.protocol
       
      if int(ch.status)==ch.STATUS_OFFLINE: 
        name_formatted += " [COLOR red]%s[/COLOR]" % addon.getLocalizedString(30063)  #Offline
      
      addLink(ch.id, name_formatted, ch.name, ch.address.strip(), ch.protocol.strip(),
              ch.id_cat, 2, '', "", len(arrChannels))
Ejemplo n.º 2
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.º 3
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.º 4
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.º 5
0
Archivo: default.py Proyecto: teosan5/0
def addLink(ch_id, name_formatted, name, url, protocol, schedule_ch_id,
            cat_name, cat_id, mode, iconimage, plot, totalitems):
    name = name.encode('utf8')
    cat_name = cat_name.encode('utf8')
    ok = True
    contextMenuItems = []

    if SETTINGS.DISABLE_SCHEDULE != 'true':
        u = sys.argv[0] + "?mode=3&name=" + urllib.quote_plus(name)
        if schedule_ch_id != "0":
            u += "&sch_ch_id=" + urllib.quote_plus(schedule_ch_id)
        contextMenuItems.append((
            addon.getLocalizedString(30050),
            "XBMC.RunPlugin(" + u + ")",
        ))  #Refresh Schedule

        u = sys.argv[0] + "?mode=5&name=" + urllib.quote_plus(
            cat_name) + "&cat_id=" + cat_id
        contextMenuItems.append((
            addon.getLocalizedString(30051),
            "XBMC.RunPlugin(" + u + ")",
        ))  #Refresh All Schedules

        #u=sys.argv[0]+"?mode=6"
        #contextMenuItems.append(( 'EPG', "XBMC.RunPlugin("+u+")", )) #EPG

    u = sys.argv[0] + "?mode=4"
    contextMenuItems.append((
        addon.getLocalizedString(30052),
        "XBMC.RunPlugin(" + u + ")",
    ))  #Refresh Channel List

    liz = xbmcgui.ListItem(name_formatted,
                           iconImage="DefaultVideo.png",
                           thumbnailImage=iconimage)
    liz.setInfo(type="Video", infoLabels={"Title": name, "Plot": plot})

    u=sys.argv[0]+"?"+"url="+urllib.quote_plus(url)+"&mode="+str(mode)+\
                           "&name="+urllib.quote_plus(name)+\
                           "&iconimage="+urllib.quote_plus(iconimage)+\
                           "&cat_id="+cat_id+"&protocol="+protocol+\
                           "&ch_id="+str(ch_id)
    if schedule_ch_id != "0":
        u += "&sch_ch_id=" + urllib.quote_plus(schedule_ch_id)

    liz.addContextMenuItems(contextMenuItems)

    ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),
                                     url=u,
                                     listitem=liz,
                                     isFolder=False)
    return ok
Ejemplo n.º 6
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)")
Ejemplo n.º 7
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.º 8
0
def addLink(ch_id, name_formatted, name, url, protocol, cat_id, mode, iconimage, plot, totalitems):
  name = name.encode('utf8')
  #cat_name = cat_name.encode('utf8')
  ok = True
  contextMenuItems = []

  #if SETTINGS.DISABLE_SCHEDULE != 'true':
    #u=sys.argv[0]+"?mode=3&name="+urllib.quote_plus(name)
    #if schedule_ch_id != "0":
      #u+="&sch_ch_id="+urllib.quote_plus(schedule_ch_id)
    #contextMenuItems.append(( addon.getLocalizedString(30050), "XBMC.RunPlugin("+u+")", )) #Refresh Schedule

    #u=sys.argv[0]+"?mode=5&name="+urllib.quote_plus(cat_name)+"&cat_id="+cat_id
    #contextMenuItems.append(( addon.getLocalizedString(30051), "XBMC.RunPlugin("+u+")", )) #Refresh All Schedules

    #u=sys.argv[0]+"?mode=6"
    #contextMenuItems.append(( 'EPG', "XBMC.RunPlugin("+u+")", )) #EPG

  u=sys.argv[0]+"?mode=4"
  contextMenuItems.append(( addon.getLocalizedString(30052), "XBMC.RunPlugin("+u+")", )) #Refresh Channel List
  
  u=sys.argv[0]+"?mode=7&ch_id=" + str(ch_id)
  contextMenuItems.append(( addon.getLocalizedString(30407), "XBMC.RunPlugin("+u+")", )) #Delete Channel

  liz = xbmcgui.ListItem(name_formatted, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
  liz.setInfo( type="Video", infoLabels={ "Title": name, "Plot": plot} )

  u = sys.argv[0] + "?url=%s&mode=%s&name=%s&cat_id=%s&protocol=%s&ch_id=%s" % ( urllib.quote_plus(url),
      str(mode), 
      urllib.quote_plus(name), 
      cat_id, 
      protocol, 
      str(ch_id) )
  
  liz.addContextMenuItems(contextMenuItems)

  ok = xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
  return ok
Ejemplo n.º 9
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.º 10
0
  def addChannel(self):
    kb = xbmc.Keyboard('', addon.getLocalizedString(30403))

    #url
    kb.doModal()
    if (kb.isConfirmed()):
      url = kb.getText()
      if url == '' : sys.exit(0)
      else:
        #protocol
        m = re.search('^(\w+)://', url)
        if(m):
          protocol = m.group(1)
        else:
          xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30406), "", 1))
          sys.exit(0)

        #name
        kb = xbmc.Keyboard('', addon.getLocalizedString(30404))
        kb.doModal()
        if (kb.isConfirmed()):
          name = kb.getText()
          name = name.title()
          if name == '' : sys.exit(0)
          else:
            #save
            ch = Channel(id_cat = self.catId, address = url, name=name, protocol=protocol, status=Channel.STATUS_ONLINE, my=1)
            if(ch.save() == False):
              xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30408), "", 1))
              xbmc.executebuiltin("Container.Refresh")
            xbmc.executebuiltin("Notification(%s,%s,%i)" % (addon.getLocalizedString(30405), "", 1))
            xbmc.executebuiltin("Container.Refresh")
        else:
          xbmc.executebuiltin("Container.Refresh")
    else:
      xbmc.executebuiltin("Container.Refresh")
Ejemplo n.º 11
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.º 12
0
 def contextmenu(self, sys):
     title = self.item['title'].encode('utf-8','ignore')
     menu = []
     # info
     menu.append((addon.getLocalizedString(30906), 'XBMC.Action(Info)'))
     # add smartlist
     try:
         if self.item['genre'][0]:
             genre = self.item['genre'][0].split('/')
         else:
             genre = ['','']
     except:
         genre = ['','']
     url1 = 'ch=%s&genre0=%s&genre1=%s' % (self.item['ch'], genre[0], genre[1])
     menu.append((addon.getLocalizedString(30903),
                  'XBMC.RunPlugin(%s?mode=61&name=%s&url=%s)' % (sys.argv[0],urllib.quote_plus(title),urllib.quote_plus(url1))))
     # favorite
     if settings['favorite'] == 'true':
         url2 = 'gtvid=%s&rank=1' % (self.item['gtvid'])
         url3 = 'gtvid=%s&rank=0' % (self.item['gtvid'])
         if self.item['favorite'] == '0':
             # add
             action = 'XBMC.RunPlugin(%s?mode=20&name=%s&url=%s)' % (sys.argv[0],urllib.quote_plus(title),urllib.quote_plus(url2))
             menu.append((addon.getLocalizedString(30925), action))
         else:
             # delete
             action = 'XBMC.RunPlugin(%s?mode=20&name=%s&url=%s)' % (sys.argv[0],urllib.quote_plus(title),urllib.quote_plus(url3))
             menu.append((addon.getLocalizedString(30926), action))
     # download
     if settings['download'] == 'true':
         url4 = 'gtvid=%s' % (self.item['gtvid'])
         json = os.path.join(DOWNLOAD_PATH, self.item['gtvid']+'.js')
         if os.path.isfile(json):
             # add
             action = 'XBMC.RunPlugin(%s?mode=31&name=%s&url=%s)' % (sys.argv[0],urllib.quote_plus(title),urllib.quote_plus(url4))
             menu.append((addon.getLocalizedString(30930), action))
         else:
             # delete
             action = 'XBMC.RunPlugin(%s?mode=30&name=%s&url=%s)' % (sys.argv[0],urllib.quote_plus(title),urllib.quote_plus(url4))
             menu.append((addon.getLocalizedString(30929), action))
     # return to top
     menu.append((addon.getLocalizedString(30936),'XBMC.Container.Update(%s,replace)' % (sys.argv[0])))
     return menu
Ejemplo n.º 13
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.º 14
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.º 15
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
Ejemplo n.º 16
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.º 17
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.º 18
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.º 19
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
Ejemplo n.º 20
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]
                    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):
                    mark = mark_stream(ch_id=self.player.ch_id)
                    mark.mark_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.º 21
0
def query2desc(query):

    params = {'sdate':None, 'ch':None, 'genre0':None, 'genre1':None, 's':None}
    lines = []

    # parse query
    for q in query.split('&'):
        (key, value) = q.split('=')
        params[key] = value

    # date
    if params['sdate'] is None:
        pass
    elif params['sdate'] == '':
        lines.append('%s:%s' % (addon.getLocalizedString(30907),addon.getLocalizedString(30912))) #日付:すべての日付
    else:
        lines.append('%s:%s' % (addon.getLocalizedString(30907),str(params['sdate']).split(' ')[0])) #日付:*

    # channel
    if params['ch'] is None:
        pass
    elif params['ch'] == '':
        lines.append('%s:%s' % (addon.getLocalizedString(30908),addon.getLocalizedString(30913))) #チャンネル:すべてのチャンネル
    else:
        lines.append('%s:%s' % (addon.getLocalizedString(30908),Channel().search(params['ch'])['name'])) #チャンネル:*

    # genre
    if params['genre0'] is None:
        pass
    elif params['genre0'] == '':
        lines.append('%s:%s' % (addon.getLocalizedString(30909),addon.getLocalizedString(30914))) #ジャンル:すべてのジャンル
    else:
        # subgenre
        if params['genre1'] is None:
            pass
        elif params['genre1'] == '':
            lines.append('%s:%s' % (addon.getLocalizedString(30909),Genre().search(params['genre0'])['name0'])) #ジャンル:*
        else:
            lines.append('%s:%s' % (addon.getLocalizedString(30909),Genre().search(params['genre0'],params['genre1'])['name1'])) #ジャンル:*

    # search
    if params['s'] is None:
        pass
    elif params['s'] == 'e':
        lines.append('%s:%s' % (addon.getLocalizedString(30911),addon.getLocalizedString(30901))) #検索対象:EPG
    elif params['s'] == 'c':
        lines.append('%s:%s' % (addon.getLocalizedString(30911),addon.getLocalizedString(30902))) #検索対象:字幕

    # join lines
    return '\n'.join(lines)
Ejemplo n.º 22
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