Esempio n. 1
0
def create_xml_channels():
    log('{} {}'.format(provider, loc(32362)), xbmc.LOGNOTICE)
    if channel_format == 'rytec':
        ## Save tkm_channels.json to Disk
        tkm_channels_response = requests.get(tkm_channels_url).json()
        with open(tkm_channels_json, 'w') as tkm_channels:
            json.dump(tkm_channels_response, tkm_channels)
        tkm_channels.close()

    with open(magentaDE_chlist_selected, 'r') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32502), provider),
                   '{} {}'.format('100', loc(32501)))

    ## Create XML Channels Provider information
    xml_structure.xml_channels_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(
            100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        channel_name = user_item['name']
        channel_icon = user_item['pictures'][0]['href']
        channel_id = channel_name
        pDialog.update(
            int(percent_completed), '{} {} '.format(loc(32502), channel_name),
            '{} {} {}'.format(int(percent_remain), loc(32501), provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider, loc(32364)), xbmc.LOGNOTICE)

        ## Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format,
                                             tkm_channels_json,
                                             magentaDE_channels_warnings_tmp,
                                             lang)

        ## Create XML Channel Information with provided Variables
        xml_structure.xml_channels(channel_name, channel_id, channel_icon,
                                   lang)
    pDialog.close()
def create_xml_channels(grabber):
    provider_temppath, hzn_genres_json, hzn_channels_json, hzn_genres_warnings_tmp, hzn_genres_warnings, hzn_channels_warnings_tmp, hzn_channels_warnings, days_to_grab, episode_format, channel_format, genre_format, hzn_chlist_provider_tmp, hzn_chlist_provider, hzn_chlist_selected, provider, lang = get_settings(
        grabber)
    log('{} {}'.format(provider, loc(32362)), xbmc.LOGNOTICE)
    if channel_format == 'rytec':
        ## Save hzn_channels.json to Disk
        rytec_file = requests.get(hzn_channels_url).json()
        with open(hzn_channels_json, 'w', encoding='utf-8') as rytec_list:
            json.dump(rytec_file, rytec_list)

    with open(hzn_chlist_selected, 'r', encoding='utf-8') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32502), provider),
                   '{} {}'.format('100', loc(32501)))

    ## Create XML Channels Provider information
    xml_structure.xml_channels_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(
            100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        channel_name = user_item['name']
        channel_icon = user_item['pictures'][0]['href']
        channel_id = channel_name
        pDialog.update(
            int(percent_completed), '{} {} '.format(loc(32502), channel_name),
            '{} {} {}'.format(int(percent_remain), loc(32501), provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider, loc(32364)), xbmc.LOGNOTICE)

        ## Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format,
                                             hzn_channels_json,
                                             hzn_channels_warnings_tmp, lang)

        ## Create XML Channel Information with provided Variables
        xml_structure.xml_channels(channel_name, channel_id, channel_icon,
                                   lang)
    pDialog.close()
