Skip to content

Commit

Permalink
#10 fixed no audio bug
Browse files Browse the repository at this point in the history
  • Loading branch information
rohankishore committed Mar 9, 2024
1 parent f635e2a commit cfa6b93
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 24 deletions.
17 changes: 15 additions & 2 deletions youtility/downloader.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os
import random

Expand All @@ -6,11 +7,18 @@
from PyQt6.QtGui import QMovie
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QGroupBox, QPushButton, QComboBox, QFileDialog, QHBoxLayout, \
QSpacerItem, QLabel, QListWidgetItem
from pytube import YouTube
from qfluentwidgets import (LineEdit,
StrongBodyLabel, MessageBox, CheckBox, ListWidget)
from pytube import YouTube

from consts import msgs, extension

with open("resources/misc/config.json", "r") as themes_file:
_themes = json.load(themes_file)

theme_color = _themes["theme"]
progressive = _themes["progressive"]


class DownloaderThread(QThread):
download_finished = pyqtSignal()
Expand Down Expand Up @@ -181,8 +189,13 @@ def __init__(self):
def get_quality(self):
url = self.link_entry.text()
try:
set_progressive = True
if progressive == "True":
set_progressive = True
else:
set_progressive = False
youtube = pytube.YouTube(url)
streams = youtube.streams.filter(progressive=False)
streams = youtube.streams.filter(progressive=set_progressive)
self.quality_menu.clear()
for stream in streams:
self.quality_menu.addItem(stream.resolution)
Expand Down
2 changes: 1 addition & 1 deletion youtility/get_captions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import random
import xml.etree.ElementTree as ET

import pytube.exceptions
from PyQt6.QtCore import Qt, QThread, pyqtSignal
Expand All @@ -11,7 +12,6 @@
StrongBodyLabel, MessageBox, ListWidget)

from consts import msgs, extension
import xml.etree.ElementTree as ET

with open("resources/misc/config.json", "r") as themes_file:
_themes = json.load(themes_file)
Expand Down
20 changes: 12 additions & 8 deletions youtility/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,25 @@
from PyQt6.QtCore import Qt, pyqtSignal, QEasingCurve, QUrl
from PyQt6.QtGui import QIcon, QDesktopServices
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QVBoxLayout, QApplication, QFrame
from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets import (NavigationBar, NavigationItemPosition, MessageBox,
isDarkTheme, setTheme, Theme,
PopUpAniStackedWidget, setThemeColor)
from qfluentwidgets import FluentIcon as FIF
from qframelesswindow import FramelessWindow, TitleBar
from downloader import YoutubeVideo
import settings
import playlist

import get_captions
import playlist
import settings
from downloader import YoutubeVideo

APP_NAME = "Youtility"

with open("resources/misc/config.json", "r") as themes_file:
_themes = json.load(themes_file)

theme_color = _themes["theme"]
progressive = _themes["progressive"]


