Skip to content

Commit

Permalink
Merge pull request #57 from su1s/0.7-updates-dm
Browse files Browse the repository at this point in the history
0.7.3
  • Loading branch information
DougMac committed Mar 7, 2018
2 parents 7ea8413 + 63834c9 commit 965ffe9
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions e2m3u2bouquet.py
Expand Up @@ -12,6 +12,7 @@

import sys
import os
import errno
import re
import unicodedata
import datetime
Expand All @@ -38,9 +39,9 @@
from argparse import RawDescriptionHelpFormatter

__all__ = []
__version__ = '0.7.1'
__version__ = '0.7.3'
__date__ = '2017-06-04'
__updated__ = '2018-02-28'
__updated__ = '2018-03-07'

DEBUG = 0
TESTRUN = 0
Expand All @@ -65,12 +66,14 @@ def __str__(self):
def __unicode__(self):
return self.msg


class AppUrlOpener(urllib.FancyURLopener):
"""Set user agent for downloads"""
version = 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36'


class IPTVSetup:
def __init__(self):
def display_welcome(self):
# welcome message
print('\n********************************')
print('Starting Engima2 IPTV bouquets v{}'.format(__version__))
Expand Down Expand Up @@ -105,7 +108,8 @@ def uninstaller(self):
bakfile.close()
tvfile.close()
except Exception, e:
raise e
print('Unable to uninstall')
raise
print('----Uninstall complete----')

def download_m3u(self, url):
Expand All @@ -118,7 +122,8 @@ def download_m3u(self, url):
try:
urllib.urlretrieve(url, filename)
except Exception, e:
raise e
print('Unable to download m3u file from url')
raise
return filename

def download_providers(self, url):
Expand All @@ -139,7 +144,8 @@ def download_providers(self, url):
urllib.urlretrieve(url, filename)
return filename
except Exception, e:
raise e
print('Unable to download Github providers')
raise

def download_bouquet(self, url):
"""Download panel bouquet file from url"""
Expand All @@ -151,7 +157,8 @@ def download_bouquet(self, url):
try:
urllib.urlretrieve(url, filename)
except Exception, e:
raise e
print('Unable to download providers panel bouquet file')
raise
return filename

def parse_panel_bouquet(self, panel_bouquet_file):
Expand Down Expand Up @@ -193,7 +200,7 @@ def parse_m3u(self, filename, all_iptv_stream_types, tv_stream_type, vod_stream_
if not os.path.getsize(filename):
raise Exception("M3U file is empty. Check username & password")
except Exception, e:
raise e
raise

category_order = []
category_options = {}
Expand Down Expand Up @@ -602,8 +609,11 @@ def save_map_xml(self, categoryorder, category_options, dictchannels, list_xmltv
def download_picons(self, dictchannels, iconpath):
print('\n----Downloading Picon files, please be patient----')
print('If no Picons exist this will take a few minutes')
if not os.path.isdir(iconpath):
try:
os.makedirs(iconpath)
except OSError, e: # race condition guard
if e.errno != errno.EEXIST:
raise

for cat in dictchannels:
if not cat.startswith('VOD'):
Expand Down Expand Up @@ -916,8 +926,11 @@ def create_epgimporter_config(self, categoryorder, category_options, dictchannel
if DEBUG:
print('creating EPGImporter config')
# create channels file
if not os.path.isdir(EPGIMPORTPATH):
try:
os.makedirs(EPGIMPORTPATH)
except OSError, e: # race condition guard
if e.errno != errno.EEXIST:
raise
channels_filename = os.path.join(EPGIMPORTPATH, 'suls_iptv_{}_channels.xml'.format(self.get_safe_filename(provider)))

if dictchannels:
Expand Down Expand Up @@ -979,7 +992,7 @@ def read_providers(self, providerfile):
if not os.path.getsize(providerfile):
raise Exception('Providers file is empty')
except Exception, e:
raise e
raise
with open(providerfile, "r") as f:
for line in f:
if line == '400: Invalid request\n':
Expand Down Expand Up @@ -1183,6 +1196,7 @@ def run_e2m3u2bouquet(self, provider):
# Re-call ourselves
main(newargs)


def main(argv=None): # IGNORE:C0111
# Command line options.
if argv is None:
Expand Down Expand Up @@ -1249,7 +1263,6 @@ def main(argv=None): # IGNORE:C0111
help='Uninstall all changes made by this script')
parser.add_argument('-V', '--version', action='version', version=program_version_message)


# Process arguments
args = parser.parse_args()
m3uurl = args.m3uurl
Expand Down Expand Up @@ -1322,6 +1335,7 @@ def main(argv=None): # IGNORE:C0111
# # Core program logic starts here
urllib._urlopener = AppUrlOpener()
e2m3uSetup = IPTVSetup()
e2m3uSetup.display_welcome()
if uninstall:
# Clean up any existing files
e2m3uSetup.uninstaller()
Expand All @@ -1331,8 +1345,11 @@ def main(argv=None): # IGNORE:C0111
sys.exit(1) # Quit here if we just want to uninstall
else:
# create config folder if it doesn't exist
if not os.path.isdir(CFGPATH):
try:
os.makedirs(CFGPATH)
except OSError, e: # race condition guard
if e.errno != errno.EEXIST:
raise

# Work out provider based setup if that's what we have
if (provider is not None) and m3uurl is None and ((username is not None) or (password is not None)):
Expand Down Expand Up @@ -1370,7 +1387,7 @@ def main(argv=None): # IGNORE:C0111
# save xml mapping - should be after m3u parsing
e2m3uSetup.save_map_xml(categoryorder, category_options, dictchannels, list_xmltv_sources, provider)

#download picons
# Download picons
if picons:
e2m3uSetup.download_picons(dictchannels, iconpath)
# Create bouquet files
Expand Down

0 comments on commit 965ffe9

Please sign in to comment.