tarrac

Untitled

Jan 10th, 2023
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.14 KB | None | 0 0
  1. import xml.etree.ElementTree as ET
  2. with open('channel,xml', 'r', encoding='utf-8') as f:
  3.     xml = f.read()
  4. root = ET.fromstring(xml)
  5. channel = {}
  6.  
  7. with open('tmp.txt', 'a', encoding='utf-8') as f:
  8.  
  9.     for child in root[0]:
  10.         tmp_dict = {}
  11.         for child1 in child:
  12.             tmp_dict[child1.tag] = child1.text
  13.  
  14.         channel[tmp_dict['channelId']] = tmp_dict
  15.  
  16. tmp_guid = ''
  17. with open('old._tvguid.txt', 'r', encoding='utf-8') as f:
  18.     try:
  19.         for i in f.readlines():
  20.             if i.startswith('#EXT-INETRA-CHANNEL-INF:'):
  21.                 channel_id = i.split(' ')[1].split('=')[-1].strip()
  22.                 tmp_guid += i
  23.                 continue
  24.             elif i.startswith('#EXTINF'):
  25.                 m_text = i.split(',')
  26.                 url = '/'.join(['http://nsotelecom.ru/wp-content/uploads/2023/icon', channel[channel_id]['logoURL'].split('/')[-1]])
  27.                 tmp_guid += f'{m_text[0]} tvg-logo="{url}", {m_text[1].strip()}\n'
  28.             else:
  29.                 tmp_guid += i
  30.     except KeyError:
  31.         tmp_guid += i
  32. with open('nso-telecom.m3u8', 'a', encoding='utf-8') as f:
  33.     f.write(tmp_guid)
Add Comment
Please, Sign In to add comment