A old version of python is needed, when we run some scripts written by python2.7, so it is essential to install this version. Please run these commands respectively:

conda create --name python2 python=2.7
activate python2
conda install anaconda

When you wanna use it, this command is commended:

activate python2

We have got a list of channels of IPTV and these television programs can be watched by inputting URL into software VLC manually. It is a cumbersome work to deal with, so a good idea has been hit on that we can produce a programme in VLC to make us find a channel and watch it conveniently.

The files you need to prepare:

url.txt

http://iptv.pdsu.edu.cn/hls/cctv1.m3u8
http://iptv.pdsu.edu.cn/hls/cctv1hd.m3u8
http://iptv.pdsu.edu.cn/hls/cctv2.m3u8
http://iptv.pdsu.edu.cn/hls/cctv2hd.m3u8
http://iptv.pdsu.edu.cn/hls/cctv3.m3u8
...

jm.txt

CCTV-1综合
CCTV-1高清
CCTV-2财经
CCTV-2高清
CCTV-3综艺
CCTV-3高清
...

The script to produce a .m3u8 file:

#!/usr/bin/env python
# encoding:utf-8
#Anaconda is recommended for users.
#The script is used to produce a .m3u8 file to watch TV
import tkinter as tk
import matplotlib.pyplot as plt
from tkinter import filedialog
def select_inputfile():
    root = tk.Tk()
    root.withdraw()
    filepath = filedialog.askopenfilename(title=u'Input File',filetypes=[('txt file', '.txt')])
    print('input path:',filepath)
    return filepath
print('Please input url file')
url_path = select_inputfile()
print('Please input programme file')
jm_path = select_inputfile()
file1 = open(url_path)
file2 = open(jm_path)
url = file1.readlines()
jm = file2.readlines()
lines1 = len(url)
lines2 = len(jm)
if lines1 == lines2:
    with open("TV.m3u8",'a+',encoding = 'utf8') as f:
        f.write('#EXTM3U'+'\n')
    f.close()
    for line in range(lines1):
        with open("TV.m3u8",'a+',encoding = 'utf8') as f:
            f.write('#EXTINF:0,'+jm[line].strip('\n')+'\n'+'#EXTVLCOPT:network-caching=1000'+'\n')
            f.write(url[line].strip('\n')+'\n')
        f.close()
file1.close()
file2.close()
print('Work done!')
#.m3u8 format
#--------------------------------
##EXTM3U
##EXTINF:0,TV_channel_name
##EXTVLCOPT:network-caching=1000
#http://....your_url

It will produce a file named "TV.m3u8" and you can input it at "Media Library" in VLC.

Last modified: 2020年3月30日

Comments

Write a Reply or Comment

Your email address will not be published.