Esempio n. 3
0
def create_xml_broadcast(enable_rating_mapper):
    download_broadcastfiles()
    log('{} {}'.format(provider, loc(32365)), xbmc.LOGNOTICE)
    if genre_format == 'eit':
        ## Save tkm_genres.json to Disk
        tkm_genres_response = requests.get(tkm_genres_url).json()
        with open(tkm_genres_json, 'w') as tkm_genres:
            json.dump(tkm_genres_response, tkm_genres)
        tkm_genres.close()

    with open(magentaDE_chlist_selected, 'r') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32503), provider),
                   '{} Prozent verbleibend'.format('100'))

    ## Create XML Broadcast Provider information
    xml_structure.xml_broadcast_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(
            100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        contentID = user_item['contentId']
        channel_name = user_item['name']
        channel_id = channel_name
        pDialog.update(
            int(percent_completed), '{} {} '.format(loc(32503), channel_name),
            '{} {} {}'.format(int(percent_remain), loc(32501), provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider, loc(32366)), xbmc.LOGNOTICE)

        broadcast_files = os.path.join(provider_temppath,
                                       '{}_broadcast.json'.format(contentID))
        with open(broadcast_files, 'r') as b:
            broadcastfiles = json.load(b)

        ### Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format,
                                             tkm_channels_json,
                                             magentaDE_channels_warnings_tmp,
                                             lang)

        try:
            for playbilllist in broadcastfiles['playbilllist']:
                try:
                    item_title = playbilllist['name']
                except (KeyError, IndexError):
                    item_title = ''
                try:
                    item_starttime = playbilllist['starttime']
                except (KeyError, IndexError):
                    item_starttime = ''
                try:
                    item_endtime = playbilllist['endtime']
                except (KeyError, IndexError):
                    item_endtime = ''
                try:
                    item_description = playbilllist['introduce']
                except (KeyError, IndexError):
                    item_description = ''
                try:
                    item_country = playbilllist['country']
                except (KeyError, IndexError):
                    item_country = ''
                try:
                    item_picture = playbilllist['pictures'][1]['href']
                except (KeyError, IndexError):
                    item_picture = ''
                try:
                    item_subtitle = playbilllist['subName']
                except (KeyError, IndexError):
                    item_subtitle = ''
                try:
                    items_genre = playbilllist['genres']
                except (KeyError, IndexError):
                    items_genre = ''
                try:
                    item_date = playbilllist['producedate']
                except (KeyError, IndexError):
                    item_date = ''
                try:
                    item_season = playbilllist['seasonNum']
                except (KeyError, IndexError):
                    item_season = ''
                try:
                    item_episode = playbilllist['subNum']
                except (KeyError, IndexError):
                    item_episode = ''
                try:
                    item_agerating = playbilllist['ratingid']
                except (KeyError, IndexError):
                    item_agerating = ''
                try:
                    items_director = playbilllist['cast']['director']
                except (KeyError, IndexError):
                    items_director = ''
                try:
                    items_producer = playbilllist['cast']['producer']
                except (KeyError, IndexError):
                    items_producer = ''
                try:
                    items_actor = playbilllist['cast']['actor']
                except (KeyError, IndexError):
                    items_actor = ''

                # Transform items to Readable XML Format
                if not item_date == '':
                    item_date = item_date.split('-')
                    item_date = item_date[0]
                if (not item_starttime == '' and not item_endtime == ''):
                    start = item_starttime.split(' UTC')
                    item_starttime = start[0].replace(' ', '').replace(
                        '-', '').replace(':', '')
                    stop = item_endtime.split(' UTC')
                    item_endtime = stop[0].replace(' ', '').replace(
                        '-', '').replace(':', '')
                if not item_country == '':
                    item_country = item_country.upper()
                if item_agerating == '-1':
                    item_agerating = ''

                # Map Genres
                if not items_genre == '':
                    items_genre = mapper.map_genres(
                        items_genre, genre_format, tkm_genres_json,
                        magentaDE_genres_warnings_tmp, lang)

                ## Create XML Broadcast Information with provided Variables
                xml_structure.xml_broadcast(
                    episode_format, channel_id, item_title, item_starttime,
                    item_endtime, item_description, item_country, item_picture,
                    item_subtitle, items_genre, item_date, item_season,
                    item_episode, item_agerating, items_director,
                    items_producer, items_actor, enable_rating_mapper, lang)

        except (KeyError, IndexError):
            log('{} {} {} {} {} {}'.format(provider, loc(32367), channel_name,
                                           loc(32368), contentID, loc(32369)))
    pDialog.close()

    ## Create Channel Warnings Textile
    channel_pull = '\n' + 'Please Create an Pull Request for Missing Rytec Id´s to https://github.com/sunsettrack4/config_files/blob/master/tkm_channels.json' + '\n'
    mapper.create_channel_warnings(magentaDE_channels_warnings_tmp,
                                   magentaDE_channels_warnings, provider,
                                   channel_pull)

    ## Create Genre Warnings Textfile
    genre_pull = '\n' + 'Please Create an Pull Request for Missing EIT Genres to https://github.com/sunsettrack4/config_files/blob/master/tkm_genres.json' + '\n'
    mapper.create_genre_warnings(magentaDE_genres_warnings_tmp,
                                 magentaDE_genres_warnings, provider,
                                 genre_pull)

    notify(addon_name,
           '{} {} {}'.format(loc(32370), provider, loc(32371)),
           icon=xbmcgui.NOTIFICATION_INFO)
    log('{} {} {}'.format(loc(32370), provider, loc(32371), xbmc.LOGNOTICE))
    xbmc.sleep(4000)

    if (os.path.isfile(magentaDE_channels_warnings)
            or os.path.isfile(magentaDE_genres_warnings)):
        notify(provider,
               '{}'.format(loc(32372)),
               icon=xbmcgui.NOTIFICATION_WARNING)
        xbmc.sleep(3000)

    ## Delete old Tempfiles, not needed any more
    for file in os.listdir(provider_temppath):
        xbmcvfs.delete(os.path.join(provider_temppath, file))
