Skip to content

Commit

Permalink
Closing video player will just hide the player window, channel list w…
Browse files Browse the repository at this point in the history
…ill kill the whole app.
  • Loading branch information
ozankaraali committed May 25, 2024
1 parent ffd3fb6 commit 4a9808f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
20 changes: 9 additions & 11 deletions channel_list.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import json
import os
import shutil
import string
import platform
import random
import re
import shutil
import string
import subprocess
import platform

from urlobject import URLObject

import requests
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import (
QMainWindow,
QFileDialog,
Expand All @@ -23,15 +21,17 @@
QLineEdit,
QGridLayout,
)
from urlobject import URLObject

from options import OptionsDialog


class ChannelList(QMainWindow):
channels_loaded = pyqtSignal(list)

def __init__(self, player):
def __init__(self, app, player):
super().__init__()
self.app = app
self.player = player
self.link = None
self.setWindowTitle("QiTV Channel List")
Expand All @@ -40,7 +40,6 @@ def __init__(self, player):
self.setCentralWidget(self.container_widget)
self.grid_layout = QGridLayout(self.container_widget)

# self.create_menu()
self.create_upper_panel()
self.create_left_panel()
self.create_media_controls()
Expand All @@ -50,9 +49,10 @@ def __init__(self, player):
self.load_channels()

def closeEvent(self, event):
self.player.close()
self.save_window_settings()
self.save_config()
event.accept()
self.app.quit()

def create_upper_panel(self):
self.upper_layout = QWidget(self.container_widget)
Expand Down Expand Up @@ -327,7 +327,6 @@ def load_stb_channels(self, url, options):
channels = result["js"]["data"]
self.display_channels(channels)
self.config["data"][self.config["selected"]]["options"] = options
# self.config["data"][self.config["selected"]]["channels"] = channels
self.save_config()
except Exception as e:
print(f"Error loading STB channels: {e}")
Expand Down Expand Up @@ -361,7 +360,6 @@ def create_options(url, mac, token):
"User-Agent": "Mozilla/5.0 (QtEmbedded; U; Linux; C) AppleWebKit/533.3 (KHTML, like Gecko) MAG200 stbapp ver: 2 rev: 250 Safari/533.3",
"Accept-Charset": "UTF-8,*;q=0.8",
"X-User-Agent": "Model: MAG200; Link: Ethernet",
# "Content-Type": "application/json",
"Host": f"{url.netloc}",
"Range": "bytes=0-",
"Accept": "*/*",
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
if __name__ == "__main__":
app = QApplication(sys.argv)
player = VideoPlayer()
channel_list = ChannelList(player)
channel_list = ChannelList(app, player)
player.show()
channel_list.show()
sys.exit(app.exec_())
16 changes: 10 additions & 6 deletions video_player.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import json
import platform
import sys

import vlc
from PyQt5.QtCore import Qt, QEvent
from PyQt5.QtWidgets import QMainWindow, QFrame, QHBoxLayout
import sys


class VideoPlayer(QMainWindow):
def __init__(self, *args, **kwargs):
super(VideoPlayer, self).__init__(*args, **kwargs)

self.load_config()
self.apply_window_settings()
self.config = None
self.media = None
self.setGeometry(100, 100, 800, 600)
Expand All @@ -23,12 +25,12 @@ def __init__(self, *args, **kwargs):
self.video_frame.mouseDoubleClickEvent = self.mouseDoubleClickEvent
self.video_frame.installEventFilter(self)
t_lay_parent.addWidget(self.video_frame)
self.instance = vlc.Instance(['--video-on-top'])
self.instance = vlc.Instance(["--video-on-top"])
self.media_player = self.instance.media_player_new()
self.media_player.video_set_mouse_input(False)
self.media_player.video_set_key_input(False)

if sys.platform.startswith('linux'):
if sys.platform.startswith("linux"):
self.media_player.set_xwindow(self.video_frame.winId())
elif sys.platform == "win32":
self.media_player.set_hwnd(self.video_frame.winId())
Expand Down Expand Up @@ -84,7 +86,8 @@ def closeEvent(self, event):
self.save_config()
if self.media_player.is_playing():
self.media_player.stop()
event.accept()
self.hide()
event.ignore()

def play_video(self, video_url):
if platform.system() == "Linux":
Expand All @@ -97,6 +100,7 @@ def play_video(self, video_url):
self.media = self.instance.media_new(video_url)
self.media_player.set_media(self.media)
self.media_player.play()
self.show()

def stop_video(self):
self.media_player.stop()
Expand Down Expand Up @@ -158,4 +162,4 @@ def apply_window_settings(self):
video_player_pos.get("y", 100),
video_player_pos.get("width", 1200),
video_player_pos.get("height", 800),
)
)

0 comments on commit 4a9808f

Please sign in to comment.