Skip to content

Commit

Permalink
Merge pull request #363 from bohning/rate_via_syncer
Browse files Browse the repository at this point in the history
Rate via syncer
  • Loading branch information
bohning authored Mar 9, 2025
2 parents 22f714a + 377c70a commit ac75839
Show file tree
Hide file tree
Showing 5 changed files with 207 additions and 128 deletions.
22 changes: 5 additions & 17 deletions src/usdb_syncer/gui/comment_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from PySide6.QtWidgets import QDialog, QWidget

from usdb_syncer.gui.forms.CommentDialog import Ui_Dialog
from usdb_syncer.usdb_scraper import RequestMethod, get_usdb_page
from usdb_syncer.usdb_scraper import post_song_comment
from usdb_syncer.usdb_song import UsdbSong


Expand All @@ -20,20 +20,8 @@ def __init__(self, parent: QWidget, selected_song: UsdbSong) -> None:
self.combobox_rating.addItem("Negative", "negativ")

def accept(self) -> None:
payload = {
"text": self.text_edit_comment.toPlainText(),
"stars": self.combobox_rating.currentData(),
}

get_usdb_page(
"index.php",
RequestMethod.POST,
headers={"Content-Type": "application/x-www-form-urlencoded"},
params={
"link": "detail",
"id": str(int(self._selected_song.song_id)),
"comment": str(1),
},
payload=payload,
)
song_id = self._selected_song.song_id
text = self.text_edit_comment.toPlainText()
rating = self.combobox_rating.currentData()
post_song_comment(song_id, text, rating)
super().accept()
200 changes: 90 additions & 110 deletions src/usdb_syncer/gui/forms/CommentDialog.ui
Original file line number Diff line number Diff line change
@@ -1,113 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>294</width>
<height>214</height>
</rect>
</property>
<property name="windowTitle">
<string>Post a Comment</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="comment_label">
<property name="text">
<string>Comment:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPlainTextEdit" name="text_edit_comment">
<property name="toolTip">
<string>Enter the comment you want to post on the song.</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="rating_label">
<property name="text">
<string>Rating:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="combobox_rating">
<property name="toolTip">
<string>Please select a rating for this comment.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Save</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>425</width>
<height>273</height>
</rect>
</property>
<property name="windowTitle">
<string>Post a Comment</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="text_edit_comment">
<property name="toolTip">
<string>Enter the comment you want to post on the song.</string>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout" columnstretch="0,1">
<item row="0" column="0">
<widget class="QLabel" name="rating_label">
<property name="text">
<string>Rating:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QComboBox" name="combobox_rating">
<property name="toolTip">
<string>Please select a rating for this comment.</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Save</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>Dialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
69 changes: 68 additions & 1 deletion src/usdb_syncer/gui/forms/MainWindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,25 @@
<addaction name="action_open_song_in_karedi"/>
<addaction name="action_open_song_in_ultrastar_manager"/>
</widget>
<widget class="QMenu" name="menu_rate_song_on_usdb">
<property name="title">
<string>Rate Song on USDB</string>
</property>
<property name="icon">
<iconset resource="../resources/resources.qrc">
<normaloff>:/icons/rating.png</normaloff>:/icons/rating.png</iconset>
</property>
<addaction name="action_rate_1star"/>
<addaction name="action_rate_2stars"/>
<addaction name="action_rate_3stars"/>
<addaction name="action_rate_4stars"/>
<addaction name="action_rate_5stars"/>
</widget>
<addaction name="action_songs_download"/>
<addaction name="action_songs_abort"/>
<addaction name="action_show_in_usdb"/>
<addaction name="action_post_comment_in_usdb"/>
<addaction name="menu_rate_song_on_usdb"/>
<addaction name="separator"/>
<addaction name="action_open_song_folder"/>
<addaction name="menu_open_song_in"/>
Expand Down Expand Up @@ -601,7 +616,7 @@
<normaloff>:/icons/balloon.png</normaloff>:/icons/balloon.png</iconset>
</property>
<property name="text">
<string>Post Comment</string>
<string>Post Comment on USDB</string>
</property>
</action>
<action name="action_open_song_folder">
Expand Down Expand Up @@ -752,6 +767,58 @@
<string>YASS Reloaded</string>
</property>
</action>
<action name="action_rate_in_usdb">
<property name="icon">
<iconset resource="../resources/resources.qrc">
<normaloff>:/icons/rating.png</normaloff>:/icons/rating.png</iconset>
</property>
<property name="text">
<string>action_rate_in_usdb</string>
</property>
<property name="menuRole">
<enum>QAction::MenuRole::NoRole</enum>
</property>
</action>
<action name="action_rate_1star">
<property name="text">
<string>★ – Unusable, requires a complete overhaul</string>
</property>
<property name="toolTip">
<string>unusable, needs a total rework</string>
</property>
</action>
<action name="action_rate_2stars">
<property name="text">
<string>★★ – Barely usable, needs significant revisions</string>
</property>
<property name="toolTip">
<string>hardly usable, needs a lot of improvements</string>
</property>
</action>
<action name="action_rate_3stars">
<property name="text">
<string>★★★ – Usable, but requires improvements</string>
</property>
<property name="toolTip">
<string>usable, but room for improvement</string>
</property>
</action>
<action name="action_rate_4stars">
<property name="text">
<string>★★★★ – Very good, with minor areas for improvement</string>
</property>
<property name="toolTip">
<string>room for some improvements</string>
</property>
</action>
<action name="action_rate_5stars">
<property name="text">
<string>★★★★★ – Excellent, no improvements needed</string>
</property>
<property name="toolTip">
<string>simply perfect</string>
</property>
</action>
</widget>
<resources>
<include location="../resources/resources.qrc"/>
Expand Down
13 changes: 13 additions & 0 deletions src/usdb_syncer/gui/mw.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from usdb_syncer.pdf import generate_song_pdf
from usdb_syncer.song_loader import DownloadManager
from usdb_syncer.sync_meta import SyncMeta
from usdb_syncer.usdb_scraper import post_song_rating
from usdb_syncer.usdb_song import UsdbSong
from usdb_syncer.utils import AppPaths, open_file_explorer

Expand Down Expand Up @@ -103,6 +104,11 @@ def _setup_toolbar(self) -> None:
(self.action_show_log, lambda: open_file_explorer(AppPaths.log.parent)),
(self.action_show_in_usdb, self._show_current_song_in_usdb),
(self.action_post_comment_in_usdb, self._show_comment_dialog),
(self.action_rate_1star, lambda: self._rate_in_usdb(1)),
(self.action_rate_2stars, lambda: self._rate_in_usdb(2)),
(self.action_rate_3stars, lambda: self._rate_in_usdb(3)),
(self.action_rate_4stars, lambda: self._rate_in_usdb(4)),
(self.action_rate_5stars, lambda: self._rate_in_usdb(5)),
(self.action_open_song_folder, self._open_current_song_folder),
(
self.action_open_song_in_karedi,
Expand Down Expand Up @@ -295,6 +301,13 @@ def _show_comment_dialog(self) -> None:
else:
logger.debug("Not opening comment dialog: no song selected.")

def _rate_in_usdb(self, stars: int) -> None:
song = self.table.current_song()
if song:
post_song_rating(song.song_id, stars)
else:
logger.debug("Not rating song: no song selected.")

def _open_current_song(self, action: Callable[[Path], None]) -> None:
if song := self.table.current_song():
if song.sync_meta:
Expand Down
Loading

0 comments on commit ac75839

Please sign in to comment.