Esempio n. 4
0
def create_xml_broadcast(grabber, enable_rating_mapper):
    provider_temppath, hzn_genres_json, hzn_channels_json, hzn_genres_warnings_tmp, hzn_genres_warnings, hzn_channels_warnings_tmp, hzn_channels_warnings, days_to_grab, episode_format, channel_format, genre_format, hzn_chlist_provider_tmp, hzn_chlist_provider, hzn_chlist_selected, provider, lang = get_settings(grabber)
    hzndict = get_hzndict(grabber)
    download_broadcastfiles(grabber, hzn_chlist_selected, provider, provider_temppath, hzndict, days_to_grab)
    log('{} {}'.format(provider,loc(32365)), xbmc.LOGNOTICE)
    if genre_format == 'eit':
        ## Save hzn_genres.json to Disk
        genres_file = requests.get(hzn_genres_url).json()
        with open(hzn_genres_json, 'w') as genres_list:
            json.dump(genres_file, genres_list)
        genres_list.close()

    with open(hzn_chlist_selected, 'r') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32503),provider), '{} Prozent verbleibend'.format('100'))

    ## Create XML Broadcast Provider information
    xml_structure.xml_broadcast_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        contentID = user_item['contentId']
        channel_name = user_item['name']
        channel_id = channel_name
        pDialog.update(int(percent_completed), '{} {} '.format(loc(32503),channel_name),'{} {} {}'.format(int(percent_remain),loc(32501),provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider,loc(32366)), xbmc.LOGNOTICE)

        broadcast_files = os.path.join(provider_temppath, '{}_broadcast.json'.format(contentID))
        with open(broadcast_files, 'r') as b:
            broadcastfiles = json.load(b)

        ### Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format, hzn_channels_json, hzn_channels_warnings, lang)

        try:
            for playbilllist in broadcastfiles['listings']:
                try:
                    item_title = playbilllist['program']['title']
                except (KeyError, IndexError):
                    item_title = ''
                try:
                    item_starttime = playbilllist['startTime']
                except (KeyError, IndexError):
                    item_starttime = ''
                try:
                    item_endtime = playbilllist['endTime']
                except (KeyError, IndexError):
                    item_endtime = ''
                try:
                    item_description = playbilllist['program']['longDescription']
                except (KeyError, IndexError):
                    item_description = ''
                try:
                    item_picture = 'https://www.staticwhich.co.uk/static/images/products/no-image/no-image-available.png'
                    found = False
                    asset_types = ['HighResPortrait', 'boxart-xlarge', 'boxart-large', 'boxart-medium', 'tva-poster', 'tva-boxcover']
                    for asset_type in asset_types:
                        for i in range(0, len(playbilllist['program']['images'])):
                            if playbilllist['program']['images'][i]['assetType'] == asset_type:
                                item_picture = playbilllist['program']['images'][i]['url']
                                found = True
                                break
                        if found: break
                    item_picture = item_picture.split('?w')
                    item_picture = item_picture[0]
                except (KeyError, IndexError):
                    item_picture = 'https://www.staticwhich.co.uk/static/images/products/no-image/no-image-available.png'
                try:
                    item_subtitle = playbilllist['program']['secondaryTitle']
                except (KeyError, IndexError):
                    item_subtitle = ''
                genres_list = list()
                try:
                    genre_1 = playbilllist['program']['categories'][0]['title'].replace(',','')
                    genres_list.append(genre_1)
                except (KeyError, IndexError):
                    genre_1 = ''
                try:
                    genre_2 = playbilllist['program']['categories'][1]['title'].replace(',','')
                    genres_list.append(genre_2)
                except (KeyError, IndexError):
                    genre_2 = ''
                try:
                    genre_3 = playbilllist['program']['categories'][2]['title'].replace(',','')
                    genres_list.append(genre_3)
                except (KeyError, IndexError):
                    genre_3 = ''
                try:
                    items_genre = ','.join(genres_list)
                except (KeyError, IndexError):
                    items_genre = ''
                try:
                    item_date = playbilllist['program']['year']
                except (KeyError, IndexError):
                    item_date = ''
                try:
                    item_season = playbilllist['program']['seriesNumber']
                except (KeyError, IndexError):
                    item_season = ''
                try:
                    item_episode = playbilllist['program']['seriesEpisodeNumber']
                except (KeyError, IndexError):
                    item_episode = ''
                try:
                    item_agerating = playbilllist['program']['parentalRating']
                except (KeyError, IndexError):
                    item_agerating = ''
                try:
                    items_director = ','.join(playbilllist['program']['directors'])
                except (KeyError, IndexError):
                    items_director = ''
                try:
                    items_actor = ','.join(playbilllist['program']['cast'])
                except (KeyError, IndexError):
                    items_actor = ''

                # Transform items to Readable XML Format
                item_country = ''
                items_producer = ''
                if item_agerating == '-1':
                    item_agerating = ''

                if not item_season == '':
                    if int(item_season) >999:
                        item_season = ''
                if not item_episode == '':
                    if int(item_episode) >99999:
                        item_episode = ''

                item_starttime = datetime.utcfromtimestamp(item_starttime / 1000).strftime('%Y%m%d%H%M%S')
                item_endtime = datetime.utcfromtimestamp(item_endtime / 1000).strftime('%Y%m%d%H%M%S')

                # Map Genres
                if not items_genre == '':
                    items_genre = mapper.map_genres(items_genre, genre_format, hzn_genres_json, hzn_genres_warnings_tmp, lang)

                ## Create XML Broadcast Information with provided Variables
                xml_structure.xml_broadcast(episode_format, channel_id, item_title, str(item_starttime), str(item_endtime),
                                            item_description, item_country, item_picture, item_subtitle, items_genre,
                                            item_date, item_season, item_episode, item_agerating, items_director,
                                            items_producer, items_actor, enable_rating_mapper, lang)

        except (KeyError, IndexError):
            log('{} {} {} {} {} {}'.format(provider,loc(32367),channel_name,loc(32368),contentID,loc(32369)))
    pDialog.close()

    ## Create Channel Warnings Textile
    channel_pull = '\n' + 'Please Create an Pull Request for Missing Rytec Id´s to https://github.com/sunsettrack4/config_files/blob/master/hzn_channels.json' + '\n'
    mapper.create_channel_warnings(hzn_channels_warnings_tmp, hzn_channels_warnings, provider, channel_pull)

    ## Create Genre Warnings Textfile
    genre_pull = '\n' + 'Please Create an Pull Request for Missing EIT Genres to https://github.com/sunsettrack4/config_files/blob/master/hzn_genres.json' + '\n'
    mapper.create_genre_warnings(hzn_genres_warnings_tmp, hzn_genres_warnings, provider, genre_pull)

    notify(addon_name, '{} {} {}'.format(loc(32370),provider,loc(32371)), icon=xbmcgui.NOTIFICATION_INFO)
    log('{} {} {}'.format(loc(32370),provider,loc(32371), xbmc.LOGNOTICE))
    xbmc.sleep(4000)

    if (os.path.isfile(hzn_channels_warnings) or os.path.isfile(hzn_genres_warnings)):
        notify(provider, '{}'.format(loc(32372)), icon=xbmcgui.NOTIFICATION_WARNING)
        xbmc.sleep(3000)

    ## Delete old Tempfiles, not needed any more
    for file in os.listdir(provider_temppath): xbmcvfs.delete(os.path.join(provider_temppath, file))
