When I am running this on linux I am getting this error. I have given my code down there,
Traceback (most recent call last):
File "C:\Users\Egon\Documents\EgonTv\TV2.py", line 81, in load_list
self.media = self.vlc_instance.media_new(pl[self.current_Ch][1])
IndexError: list index out of range
Traceback (most recent call last):
File "c:\users\egon\documents\egontv\tv2.py", line 72, in load_list
line = f.readline()
File "c:\users\egon\documents\egontv\tv2.py", line 72, in load_list
line = f.readline()
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Traceback (most recent call last):
File "c:\users\egon\documents\egontv\tv2.py", line 70, in load_list
pl.append([ch,url])
File "c:\users\egon\documents\egontv\tv2.py", line 70, in load_list
pl.append([ch,url])
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Traceback (most recent call last):
File "c:\users\egon\documents\egontv\tv2.py", line 67, in load_list
while line:
File "c:\users\egon\documents\egontv\tv2.py", line 67, in load_list
while line:
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Traceback (most recent call last):
File "c:\users\egon\documents\egontv\tv2.py", line 70, in load_list
pl.append([ch,url])
File "c:\users\egon\documents\egontv\tv2.py", line 70, in load_list
pl.append([ch,url])
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
Traceback (most recent call last):
File "c:\users\egon\documents\egontv\tv2.py", line 67, in load_list
while line:
File "c:\users\egon\documents\egontv\tv2.py", line 67, in load_list
while line:
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 88, in trace_dispatch
return self.dispatch_line(frame)
File "C:\ProgramData\Anaconda3\lib\bdb.py", line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit
and this is the code
import sys
import vlc
import os
from PyQt5 import uic
from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog
from PyQt5.QtCore import QAbstractListModel, QModelIndex, Qt, QItemSelectionModel
from ErrorLogger import *
import traceback
pl = []
channel_list = []
def handle_error(error):
'''Handles exceptions by logging their tracebacks and displaying a critical QMessageBox.'''
ErrorLogger.WriteError(traceback.format_exc())
QtWidgets.QMessageBox.critical(None, 'Exception raised', format(error))
class ProgramList(QAbstractListModel):
def __init__(self, parent=None):
super(ProgramList, self).__init__(parent)
self.list = channel_list
def rowCount(self, parent=QModelIndex()):
return len(self.list)
def data(self, index, role = Qt.DisplayRole):
if role == Qt.DisplayRole:
channel_name = self.list[index.row()]
return channel_name
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
try:
uic.loadUi(r"TV2.ui", self)
self.vlc_instance = vlc.Instance()
self.mediaplayer = self.vlc_instance.media_player_new()
self.pushButtonForward.clicked.connect(self.next_channel)
self.pushButtonBack.clicked.connect(self.last_channel)
self.pushButtonClose.clicked.connect(lambda: [self.mediaplayer.stop(), self.close()])
self.pushButtonFullScreen.clicked.connect(lambda: [self.showFullScreen(), self.frameControl.hide(),
self.statusBar().showMessage('right mouse click on screen below edge to minimize') ])
self.pushButtonLoadList.clicked.connect(self.load_list)
except Exception as e:
self.mediaplayer.stop()
handle_error(e)
def load_list(self):
pl.clear()
channel_list.clear()
self.mediaplayer.stop()
try:
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
tvList, _ = QFileDialog.getOpenFileName(None, "Chose a m3u file", "",
"m3u file *.m3u", options=options)
if tvList:
f = open(tvList, encoding="utf8")
line = f.readline()
# while line:
# ch = line.split(',')[1].strip()
# url = line.split(',')[0].strip()
# pl.append([ch,url])
# line = f.readline()
# f.close()
while line:
if "#EXTINF:" in line:
ch = line.split(',')[1].strip()
url = f.readline().strip()
pl.append([ch,url])
line = f.readline()
f.close()
for chs in pl:
channel_list.append(chs[0])
self.current_Ch = 0
self.lastChannel = len(pl)-1
self.mediaplayer.set_hwnd(int(self.frameTv.winId()))
self.media = self.vlc_instance.media_new(pl[self.current_Ch][0])
self.mediaplayer.set_media(self.media)
self.media.get_mrl()
self.mediaplayer.play()
self.statusBar().showMessage('Wait, loading can take a while', 5000)
self.pl_model = ProgramList()
self.listView.setModel(self.pl_model)
first = self.pl_model.index(0, 0)
self.listView.setCurrentIndex(first)
self.listView.selectionModel().selectionChanged.connect(self.change_channel)
else:
QtWidgets.QMessageBox.critical(None, 'No Channel', 'No channels could be found' )
except Exception as e: handle_error(e)
def change_channel(self):
try:
channel_row = self.listView.currentIndex().row()
self.current_Ch = channel_row
self.media = self.vlc_instance.media_new(pl[channel_row][1])
self.mediaplayer.set_media(self.media)
self.media.get_mrl()
self.mediaplayer.play()
except Exception as e: handle_error(e)
def next_channel(self):
try:
self.current_Ch += 1
if self.current_Ch > self.lastChannel:
self.current_Ch = 0
index = self.pl_model.index(self.current_Ch, 0)
self.listView.setCurrentIndex(index)
self.media = self.vlc_instance.media_new(pl[self.current_Ch][1])
self.mediaplayer.set_media(self.media)
self.media.get_mrl()
self.mediaplayer.play()
except Exception as e: handle_error(e)
def last_channel(self):
self.current_Ch -= 1
if self.current_Ch < 0:
self.current_Ch = self.lastChannel
index = self.pl_model.index(self.current_Ch, 0)
self.listView.setCurrentIndex(index)
self.media = self.vlc_instance.media_new(pl[self.current_Ch][1])
self.mediaplayer.set_media(self.media)
self.media.get_mrl()
self.mediaplayer.play()
def closeEvent(self, event):
self.mediaplayer.stop()
# def mouseDoubleClickEvent(self,event):
# if self.isFullScreen():
# self.showNormal()
# self.setCursor (self.cursor())
# self.frameControl.show()
def contextMenuEvent(self, event):
if self.isFullScreen():
self.showNormal()
self.setCursor (self.cursor())
self.frameControl.show()
self.statusBar().clearMessage()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())
>Solution :
It looks like you are using a Windows file system path on a Linux machine. Both are different in their syntax. You will have to rewrite the paths. Assuming this program works on a Windows machine. That is the error. https://en.wikipedia.org/wiki/File_system
I don’t think there is any real work around for this issue without rewriting the file paths. You are giving the OS a file path it doesn’t recognize, but windows does.