Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement format version support. #313

Merged
merged 7 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

# Changes

## Features

- The UltraStar format version can now be specified in the settings (see https://usdx.eu/format/).

<!-- 0.9.0 -->

# Changes

## Fixes

- Switch from browser_cookie3 to rookiepy in order to retrieve browser cookies on
Expand Down
2 changes: 2 additions & 0 deletions src/usdb_syncer/download_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class TxtOptions:

encoding: settings.Encoding
newline: settings.Newline
format_version: settings.FormatVersion
fix_linebreaks: settings.FixLinebreaks
fix_first_words_capitalization: bool
fix_spaces: settings.FixSpaces
Expand Down Expand Up @@ -100,6 +101,7 @@ def _txt_options() -> TxtOptions | None:
return TxtOptions(
encoding=settings.get_encoding(),
newline=settings.get_newline(),
format_version=settings.get_version(),
fix_linebreaks=settings.get_fix_linebreaks(),
fix_first_words_capitalization=settings.get_fix_first_words_capitalization(),
fix_spaces=settings.get_fix_spaces(),
Expand Down
97 changes: 60 additions & 37 deletions src/usdb_syncer/gui/forms/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>640</width>
<height>649</height>
<height>677</height>
</rect>
</property>
<property name="windowTitle">
Expand All @@ -28,7 +28,7 @@
<number>20</number>
</property>
<item>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0,0">
<item>
<widget class="QGroupBox" name="groupBox_login">
<property name="title">
Expand Down Expand Up @@ -76,17 +76,20 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="0">
<widget class="QLabel" name="label_song_file_line_endings">
<item row="0" column="0">
<widget class="QLabel" name="label_song_file_encoding">
<property name="toolTip">
<string/>
</property>
<property name="text">
<string>Line endings:</string>
<string>Encoding:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_song_file_fix_first_words_capitalization">
<item row="1" column="0">
<widget class="QLabel" name="label_song_file_line_endings">
<property name="text">
<string>Fix capitalization:</string>
<string>Line endings:</string>
</property>
</widget>
</item>
Expand All @@ -103,72 +106,92 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QCheckBox" name="checkBox_fix_first_words_capitalization">
<property name="text">
<string/>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_line_endings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;USDX and variants can handle both line ending types, but if you want to edit the song file manually, your editor of choice may require a certain line ending. UNIX users (MacOS, Linux) should generally use LF (line feed). On Windows, some text editors may require CRLF (carriage return, line feed). USDB currently requires CRLF line endings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_song_file_fix_spaces">
<item row="2" column="0">
<widget class="QLabel" name="label_song_file_format_version">
<property name="text">
<string>Fix spaces:</string>
<string>Version:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_fix_linebreaks">
<widget class="QComboBox" name="comboBox_format_version">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this setting is enabled, the linebreak timings will be recalculated, either according to USDX or to YASS rules.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;V1.0.0&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Choose this version for highest compatibility. This uses #MP3 to specifiy the audio file.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;V1.1.0&lt;/span&gt;&lt;/p&gt;&lt;p&gt;This version switches from #MP3 to #AUDIO to underline that other audio formats than mp3 are supported. For compatibility, the Syncer adds both #MP3 and #AUDIO to the text file, which should cause no issues when loading the song.&lt;/p&gt;&lt;p&gt;&lt;span style=&quot; font-weight:700;&quot;&gt;V1.2.0&lt;/span&gt;&lt;/p&gt;&lt;p&gt;This version introduces new tags #AUDIOURL, #COVERURL, #BACKGROUNDURL and #VIDEOURL to specify URLs for the respective sources. The syncer will fill these tags with the contents of the respective metatags, if available.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="2" column="0">
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_fixes">
<property name="title">
<string>Optional song file fixes</string>
</property>
<layout class="QGridLayout" name="gridLayout_9">
<item row="0" column="0">
<widget class="QLabel" name="label_song_file_fix_linebreaks">
<property name="text">
<string>Fix linebreaks:</string>
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QComboBox" name="comboBox_fix_spaces">
<item row="0" column="1">
<widget class="QComboBox" name="comboBox_fix_linebreaks">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this setting is enabled, all inter-word spaces will be shifted to either after or before a word.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this setting is enabled, the linebreak timings will be recalculated, either according to USDX or to YASS rules.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QComboBox" name="comboBox_line_endings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>1</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;USDX and variants can handle both line ending types, but if you want to edit the song file manually, your editor of choice may required a certain line ending. UNIX users (MacOS, Linux) should generally use LF (line feed). On Windows, some text editors may require CRLF (carriage return, line feed). USDB currently requires CRLF line endings.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<item row="1" column="0">
<widget class="QLabel" name="label_song_file_fix_first_words_capitalization">
<property name="text">
<string>Fix capitalization:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_song_file_encoding">
<property name="toolTip">
<item row="1" column="1">
<widget class="QCheckBox" name="checkBox_fix_first_words_capitalization">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_song_file_fix_spaces">
<property name="text">
<string>Encoding:</string>
<string>Fix spaces:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="comboBox_fix_spaces">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If this setting is enabled, all inter-word spaces will be shifted to either after or before a word.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</widget>
</item>
<item row="5" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_song_file_fix_quotation_marks">
<property name="text">
<string>Fix quotation marks:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<item row="3" column="1">
<widget class="QCheckBox" name="checkBox_fix_quotation_marks">
<property name="text">
<string/>
Expand Down
5 changes: 5 additions & 0 deletions src/usdb_syncer/gui/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ def _populate_comboboxes(self) -> None:
combobox_settings = (
(self.comboBox_encoding, settings.Encoding),
(self.comboBox_line_endings, settings.Newline),
(self.comboBox_format_version, settings.FormatVersion),
(self.comboBox_fix_linebreaks, settings.FixLinebreaks),
(self.comboBox_fix_spaces, settings.FixSpaces),
(self.comboBox_cover_max_size, settings.CoverMaxSize),
Expand Down Expand Up @@ -148,6 +149,9 @@ def _load_settings(self) -> None:
self.comboBox_line_endings.setCurrentIndex(
self.comboBox_line_endings.findData(settings.get_newline())
)
self.comboBox_format_version.setCurrentIndex(
self.comboBox_format_version.findData(settings.get_version())
)
self.comboBox_fix_linebreaks.setCurrentIndex(
self.comboBox_fix_linebreaks.findData(settings.get_fix_linebreaks())
)
Expand Down Expand Up @@ -244,6 +248,7 @@ def _save_settings(self) -> bool:
settings.set_txt(self.groupBox_songfile.isChecked())
settings.set_encoding(self.comboBox_encoding.currentData())
settings.set_newline(self.comboBox_line_endings.currentData())
settings.set_version(self.comboBox_format_version.currentData())
settings.set_fix_linebreaks(self.comboBox_fix_linebreaks.currentData())
settings.set_fix_first_words_capitalization(
self.checkBox_fix_first_words_capitalization.isChecked()
Expand Down
6 changes: 3 additions & 3 deletions src/usdb_syncer/json_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from usdb_syncer import SongId
from usdb_syncer.logger import logger
from usdb_syncer.usdb_song import UsdbSong
from usdb_syncer.utils import url_from_resource
from usdb_syncer.utils import video_url_from_resource

JSON_EXPORT_VERSION = 1

Expand Down Expand Up @@ -62,12 +62,12 @@ def from_usdb_song(cls, song: UsdbSong) -> SongExportData | None:
meta.meta_tags.cover.to_str("co") if meta.meta_tags.cover else None
),
audio_url=(
url_from_resource(meta.meta_tags.audio)
video_url_from_resource(meta.meta_tags.audio)
if meta.meta_tags.audio
else None
),
video_url=(
url_from_resource(meta.meta_tags.video)
video_url_from_resource(meta.meta_tags.video)
if meta.meta_tags.video
else None
),
Expand Down
4 changes: 2 additions & 2 deletions src/usdb_syncer/resource_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from usdb_syncer.meta_tags import ImageMetaTags
from usdb_syncer.settings import Browser, CoverMaxSize
from usdb_syncer.usdb_scraper import SongDetails
from usdb_syncer.utils import url_from_resource
from usdb_syncer.utils import video_url_from_resource

IMAGE_DOWNLOAD_HEADERS = {
"User-Agent": (
Expand Down Expand Up @@ -134,7 +134,7 @@ def _ytdl_options(format_: str, _browser: Browser, target_stem: Path) -> YtdlOpt


def _download_resource(options: YtdlOptions, resource: str, logger: Log) -> str | None:
if (url := url_from_resource(resource)) is None:
if (url := video_url_from_resource(resource)) is None:
logger.debug(f"invalid audio/video resource: {resource}")
return None

Expand Down
30 changes: 25 additions & 5 deletions src/usdb_syncer/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,11 @@ class SettingKey(Enum):
TXT = "downloads/txt"
ENCODING = "downloads/encoding"
NEWLINE = "downloads/newline"
FORMAT_VERSION = "downloads/format_version"
FIX_LINEBREAKS = "fixes/linebreaks"
FIX_FIRST_WORDS_CAPITALIZATION = "fixes/firstwordscapitalization"
FIX_SPACES = "fixes/spaces"
FIX_QUOTATION_MARKS = "fixes/quotationmarks"
FIX_QUOTATION_MARKS = "fixes/quotation_marks"
AUDIO = "downloads/audio"
AUDIO_FORMAT = "downloads/audio_format"
AUDIO_BITRATE = "downloads/audio_bitrate"
Expand Down Expand Up @@ -146,6 +147,17 @@ def default() -> Newline:
return Newline.LF


class FormatVersion(Enum):
"""Supported format versions for song txts."""

V1_0_0 = "1.0.0"
V1_1_0 = "1.1.0"
V1_2_0 = "1.2.0"

def __str__(self) -> str:
return str(self.value)


class FixLinebreaks(Enum):
"""Supported variants for fixing linebreak timings."""

Expand Down Expand Up @@ -624,6 +636,14 @@ def set_audio_embed_artwork(value: bool) -> None:
set_setting(SettingKey.AUDIO_EMBED_ARTWORK, value)


def get_encoding() -> Encoding:
return get_setting(SettingKey.ENCODING, Encoding.UTF_8)


def set_encoding(value: Encoding) -> None:
set_setting(SettingKey.ENCODING, value)


def get_newline() -> Newline:
return get_setting(SettingKey.NEWLINE, Newline.default())

Expand All @@ -632,12 +652,12 @@ def set_newline(value: Newline) -> None:
set_setting(SettingKey.NEWLINE, value)


def get_encoding() -> Encoding:
return get_setting(SettingKey.ENCODING, Encoding.UTF_8)
def get_version() -> FormatVersion:
return get_setting(SettingKey.FORMAT_VERSION, FormatVersion.V1_0_0)


def set_encoding(value: Encoding) -> None:
set_setting(SettingKey.ENCODING, value)
def set_version(value: FormatVersion) -> None:
set_setting(SettingKey.FORMAT_VERSION, value)


def get_txt() -> bool:
Expand Down
Loading
Loading