def create_xml_broadcast(enable_rating_mapper, thread_temppath,
                         download_threads):

    download_multithread(thread_temppath, download_threads)
    log('{} {}'.format(provider, loc(32365)), xbmc.LOGNOTICE)

    if genre_format == 'eit':
        ## Save hzn_genres.json to Disk
        genres_file = requests.get(swcCH_genres_url).json()
        with open(swcCH_genres_json, 'w', encoding='utf-8') as genres_list:
            json.dump(genres_file, genres_list)

    with open(swcCH_chlist_selected, 'r', encoding='utf-8') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32503), provider),
                   '{} Prozent verbleibend'.format('100'))

    ## Create XML Broadcast Provider information
    xml_structure.xml_broadcast_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(
            100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        contentID = user_item['contentId']
        channel_name = user_item['name']
        channel_id = channel_name
        pDialog.update(
            int(percent_completed), '{} {} '.format(loc(32503), channel_name),
            '{} {} {}'.format(int(percent_remain), loc(32501), provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider, loc(32366)), xbmc.LOGNOTICE)

        broadcast_files = os.path.join(provider_temppath,
                                       '{}_broadcast.json'.format(contentID))
        with open(broadcast_files, 'r', encoding='utf-8') as b:
            broadcastfiles = json.load(b)

        ### Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format,
                                             swcCH_channels_json,
                                             swcCH_channels_warnings_tmp, lang)

        try:
            for playbilllist in broadcastfiles['Nodes']['Items'][0]['Content'][
                    'Nodes']['Items']:
                try:
                    item_title = playbilllist['Content']['Description'][
                        'Title']
                except (KeyError, IndexError):
                    item_title = ''
                try:
                    item_starttime = playbilllist['Availabilities'][0][
                        'AvailabilityStart']
                except (KeyError, IndexError):
                    item_starttime = ''
                try:
                    item_endtime = playbilllist['Availabilities'][0][
                        'AvailabilityEnd']
                except (KeyError, IndexError):
                    item_endtime = ''
                try:
                    item_description = playbilllist['Content']['Description'][
                        'Summary']
                except (KeyError, IndexError):
                    item_description = ''
                try:
                    url = playbilllist['Content']['Nodes']['Items'][0][
                        'ContentPath']
                    item_picture = 'https://services.sg1.etvp01.sctv.ch/content/images{}_w1920.png'.format(
                        url)
                except (KeyError, IndexError):
                    item_picture = ''
                try:
                    item_subtitle = playbilllist['Content']['Description'][
                        'Subtitle']
                except (KeyError, IndexError):
                    item_subtitle = ''
                try:
                    items_genre = ''
                    found = False
                    role = ['Genre']
                    for genre in role:
                        for i in range(0, len(playbilllist['Relations'])):
                            if playbilllist['Relations'][i]['Role'] == genre:
                                items_genre = playbilllist['Relations'][i][
                                    'TargetIdentifier']
                                found = True
                                break
                        if found: break
                except (KeyError, IndexError):
                    items_genre = ''
                try:
                    item_date = playbilllist['Content']['Description'][
                        'ReleaseDate']
                except (KeyError, IndexError):
                    item_date = ''
                try:
                    item_country = playbilllist['Content']['Description'][
                        'Country']
                except (KeyError, IndexError):
                    item_country = ''
                try:
                    item_season = playbilllist['Content']['Series']['Season']
                except (KeyError, IndexError):
                    item_season = ''
                try:
                    item_episode = playbilllist['Content']['Series']['Episode']
                except (KeyError, IndexError):
                    item_episode = ''
                try:
                    item_agerating = playbilllist['Content']['Description'][
                        'AgeRestrictionRating']
                except (KeyError, IndexError):
                    item_agerating = ''
                try:
                    item_starrating = playbilllist['Content']['Description'][
                        'Rating']
                except (KeyError, IndexError):
                    item_starrating = ''
                try:
                    items_director = ''
                    found = False
                    role = ['Director']
                    for director in role:
                        for i in range(0, len(playbilllist['Relations'])):
                            if playbilllist['Relations'][i][
                                    'Role'] == director:
                                items_director_fn = playbilllist['Relations'][
                                    i]['TargetNode']['Content']['Description'][
                                        'FirstName']
                                items_director_ln = playbilllist['Relations'][
                                    i]['TargetNode']['Content']['Description'][
                                        'LastName']
                                items_director = '{} {}'.format(
                                    items_director_fn, items_director_ln)
                                found = True
                                break
                        if found: break
                except (KeyError, IndexError):
                    items_director = ''
                try:
                    actor_list = list()
                    items_actor = ''
                    found = False
                    role = ['Actor']
                    for actor in role:
                        for i in range(0, len(playbilllist['Relations'])):
                            if playbilllist['Relations'][i]['Role'] == actor:
                                items_actor_fn = playbilllist['Relations'][i][
                                    'TargetNode']['Content']['Description'][
                                        'FirstName']
                                items_actor_ln = playbilllist['Relations'][i][
                                    'TargetNode']['Content']['Description'][
                                        'LastName']
                                item_actor = '{} {}'.format(
                                    items_actor_fn, items_actor_ln)
                                actor_list.append(item_actor)
                                found = True
                        if found: break
                    items_actor = ','.join(actor_list)
                except (KeyError, IndexError):
                    items_actor = ''

                # Transform items to Readable XML Format
                if not item_agerating == '':
                    item_agerating = re.sub(r"\D+", '#',
                                            item_agerating).split('#')[0]
                if not item_date == '':
                    item_date = item_date.split('-')[0]
                items_producer = ''

                if (not item_starttime == '' and not item_endtime == ''):
                    item_starttime = re.sub(r"\D+", '', item_starttime)
                    item_endtime = re.sub(r"\D+", '', item_endtime)

                # Map Genres
                if not items_genre == '':
                    items_genre = mapper.map_genres(items_genre, genre_format,
                                                    swcCH_genres_json,
                                                    swcCH_genres_warnings_tmp,
                                                    lang)

                ## Create XML Broadcast Information with provided Variables
                xml_structure.xml_broadcast(
                    episode_format,
                    channel_id, item_title, str(item_starttime),
                    str(item_endtime), item_description, item_country,
                    item_picture, item_subtitle, items_genre, item_date,
                    item_season, item_episode, item_agerating, item_starrating,
                    items_director, items_producer, items_actor,
                    enable_rating_mapper, lang)

        except (KeyError, IndexError):
            log('{} {} {} {} {} {}'.format(provider, loc(32367), channel_name,
                                           loc(32368), contentID, loc(32369)))
    pDialog.close()

    ## Create Channel Warnings Textile
    channel_pull = '\nPlease Create an Pull Request for Missing Rytec Id´s to https://github.com/sunsettrack4/config_files/blob/master/tvs_channels.json\n'
    mapper.create_channel_warnings(swcCH_channels_warnings_tmp,
                                   swcCH_channels_warnings, provider,
                                   channel_pull)

    ## Create Genre Warnings Textfile
    genre_pull = '\nPlease Create an Pull Request for Missing EIT Genres to https://github.com/sunsettrack4/config_files/blob/master/tvs_genres.json\n'
    mapper.create_genre_warnings(swcCH_genres_warnings_tmp,
                                 swcCH_genres_warnings, provider, genre_pull)

    notify(addon_name,
           '{} {} {}'.format(loc(32370), provider, loc(32371)),
           icon=xbmcgui.NOTIFICATION_INFO)
    log('{} {} {}'.format(loc(32370), provider, loc(32371), xbmc.LOGNOTICE))

    if (os.path.isfile(swcCH_channels_warnings)
            or os.path.isfile(swcCH_genres_warnings)):
        notify(provider,
               '{}'.format(loc(32372)),
               icon=xbmcgui.NOTIFICATION_WARNING)

    ## Delete old Tempfiles, not needed any more
    for file in os.listdir(provider_temppath):
        xbmcvfs.delete(os.path.join(provider_temppath, file))
