Skip to content

Commit 1f98c91

Browse files
committed
add download statistics and donate button to the about tab
1 parent b10e06a commit 1f98c91

File tree

8 files changed

+54
-38
lines changed

8 files changed

+54
-38
lines changed

src/onthespot/api/youtube_music.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def youtube_music_login_user(account):
2121
"service": "youtube_music",
2222
"status": "active",
2323
"account_type": "public",
24-
"bitrate": "256k",
24+
"bitrate": "128k",
2525
})
2626
return True
2727
except Exception as e:
@@ -66,7 +66,7 @@ def youtube_music_get_search_results(_, search_term, content_types):
6666
'item_by': result['channel'],
6767
'item_type': "track",
6868
'item_service': "youtube_music",
69-
'item_url': result['url'],
69+
'item_url': f"https://music.youtube.com/watch?v={result['id']}",
7070
'item_thumbnail_url': f'https://i.ytimg.com/vi/{result["id"]}/hqdefault.jpg'
7171
})
7272

src/onthespot/downloader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ def run(self):
388388
ydl_opts['format'] = 'bestaudio[ext=mp3]'
389389
elif item_service == "youtube_music":
390390
default_format = '.m4a'
391-
bitrate = "256k"
391+
bitrate = "128k"
392392
ydl_opts['format'] = 'bestaudio[ext=m4a]'
393393
ydl_opts['quiet'] = True
394394
ydl_opts['no_warnings'] = True
@@ -738,7 +738,12 @@ def run(self):
738738
logger.info("Item Successfully Downloaded")
739739
if self.gui:
740740
self.progress.emit(item, self.tr("Downloaded"), 100)
741-
741+
try:
742+
config.set('total_downloaded_data', config.get('total_downloaded_data') + os.path.getsize(item['file_path']))
743+
config.set('total_downloaded_items', config.get('total_downloaded_items') + 1)
744+
config.save()
745+
except Exception:
746+
pass
742747
time.sleep(config.get("download_delay"))
743748
self.readd_item_to_download_queue(item)
744749
continue

src/onthespot/gui/mainui.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .dl_progressbtn import DownloadActionsButtons
2626
from .settings import load_config, save_config
2727
from .thumb_listitem import LabelWithThumb
28-
from ..utils import is_latest_release, open_item
28+
from ..utils import is_latest_release, open_item, format_bytes
2929
from ..search import get_search_results
3030

3131
logger = get_logger('gui.main_ui')
@@ -81,13 +81,6 @@ def closeEvent(self, event):
8181
self.hide()
8282

8383

84-
# Remove Later
85-
def contribute(self):
86-
if self.language.currentIndex() == self.language.count() - 1:
87-
url = "https://github.com/justin025/OnTheSpot/tree/main#contributing"
88-
open_item(url)
89-
90-
9184
def __init__(self, _dialog, start_url=''):
9285
super(MainWindow, self).__init__()
9386
self.path = os.path.dirname(os.path.realpath(__file__))
@@ -98,8 +91,6 @@ def __init__(self, _dialog, start_url=''):
9891
self.centralwidget.setStyleSheet(config.get('theme'))
9992

10093
self.start_url = start_url
101-
self.version.setText(config.get("version"))
102-
self.session_uuid.setText(config.session_uuid)
10394
logger.info(f"Initialising main window, logging session : {config.session_uuid}")
10495

10596
# Fill the value from configs
@@ -215,15 +206,16 @@ def bind_button_inputs(self):
215206

216207
self.settings_bookmark_accounts.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(0))
217208
self.settings_bookmark_general.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(328))
218-
self.settings_bookmark_audio_downloads.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(1160))
219-
self.settings_bookmark_audio_metadata.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(2000))
209+
self.settings_bookmark_audio_downloads.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(1176))
210+
self.settings_bookmark_audio_metadata.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(2016))
220211
self.settings_bookmark_video_downloads.clicked.connect(lambda: self.settings_scroll_area.verticalScrollBar().setValue(9999))
221212

222213
self.export_logs.clicked.connect(lambda: shutil.copy(
223214
os.path.join(cache_dir(), "logs", config.session_uuid, "onthespot.log"),
224215
os.path.join(os.path.expanduser("~"), "Downloads", "onthespot.log")) and
225216
self.show_popup_dialog(self.tr("Logs exported to '{0}'").format(os.path.join(os.path.expanduser("~"), "Downloads", "onthespot.log") or True))
226217
)
218+
self.donate.clicked.connect(lambda: open_item('https://justin025.github.io/about.html'))
227219

228220

229221
def set_table_props(self):
@@ -480,6 +472,7 @@ def add_item_to_download_list(self, item, item_metadata):
480472

481473

482474
def update_item_in_download_list(self, item, status, progress):
475+
self.statistics.setText(self.tr("{0} / {1}").format(config.get('total_downloaded_items'), format_bytes(config.get('total_downloaded_data'))))
483476
with download_queue_lock:
484477
item['gui']['status_label'].setText(status)
485478
item['gui']['progress_bar'].setValue(progress)