class StackedWidget(QFrame):
""" Stacked widget """
Expand Down Expand Up @@ -144,8 +147,9 @@ def initLayout(self):
def initNavigation(self):
self.addSubInterface(self.videoInterface, FIF.VIDEO, 'Video', selectedIcon=FIF.VIDEO)
self.addSubInterface(self.playlistInterface, FIF.FOLDER, 'Playlist', selectedIcon=FIF.FOLDER)
self.addSubInterface(self.captionInterface, QIcon("resources/icons/captions.svg"), 'Captions', selectedIcon=QIcon(
"resources/icons/captions.svg"))
self.addSubInterface(self.captionInterface, QIcon("resources/icons/captions.svg"), 'Captions',
selectedIcon=QIcon(
"resources/icons/captions.svg"))
self.addSubInterface(self.settingsInterface, FIF.SETTING, 'Settings', NavigationItemPosition.BOTTOM,
FIF.SETTING)
self.navigationBar.addItem(
Expand Down Expand Up @@ -192,8 +196,8 @@ def onCurrentInterfaceChanged(self, index):

def showMessageBox(self):
text_for_about = f"Heya! it's Rohan, the creator of {APP_NAME}. I hope you've enjoyed using this app as much as I enjoyed making it." + "" + "\n" + "\n" \
"I'm a school student and I can't earn my own money LEGALLY. So any donations will be largely appreciated. Also, if you find any bugs / have any feature requests, you can open a Issue/ Pull Request in the Repo." \
"You can visit GitHub by pressing the button below. You can find Ko-Fi link there :) " + "\n" + "\n" + \
"I'm a school student and I can't earn my own money LEGALLY. So any donations will be largely appreciated. Also, if you find any bugs / have any feature requests, you can open a Issue/ Pull Request in the Repo." \
"You can visit GitHub by pressing the button below. You can find Ko-Fi link there :) " + "\n" + "\n" + \
f"Once again, thank you for using {APP_NAME}. Please consider giving it a star ⭐ as it will largely motivate me to create more of such apps. Also do consider giving me a follow ;) "
w = MessageBox(
APP_NAME,
Expand Down
24 changes: 17 additions & 7 deletions youtility/playlist.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os
import json
import random
import re

Expand All @@ -7,12 +7,14 @@
from PyQt6.QtGui import QMovie
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QGroupBox, QPushButton, QComboBox, QFileDialog, QHBoxLayout, \
QSpacerItem, QLabel, QListWidgetItem
from qfluentwidgets import (LineEdit,
StrongBodyLabel, MessageBox, CheckBox, ListWidget, TextEdit)
from pytube import Playlist
from consts import msgs, extension
import threading
from qfluentwidgets import (LineEdit,
CheckBox, ListWidget, TextEdit)

with open("resources/misc/config.json", "r") as themes_file:
_themes = json.load(themes_file)

progressive = _themes["progressive"]

class DownloaderThread(QThread):
download_finished = pyqtSignal()
Expand Down Expand Up @@ -111,7 +113,10 @@ def __init__(self):
self.main_layout.addLayout(self.options_layout)
self.quality_menu = QComboBox()
self.quality_menu.setPlaceholderText("Video Quality (Applies to all videos)")
self.quality_menu.addItems(["1080p", "720p", "480p", "360p", "240p", "144p"])
if progressive == "True":
self.quality_menu.addItems(["720p", "480p", "360p", "240p", "144p"])
else:
self.quality_menu.addItems(["2160p", "1440p", "1080p", "720p", "480p", "360p", "240p", "144p"])
self.quality_layout.addWidget(self.quality_menu)
self.options_layout.addSpacerItem(spacer_item_medium)
self.thumbnail_url_checkbox = CheckBox('Copy Thumbnail URL', self)
Expand Down Expand Up @@ -158,9 +163,14 @@ def __init__(self):

def get_quality(self):
url = self.link_entry.text()
set_progressive = True
try:
youtube = pytube.YouTube(url)
streams = youtube.streams.filter(progressive=False)
if progressive == "True":
set_progressive = True
else:
set_progressive = False
streams = youtube.streams.filter(progressive=set_progressive)
self.quality_menu.clear()
for stream in streams:
self.quality_menu.addItem(stream.resolution)
Expand Down
26 changes: 20 additions & 6 deletions youtility/settings.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import json
import os
from PyQt6.QtWidgets import QWidget, QVBoxLayout, QGroupBox, QPushButton, QComboBox, QFileDialog, QColorDialog
from qfluentwidgets import (LineEdit, TextEdit,
ScrollArea, StrongBodyLabel, MessageBox)

from PyQt6.QtWidgets import QWidget, QVBoxLayout, QGroupBox, QPushButton, QComboBox
from qfluentwidgets import (LineEdit, StrongBodyLabel, MessageBox, CheckBox)

with open("resources/misc/config.json", "r") as themes_file:
_themes = json.load(themes_file)
Expand Down Expand Up @@ -37,23 +36,38 @@ def initUI(self):

def_sub_format_label = StrongBodyLabel("Default Subtitle Format: ", self)
pref_layout.addWidget(def_sub_format_label)

self.def_sub_format = QComboBox()
self.def_sub_format.addItems(["SRT", "XML"])
self.def_sub_format.setCurrentText(_themes["def_sub_format"])
pref_layout.addWidget(self.def_sub_format)

set_progressive_label = StrongBodyLabel("Allow higher res downloads (audio may be missing): ", self)
pref_layout.addWidget(set_progressive_label)
self.set_progressive = CheckBox()
self.set_progressive.setText("Allow")
if _themes["progressive"] == "False":
self.set_progressive.setChecked(True)
else:
pass
pref_layout.addWidget(self.set_progressive)

# Apply Button
self.apply_button = QPushButton("Apply")
self.apply_button.clicked.connect(self.save_json)
layout.addWidget(self.apply_button)

self.setLayout(layout)


def save_json(self):
progressive_state = "True"
if self.set_progressive.isChecked():
progressive_state = "False"
else:
progressive_state = "True"

_themes["theme"] = self.theme_color_line_edit.text()
_themes["def_sub_format"] = self.def_sub_format.currentText()
_themes["progressive"] = progressive_state

with open("resources/misc/config.json", "w") as json_file:
json.dump(_themes, json_file)
Expand Down

0 comments on commit cfa6b93

Please sign in to comment.