Esempio n. 6
0
def create_xml_broadcast(enable_rating_mapper, thread_temppath,
                         download_threads):

    download_multithread(thread_temppath, download_threads)
    log('{} {}'.format(provider, loc(32365)), xbmc.LOGNOTICE)

    if genre_format == 'eit':
        ## Save tvsDE_genres.json to Disk
        tvsDE_genres_response = requests.get(tvsDE_genres_url).json()
        with open(tvsDE_genres_json, 'w', encoding='utf-8') as tvsDE_genres:
            json.dump(tvsDE_genres_response, tvsDE_genres)

    with open(tvsDE_chlist_selected, 'r', encoding='utf-8') as c:
        selected_list = json.load(c)

    items_to_download = str(len(selected_list['channellist']))
    items = 0
    pDialog = xbmcgui.DialogProgressBG()
    pDialog.create('{} {} '.format(loc(32503), provider),
                   '{} Prozent verbleibend'.format('100'))

    ## Create XML Broadcast Provider information
    xml_structure.xml_broadcast_start(provider)

    for user_item in selected_list['channellist']:
        items += 1
        percent_remain = int(
            100) - int(items) * int(100) / int(items_to_download)
        percent_completed = int(100) * int(items) / int(items_to_download)
        contentID = user_item['contentId']
        contentID = channel_hack(contentID)
        channel_name = user_item['name']
        channel_id = channel_name
        pDialog.update(
            int(percent_completed), '{} {} '.format(loc(32503), channel_name),
            '{} {} {}'.format(int(percent_remain), loc(32501), provider))
        if str(percent_completed) == str(100):
            log('{} {}'.format(provider, loc(32366)), xbmc.LOGNOTICE)

        broadcast_files = os.path.join(provider_temppath,
                                       '{}_broadcast.json'.format(contentID))
        with open(broadcast_files, 'r', encoding='utf-8') as b:
            broadcastfiles = json.load(b)

        ### Map Channels
        if not channel_id == '':
            channel_id = mapper.map_channels(channel_id, channel_format,
                                             tvsDE_channels_json,
                                             tvsDE_channels_warnings_tmp, lang)

        try:
            for days in broadcastfiles['broadcasts']:
                for playbilllist in days:
                    try:
                        item_title = playbilllist['title']
                    except (KeyError, IndexError):
                        item_title = ''
                    try:
                        item_starttime = playbilllist['timestart']
                    except (KeyError, IndexError):
                        item_starttime = ''
                    try:
                        item_endtime = playbilllist['timeend']
                    except (KeyError, IndexError):
                        item_endtime = ''
                    try:
                        item_description = playbilllist['text']
                    except (KeyError, IndexError):
                        item_description = ''
                    try:
                        item_country = playbilllist['country']
                    except (KeyError, IndexError):
                        item_country = ''
                    try:
                        item_picture = playbilllist['images'][0]['size4']
                    except (KeyError, IndexError):
                        item_picture = ''
                    try:
                        item_subtitle = playbilllist['episodeTitle']
                    except (KeyError, IndexError):
                        item_subtitle = ''
                    try:
                        items_genre = playbilllist['genre']
                    except (KeyError, IndexError):
                        items_genre = ''
                    try:
                        item_date = playbilllist['year']
                    except (KeyError, IndexError):
                        item_date = ''
                    try:
                        item_season = playbilllist['seasonNumber']
                    except (KeyError, IndexError):
                        item_season = ''
                    try:
                        item_episode = playbilllist['episodeNumber']
                    except (KeyError, IndexError):
                        item_episode = ''
                    try:
                        item_agerating = playbilllist['fsk']
                    except (KeyError, IndexError):
                        item_agerating = ''
                    try:
                        items_director = playbilllist['director']
                    except (KeyError, IndexError):
                        items_director = ''
                    try:
                        actor_list = list()
                        keys_actor = playbilllist['actors']
                        for actor in keys_actor:
                            actor_list.append(list(actor.values())[0])
                        items_actor = ','.join(actor_list)
                    except (KeyError, IndexError):
                        items_actor = ''

                    # Transform items to Readable XML Format
                    item_starrating = ''
                    item_starttime = datetime.utcfromtimestamp(
                        item_starttime).strftime('%Y%m%d%H%M%S')
                    item_endtime = datetime.utcfromtimestamp(
                        item_endtime).strftime('%Y%m%d%H%M%S')

                    if not item_episode == '':
                        item_episode = re.sub(r"\D+", '#',
                                              item_episode).split('#')[0]
                    if not item_season == '':
                        item_season = re.sub(r"\D+", '#',
                                             item_season).split('#')[0]

                    items_producer = ''
                    if item_description == '':
                        item_description = 'No Program Information available'

                    # Map Genres
                    if not items_genre == '':
                        items_genre = mapper.map_genres(
                            items_genre, genre_format, tvsDE_genres_json,
                            tvsDE_genres_warnings_tmp, lang)

                    ## Create XML Broadcast Information with provided Variables
                    xml_structure.xml_broadcast(
                        episode_format, channel_id, item_title, item_starttime,
                        item_endtime, item_description, item_country,
                        item_picture, item_subtitle, items_genre, item_date,
                        item_season, item_episode, item_agerating,
                        item_starrating, items_director, items_producer,
                        items_actor, enable_rating_mapper, lang)

        except (KeyError, IndexError):
            log('{} {} {} {} {} {}'.format(provider, loc(32367), channel_name,
                                           loc(32368), contentID, loc(32369)))
    pDialog.close()

    ## Create Channel Warnings Textile
    channel_pull = '\nPlease Create an Pull Request for Missing Rytec Id´s to https://github.com/sunsettrack4/config_files/blob/master/tvs_channels.json\n'
    mapper.create_channel_warnings(tvsDE_channels_warnings_tmp,
                                   tvsDE_channels_warnings, provider,
                                   channel_pull)

    ## Create Genre Warnings Textfile
    genre_pull = '\nPlease Create an Pull Request for Missing EIT Genres to https://github.com/sunsettrack4/config_files/blob/master/tvs_genres.json\n'
    mapper.create_genre_warnings(tvsDE_genres_warnings_tmp,
                                 tvsDE_genres_warnings, provider, genre_pull)

    notify(addon_name,
           '{} {} {}'.format(loc(32370), provider, loc(32371)),
           icon=xbmcgui.NOTIFICATION_INFO)
    log('{} {} {}'.format(loc(32370), provider, loc(32371), xbmc.LOGNOTICE))

    if (os.path.isfile(tvsDE_channels_warnings)
            or os.path.isfile(tvsDE_genres_warnings)):
        notify(provider,
               '{}'.format(loc(32372)),
               icon=xbmcgui.NOTIFICATION_WARNING)

    ## Delete old Tempfiles, not needed any more
    for file in os.listdir(provider_temppath):
        xbmcvfs.delete(os.path.join(provider_temppath, file))