ó
®ˆ#\c        
   @   sš  d  d l  Z  d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m	 Z	 d  d l
 m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z m Z d  d l m Z d  d l m Z d  d l m Z d  d	 l m Z m  Z  d  d l! Z! y. d  d l" j# j$ j$ Z$ d  d l% j# j$ j& Z& Wn e' k
 rod Z$ d Z& n Xd a) d a* i  Z+ e ƒ  e j _, e d
 d ƒ e j j, _- e d
 e. ƒ e j j, _/ e d
 e. ƒ e j j, _0 e d
 d d d d g ƒ e j j, _1 e d
 d d d d d d d ƒ e j j, _2 e d
 d ƒ e j j, _3 e d
 e. ƒ e j j, _4 e d
 d d d d d d d d g ƒ e j j, _5 e ƒ  e j j, _6 e d
 e. ƒ e j j, _7 e d
 e. ƒ e j j, _8 e d
 e9 ƒ e j j, _: e d
 d ƒ e j j, _; e d
 d ƒ e j j, _< e d
 d ƒ e j j, _= e d
 d ƒ e j j, _> e d
 d ƒ e j j, _? e d
 d ƒ e j j, _@ e d
 d ƒ e j j, _A e d
 d ƒ e j j, _B e d
 d ƒ e j j, _C e d
 d ƒ e j j, _D e d
 d ƒ e j j, _E d e jF f d „  ƒ  YZG d d> d  „  ƒ  YZH d d! „ ZI d d" „ ZJ d# „  ZK d$ „  ZL e. d d% „ ZM d& „  ZN d' „  ZO d( „  ZP d) „  ZQ d* „  ZR d+ „  ZS d, „  ZT d d- „ ZU d. „  ZV d/ „  ZW d0 „  ZX d1 „  ZY d2 „  ZZ d3 „  Z[ d4 „  Z\ d5 Z] d6 Z^ d7 GHe d8 e] d9 e^ d: e j_ d; eX ƒ Z` e d8 e] d9 e^ d: e j_ d; eY ƒ Za e d8 e] d9 e^ d: e jb d; eW ƒ Zc e j j, j7 jd e[ d< e. ƒe j j, j8 jd e\ d< e. ƒd= „  Ze d S(?   iÿÿÿÿN(   t   E2m3u2b_Menu(   t   E2m3u2b_Check(   t   eTimer(   t   configt   ConfigEnableDisablet   ConfigSubsectiont   ConfigYesNot   ConfigClockt   getConfigListEntryt
   ConfigTextt   ConfigSelectiont   ConfigNumbert   ConfigSubDictt   NoSavet   ConfigPasswordt   ConfigSelectionNumber(   t
   MessageBox(   t   PluginDescriptor(   t   plugins(   t   reactort   threadst   defaultt    t   intervalt   choicess
   fixed timei   t   mini   t   maxi0   t	   stepwidthi   i    s   /usr/share/enigma2/picon/s   /media/usb/picon/s   /media/hdd/picon/s   /media/cf/picon/s   /media/mmc/picon/s   /picon/t   AppUrlOpenerc           B   s   e  Z d  Z d Z RS(   s!   Set user agent for downloads
    sf   Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36(   t   __name__t
   __module__t   __doc__t   version(    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR   H   s   t   AutoStartTimerc           B   s5   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s9   | |  _  t ƒ  |  _ |  j j j |  j ƒ |  j ƒ  d  S(   N(   t   sessionR   t   timert   callbackt   appendt   on_timert   update(   t   selfR"   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   __init__O   s    	c         C   s&  t  d IJt j j j j rt j j j j d k rn t t j j j j ƒ } t	 j	 ƒ  } t | ƒ | d d St j j j j d k r"t j j j
 j } t	 j t	 j	 ƒ  ƒ } t t	 j | j | j | j | d | d | j | j | j | j f	 ƒ ƒ } d t	 j t	 j | ƒ ƒ f GH| Sn d Sd  S(	   Ns)   [e2m3u2b] AutoStartTimer -> get_wake_timeR   i<   s
   fixed timei    i   s   fixed schedule time: iÿÿÿÿ(   t   logR   R   t   e2m3u2bt   autobouquetupdatet   valuet   scheduletypet   intt   updateintervalt   timet   schedulefixedtimet	   localtimet   mktimet   tm_yeart   tm_mont   tm_mdayt   tm_sect   tm_wdayt   tm_ydayt   tm_isdstt   asctime(   R(   R   t   nowtt   fixed_time_clockt   nowt   fixed_wake_time(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   get_wake_timeU   s    
"+c         C   s!  t  d IJ|  j j ƒ  |  j ƒ  } t j ƒ  } t | ƒ } | d k rÝ | | k rÀ t j j j	 j
 d k r˜ t t j j j j
 ƒ } | | d d 7} qÀ t j j j	 j
 d k rÀ | d
 7} qÀ n  | | } |  j j | ƒ n d } t  d j t j t j | ƒ ƒ t j t j | ƒ ƒ ƒ IJ| S(   Ns"   [e2m3u2b] AutoStartTimer -> updatei    R   i<   s
   fixed timei   iÿÿÿÿs'   [e2m3u2b] next wake up time {} (now={})i  i€Q (   R*   R#   t   stopRA   R1   R/   R   R   R+   R.   R-   R0   t   startLongTimert   formatR<   R3   (   R(   t   wakeR=   R?   R   t	   next_wake(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR'   i   s"    

:c         C   sÓ   |  j  j ƒ  t t j ƒ  ƒ } | } t d j | ƒ IJt d IJt j j j	 j
 d k ri |  j ƒ  } n  | | d k  rÅ y t ƒ  WqÅ t k
 rÁ } t d I| IJt j j j j
 rÂ ‚  qÂ qÅ Xn  |  j ƒ  d  S(   Ns    [e2m3u2b] on_timer occured at {}sP   [e2m3u2b] Stating bouquet update because auto update bouquet schedule is enableds
   fixed timei<   s   [e2m3u2b] on_timer Error:(   R#   RB   R/   R1   R*   RD   R   R   R+   R.   R-   RA   t   start_updatet	   Exceptiont   debugR'   (   R(   R?   RE   t   e(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR&   ‚   s    
c         C   s   t  d IJd  S(   Ns%   [e2m3u2b] AutoStartTimer -> getStatus(   R*   (   R(   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt
   get_status–   s    (   R   R   R)   RA   R'   R&   RK   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR!   N   s
   				c         C   s$  d GHt  j ƒ  } t j j t j j t  j d ƒ ƒ r | j t j j t  j d ƒ ƒ g  } g  } xƒ | j j	 ƒ  D]r \ } } | j
 rp | j j d ƒ rp | j | ƒ t j j t  j d j t  j | j ƒ ƒ ƒ } | j | ƒ qp qp Wt j t | | ƒ } | j t | t t j ƒ  ƒ |  ƒ n  d S(   s   Run m3u channel update
    s   start_update calleds
   config.xmls   Supplier Names   suls_iptv_{}.sources.xmlN(   t   e2m3u2bouquett   Configt   ost   patht   isfilet   joint   CFGPATHt   read_configt	   providerst	   iteritemst   enabledt   namet
   startswithR%   t   EPGIMPORTPATHRD   t   get_safe_filenameR   t   deferToThreadt   start_process_providerst   addCallbackt   start_update_callbackR/   R1   (   t	   epgimportt   e2m3u2b_configt   providers_to_processt   epgimport_sourcefilest   keyt   provider_configt   epgimport_sourcefilenamet   d(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyRG   š   s    $c         C   sñ   t  t j ƒ  ƒ | } d j t | ƒ ƒ } | t j _ t d j | ƒ IJt rí t	 j
 j j j t k rí | d  k r• t j t j j ƒ  d „  ƒ } n  g  t | ƒ D] } | ^ q¢ } | j ƒ  | | _ t | _ | j d t j ƒ  d	 ƒ n  d  S(
   Ns   Finished bouquet update in {}ss   [e2m3u2b] {}c         S   s   t  S(   N(   t   True(   t   x(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   <lambda>º   s    t   longDescUntili   i   i  ix   i€— (   R/   R1   RD   t   strRL   t   Statust   messageR*   t	   EPGImportR   R   R+   t   do_epgimportR-   Rg   t   Nonet   enigmat	   eEPGCachet   getInstancet   epgimport_sourcest   reverset   sourcest   epgimport_donet   onDonet   beginImport(   t   resultRb   t
   start_timeR_   t   elapsed_secst   msgt   sRv   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR^   ±   s    !
		c         C   s$  t  } x· |  D]¯ } t j | ƒ } t t j ƒ  ƒ t | j j ƒ d k rY | j ƒ  } n  | j j s€ t j	 j
 j j | j _ n  t d j | j j ƒ IJ| j ƒ  t d j | j j ƒ IJq W| rÓ | j ƒ  n  t j t j t j ƒ  ƒ ƒ } | t j	 j
 j _ t j	 j
 j j ƒ  t j ƒ  d  S(   Ni`T  s$   [e2m3u2b] Starting backend script {}s$   [e2m3u2b] Finished backend script {}(   t   FalseRL   t   ProviderR/   R1   R   t   last_provider_updatet   provider_updatet	   icon_pathR   R+   t   iconpathR-   R*   RD   RW   t   process_providert   write_configR<   R3   t   last_updatet   savet   reload_bouquets(   Ra   R`   t   providers_updatedRd   t   providerR3   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR\   Ã   s     (
c         c   sj   xc |  D][ } y# x t  j | ƒ D] } | Vq  WWq t k
 ra } t d I| Id I| IJq Xq Wd  S(   Ns%   [e2m3u2b] Failed top open epg source s    Error: (   t	   EPGConfigt   enumSourcesFileRH   R*   (   t   sourcefilest
   sourcefileR~   RJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyRt   Þ   s    c         C   s   t  d IJd  S(   Ns'   [e2m3u2b] Automatic epg import finished(   R*   (   t   reboott   epgfile(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyRw   ç   s    c           C   s   d GHt  j ƒ  t  j ƒ  d S(   sV   Reset bouquets and
    epg importer config by running the script uninstall method
    s   do_reset calledN(   RL   t   uninstallerR‰   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   do_resetë   s    
c         K   sG   t  ƒ  t _ t ƒ  t ƒ  t s9 |  j t |  ƒ t ƒ n
 t |  ƒ d  S(   N(	   R   t   urllibt
   _urlopenert   check_cfg_foldert   set_default_do_epgimportRn   t   openWithCallbackt	   open_menuR   (   R"   t   kwargs(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   mainô   s    c           C   sD   t  j j j j d k r@ t t  j j j _ t  j j j j ƒ  n  d  S(   Nt   1(   R   R   R+   t   cfglevelR-   R   Ro   Rˆ   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR—      s    c         C   s   |  j  t ƒ d  S(   N(   t   openR    (   R"   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR™     s    c          C   sk   y t  j t j ƒ WnP t k
 rf }  |  j t j k rg t d I|  IJt j	 j
 j j rc ‚  qc qg n Xd S(   s+   Make config folder if it doesn't exist
    s&   [e2m3u2b] unable to create config dir:N(   RN   t   makedirsRL   RR   t   OSErrort   errnot   EEXISTR*   R   R   R+   RI   R-   (   RJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR–     s    c           C   s'   t  d IJt d k	 r# t j ƒ  n  d S(   s/   Check for new config values for auto start
    s   [e2m3u2b] Done configuringN(   R*   t   autoStartTimerRp   R'   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   done_configuring  s    
c          C   si   t  t j ƒ  ƒ }  t d IJy t ƒ  Wn; t k
 rd } t d I| IJt j j j j	 re ‚  qe n Xd S(   sT   This will only execute if the
    config option autobouquetupdateatboot is true
    sM   [e2m3u2b] Stating bouquet update because auto update bouquet at start enableds$   [e2m3u2b] on_boot_start_check Error:N(
   R/   R1   R*   RG   RH   R   R   R+   RI   R-   (   R?   RJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   on_boot_start_check  s    
c         K   s¤   t  ƒ  t _ t ƒ  t d j |  t j ƒ  ƒ IJ|  d k r– t d  k r– | d  k	 r  | a t	 d  k rt t
 | ƒ a	 n  t j j j j r“ t ƒ  q“ q  n
 t d IJd  S(   Ns$   [e2m3u2b] autostart {} occured at {}i    s   [e2m3u2b] stop(   R   R”   R•   R—   R*   RD   R1   t   _sessionRp   R£   R!   R   R   R+   t   autobouquetupdateatbootR-   R¥   (   t   reasonR"   Rš   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt	   autostart.  s    c           C   s   t  d IJd S(   Ns   [e2m3u2b] get_next_wakeupiÿÿÿÿ(   R*   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   get_next_wakeupB  s    
c         C   s#   |  d k r t  t t  d f g Sg  S(   s"    Called whenever a menu is createdt   mainmenui-   (   t   plugin_namet   quick_import_menu(   t   menuid(    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   menuHookH  s    c         K   s   t  |  |  d S(   s.    Needed for the extension menu descriptor
    N(   R›   (   R"   Rš   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   extensions_menuO  s    c      	   K   s)   |  j  t t d t j d d d t ƒd  S(   NsD   Update of channels will start.
This may take a few minutes.
Proceed?t   timeouti   R   (   R˜   t   quick_import_callbackR   t
   TYPE_YESNORg   (   R"   Rš   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR­   U  s    	c         C   sW   |  s
 d  Sy t  ƒ  Wn; t k
 rR } t d I| IJt j j j j rS ‚  qS n Xd  S(   Ns'   [e2m3u2b] manual_update_callback Error:(   RG   RH   R*   R   R   R+   RI   R-   (   t	   confirmedRJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyR²   \  s    c         C   s^   t  d IJy* |  j r& t j t ƒ n t j t ƒ Wn# t k
 rY } t  d I| IJn Xd  S(   Ns    [e2m3u2b] update extensions menus,   [e2m3u2b] Failed to update extensions menu: (   R*   R-   R   t	   addPlugint   extDescriptorQuickt   removePluginRH   (   t   cfg_elRJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   update_extensions_menug  s    
	c         C   s^   t  d IJy* |  j r& t j t ƒ n t j t ƒ Wn# t k
 rY } t  d I| IJn Xd  S(   Ns   [e2m3u2b] update main menus&   [e2m3u2b] Failed to update main menu: (   R*   R-   R   Rµ   t   extDescriptorQuickMainR·   RH   (   R¸   RJ   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   update_main_menur  s    
	s   IPTV Bouquet Makers'   IPTV for Enigma2 - E2m3u2bouquet plugins   [e2m3u2b] add notifierRW   t   descriptiont   wheret   fnct   initial_callc          K   s¥   t  d t d t d t  j t  j g d t d t ƒ t  d t d t d t  j d d d t ƒ g } t	 j
 j j j r | j t ƒ n  t	 j
 j j j r¡ | j t ƒ n  | S(   NRW   R¼   R½   R¾   t	   wakeupfnct   icons   images/e2m3ubouquetlogo.png(   R   R¬   t   plugin_descriptiont   WHERE_AUTOSTARTt   WHERE_SESSIONSTARTR©   Rª   t   WHERE_PLUGINMENUR›   R   R   R+   t
   extensionsR-   R%   R¶   R«   Rº   (   Rš   Rz   (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   Plugins†  s$    	(    (f   R1   RN   R¡   Rq   R*   R”   t   menuR    R   R   t   Components.configR   R   R   R   R   R   R	   R
   R   R   R   R   R   t   Screens.MessageBoxR   t   Plugins.PluginR   t   Components.PluginComponentR   t   twisted.internetR   R   RL   t&   Plugins.Extensions.EPGImport.EPGImportt
   ExtensionsRn   t&   Plugins.Extensions.EPGImport.EPGConfigRŒ   t   ImportErrorRp   R£   R¦   t   providers_listR+   R   R   RI   R,   R.   R0   R2   R§   R„   R‡   RÆ   R«   Rg   Ro   t   providernamet   usernamet   passwordt	   iptvtypest   multivodt
   bouquetpost
   allbouquett   piconst   srefoverridet   bouquetdownloadR   t   FancyURLopenerR   R!   RG   R^   R\   Rt   Rw   R“   R›   R—   R™   R–   R¤   R¥   R©   Rª   R¯   R°   R­   R²   R¹   R»   R¬   RÂ   t   WHERE_EXTENSIONSMENUt   extDescriptorR¶   t
   WHERE_MENURº   t   addNotifierRÇ   (    (    (    sB   /usr/lib/enigma2/python/Plugins/Extensions/E2m3u2bouquet/plugin.pyt   <module>   s¨   X
$*L																		
$$$