@@ -19,11 +19,11 @@ def rewrite_m3u_links_streaming(
1919 m3u_lines_iterator : Iterator [str ], base_url : str , api_password : Optional [str ]
2020) -> Iterator [str ]:
2121 """
22- Riscrive i link da un iteratore di linee M3U secondo le regole specificate ,
23- includendo gli headers da #EXTVLCOPT e #EXTHTTP. Yields rewritten lines.
22+ Rewrites links from an M3U line iterator according to the specified rules ,
23+ including headers from #EXTVLCOPT and #EXTHTTP. Yields rewritten lines.
2424 """
25- current_ext_headers : Dict [str , str ] = {} # Dizionario per conservare gli headers dalle direttive
26- current_kodi_props : Dict [str , str ] = {} # Dizionario per conservare le proprietà KODI
25+ current_ext_headers : Dict [str , str ] = {} # Dictionary to store headers from directives
26+ current_kodi_props : Dict [str , str ] = {} # Dictionary to store KODI properties
2727
2828 for line_with_newline in m3u_lines_iterator :
2929 line_content = line_with_newline .rstrip ("\n " )
@@ -49,11 +49,11 @@ def rewrite_m3u_links_streaming(
4949 header_value = header_value .strip ()
5050 current_ext_headers [header_key ] = header_value
5151 elif key_vlc .startswith ("http-" ):
52- # Gestisce http-user-agent, http-referer etc.
52+ # Handle http-user-agent, http-referer, etc.
5353 header_key = key_vlc [len ("http-" ) :]
5454 current_ext_headers [header_key ] = value_vlc
5555 except Exception as e :
56- logger .error (f"⚠️ Error parsing #EXTVLCOPT '{ logical_line } ': { e } " )
56+ logger .error (f"Error parsing #EXTVLCOPT '{ logical_line } ': { e } " )
5757
5858 elif logical_line .startswith ("#EXTHTTP:" ):
5959 # Yield the original line to preserve it
@@ -62,11 +62,11 @@ def rewrite_m3u_links_streaming(
6262 is_header_tag = True
6363 try :
6464 json_str = logical_line .split (":" , 1 )[1 ]
65- # Sostituisce tutti gli header correnti con quelli del JSON
65+ # Replace all current headers with those from the JSON
6666 current_ext_headers = json .loads (json_str )
6767 except Exception as e :
68- logger .error (f"⚠️ Error parsing #EXTHTTP '{ logical_line } ': { e } " )
69- current_ext_headers = {} # Resetta in caso di errore
68+ logger .error (f"Error parsing #EXTHTTP '{ logical_line } ': { e } " )
69+ current_ext_headers = {} # Reset on error
7070
7171 elif logical_line .startswith ("#KODIPROP:" ):
7272 # Yield the original line to preserve it
@@ -79,7 +79,7 @@ def rewrite_m3u_links_streaming(
7979 key_kodi , value_kodi = prop_str .split ("=" , 1 )
8080 current_kodi_props [key_kodi .strip ()] = value_kodi .strip ()
8181 except Exception as e :
82- logger .error (f"⚠️ Error parsing #KODIPROP '{ logical_line } ': { e } " )
82+ logger .error (f"Error parsing #KODIPROP '{ logical_line } ': { e } " )
8383
8484 if is_header_tag :
8585 continue
@@ -169,10 +169,10 @@ def rewrite_m3u_links_streaming(
169169 processed_url_content += header_params_str
170170 current_ext_headers = {}
171171
172- # Resetta le proprietà KODI dopo averle usate
172+ # Reset KODI properties after using them
173173 current_kodi_props = {}
174174
175- # Aggiungi api_password sempre alla fine
175+ # Always append api_password at the end
176176 if api_password :
177177 processed_url_content += f"&api_password={ api_password } "
178178
@@ -207,16 +207,16 @@ async def async_download_m3u_playlist(url: str) -> list[str]:
207207
208208def parse_channel_entries (lines : list [str ]) -> list [list [str ]]:
209209 """
210- Analizza le linee di una playlist M3U e le raggruppa in entry di canali .
211- Ogni entry è una lista di linee che compongono un singolo canale
212- (da #EXTINF fino all' URL, incluse le righe intermedie ).
210+ Parse the lines of an M3U playlist and group them into channel entries .
211+ Each entry is a list of lines that make up a single channel
212+ (from #EXTINF to the URL, including intermediate lines ).
213213 """
214214 entries = []
215215 current_entry = []
216216 for line in lines :
217217 stripped_line = line .strip ()
218218 if stripped_line .startswith ("#EXTINF:" ):
219- if current_entry : # In caso di #EXTINF senza URL precedente
219+ if current_entry : # In case of #EXTINF without a preceding URL
220220 logger .warning (
221221 f"Found a new #EXTINF tag before a URL was found for the previous entry. Discarding: { current_entry } "
222222 )
@@ -242,15 +242,15 @@ async def async_generate_combined_playlist(playlist_definitions: list[str], base
242242 should_sort = True
243243 definition = definition [len ("sort:" ) :]
244244
245- if definition .startswith ("no_proxy:" ): # Può essere combinato con sort:
245+ if definition .startswith ("no_proxy:" ): # Can be combined with sort:
246246 should_proxy = False
247247 playlist_url_str = definition [len ("no_proxy:" ) :]
248248 else :
249249 playlist_url_str = definition
250250
251251 download_tasks .append ({"url" : playlist_url_str , "proxy" : should_proxy , "sort" : should_sort })
252252
253- # Scarica tutte le playlist in parallelo
253+ # Download all playlists in parallel
254254 results = await asyncio .gather (
255255 * [async_download_m3u_playlist (task ["url" ]) for task in download_tasks ], return_exceptions = True
256256 )
@@ -293,29 +293,28 @@ def yield_header_once(lines_iter):
293293
294294 # 1. Processa e ordina le playlist marcate con 'sort'
295295 if sorted_playlist_lines :
296- # Estrai le entry dei canali
297- # Modifica: Estrai le entry e mantieni l'informazione sul proxy
296+ # Extract channel entries and keep proxy info
298297 channel_entries_with_proxy_info = []
299298 for idx , result in enumerate (results ):
300299 task_info = download_tasks [idx ]
301300 if task_info .get ("sort" ) and isinstance (result , list ):
302- entries = parse_channel_entries (result ) # result è la lista di linee della playlist
301+ entries = parse_channel_entries (result ) # result is the list of playlist lines
303302 for entry_lines in entries :
304- # L'opzione proxy si applica a tutto il blocco del canale
303+ # The proxy option applies to the entire channel block
305304 channel_entries_with_proxy_info .append ((entry_lines , task_info ["proxy" ]))
306305
307- # Ordina le entry in base al nome del canale (da #EXTINF)
308- # La prima riga di ogni entry è sempre #EXTINF
306+ # Sort entries by channel name (from #EXTINF)
307+ # The first line of each entry is always #EXTINF
309308 channel_entries_with_proxy_info .sort (key = lambda x : x [0 ][0 ].split ("," )[- 1 ].strip ())
310309
311- # Gestisci l' header una sola volta per il blocco ordinato
310+ # Handle the header only once for the sorted block
312311 if not first_playlist_header_handled :
313312 yield "#EXTM3U\n "
314313 first_playlist_header_handled = True
315314
316- # Applica la riscrittura dei link in modo selettivo
315+ # Apply link rewriting selectively
317316 for entry_lines , should_proxy in channel_entries_with_proxy_info :
318- # L' URL è l'ultima riga dell' entry
317+ # The URL is the last line of the entry
319318 url = entry_lines [- 1 ]
320319 # Yield tutte le righe prima dell'URL
321320 for line in entry_lines [:- 1 ]:
0 commit comments