src/onthespot/gui/qtui/main.ui

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4674,14 +4674,14 @@
46744674
</widget>
46754675
</item>
46764676
<item>
4677-
<widget class="QLabel" name="lb_session_uuid">
4677+
<widget class="QLabel" name="lb_statistics">
46784678
<property name="text">
4679-
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Log UUID : &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
4679+
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:600;&quot;&gt;Total Downloads : &lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
46804680
</property>
46814681
</widget>
46824682
</item>
46834683
<item>
4684-
<widget class="QLineEdit" name="session_uuid">
4684+
<widget class="QLineEdit" name="statistics">
46854685
<property name="enabled">
46864686
<bool>false</bool>
46874687
</property>
@@ -4696,13 +4696,6 @@
46964696
</property>
46974697
</widget>
46984698
</item>
4699-
<item>
4700-
<widget class="QPushButton" name="export_logs">
4701-
<property name="text">
4702-
<string>Export Logs</string>
4703-
</property>
4704-
</widget>
4705-
</item>
47064699
<item>
47074700
<spacer name="horizontalSpacer_25">
47084701
<property name="orientation">
@@ -4716,6 +4709,20 @@
47164709
</property>
47174710
</spacer>
47184711
</item>
4712+
<item>
4713+
<widget class="QPushButton" name="export_logs">
4714+
<property name="text">
4715+
<string>Export Logs</string>
4716+
</property>
4717+
</widget>
4718+
</item>
4719+
<item>
4720+
<widget class="QPushButton" name="donate">
4721+
<property name="text">
4722+
<string>Donate</string>
4723+
</property>
4724+
</widget>
4725+
</item>
47194726
</layout>
47204727
</widget>
47214728
</item>
@@ -4729,8 +4736,8 @@
47294736
<rect>
47304737
<x>0</x>
47314738
<y>0</y>
4732-
<width>140</width>
4733-
<height>1309</height>
4739+
<width>641</width>
4740+
<height>405</height>
47344741
</rect>
47354742
</property>
47364743
<layout class="QVBoxLayout" name="verticalLayout_2">
@@ -4755,12 +4762,9 @@
47554762
program or source code. Users are solely responsible for ensuring that their use of
47564763
OnTheSpot complies with all relevant/applicable laws in their country.The creators
47574764
and contributors of OnTheSpot assume no liability for any misuse of legal terms
4758-
associated with the application or its source code.
4765+
associated with the application or its source code. Licensed under GPL-2.0.
47594766
&lt;br&gt;
47604767
&lt;br&gt;
4761-
&lt;a href=&quot;https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1&quot; style=&quot;text-decoration: underline; color:#64B5F6;&quot;&gt;
4762-
GPL-2.0 License
4763-
&lt;/a&gt;
47644768
&lt;/p&gt;</string>
47654769
</property>
47664770
<property name="scaledContents">

src/onthespot/gui/settings.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from PyQt6.QtGui import QIcon
33
from PyQt6.QtWidgets import QSpinBox, QComboBox, QWidget
44
from ..otsconfig import config
5+
from ..utils import format_bytes
56

67

78
class NonScrollableSpinBox(QSpinBox):
@@ -15,6 +16,9 @@ def wheelEvent(self, event):
1516

1617

1718
def load_config(self):
19+
self.version.setText(config.get("version"))
20+
self.statistics.setText(self.tr("{0} / {1}").format(config.get('total_downloaded_items'), format_bytes(config.get('total_downloaded_data'))))
21+
1822
# Dev Tools
1923
self.settings_scrollarea_value.valueChanged.connect(self.settings_scroll_area.verticalScrollBar().setValue)
2024
if not config.get('debug_mode'):
@@ -27,12 +31,11 @@ def load_config(self):
2731
# Icons
2832
self.toggle_theme_button.setIcon(self.get_icon('light'))
2933
self.export_logs.setIcon(self.get_icon('export_file'))
34+
self.donate.setIcon(self.get_icon('filled_heart'))
3035

3136
self.language.insertItem(0, self.get_icon('en_US'), "English")
3237
self.language.insertItem(1, self.get_icon('de_DE'), "Deutsch")
3338
self.language.insertItem(2, self.get_icon('pt_PT'), "Português")
34-
self.language.insertItem(999, self.get_icon('pirate_flag'), "Contribute")
35-
self.language.currentIndexChanged.connect(self.contribute)
3639

3740
self.login_service.insertItem(0, "Audio")
3841
self.login_service.insertItem(1, self.get_icon('apple_music'), "Apple Music")

src/onthespot/otsconfig.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ def __init__(self, cfg_path=None):
3838
self.__template_data = {
3939
# System Variables
4040
"version": "v1.0.7", # Application version
41-
"debug_mode": False, # Application version
41+
"debug_mode": False, # Enable debug mode
4242
"language_index": 0, # Language Index
43+
"total_downloaded_items": 0, # Total downloaded items
44+
"total_downloaded_data": 0, # Total downloaded data in bytes
4345
"m3u_format": "m3u8", # M3U file format
4446
"use_double_digit_path_numbers": False, # Append a 0 to single digit path numbers, for instance 1 -> 01
4547
"ffmpeg_args": [], # Extra arguments for ffmpeg

src/onthespot/resources/web/about.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ <h1 align="center">Disclaimer</h1>
3232
program or source code. Users are solely responsible for ensuring that their use of
3333
OnTheSpot complies with all relevant/applicable laws in their country.The creators
3434
and contributors of OnTheSpot assume no liability for any misuse of legal terms
35-
associated with the application or its source code.
35+
associated with the application or its source code. Licensed under GPL-2.0.
3636
<br>
3737
<br>
38-
<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html#SEC1" style="text-decoration: underline; color:#64B5F6;">
39-
GPL-2.0 License
38+
<a href="https://justin025.github.io/about.html" style="text-decoration: underline; color:#64B5F6;">
39+
<strong>Donate <3</strong>
4040
</a>
4141
</p>
4242
</body>

src/onthespot/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,12 @@ def strip_metadata(item):
722722
else:
723723
subprocess.check_call(command, shell=False)
724724
os.remove(temp_name)
725+
726+
727+
def format_bytes(size):
728+
units = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']
729+
index = 0
730+
while size >= 1024 and index < len(units) - 1:
731+
size /= 1024
732+
index += 1
733+
return f"{size:.2f} {units[index]}"

0 commit comments

Comments
 (0)