Skip to content

Commit

Permalink
update version migration function
Browse files Browse the repository at this point in the history
  • Loading branch information
justin025 committed Jan 27, 2025
1 parent 40d788d commit c7657fa
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 115 deletions.
60 changes: 2 additions & 58 deletions src/onthespot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,64 +45,8 @@ def quit_application(self):

def main():
logger.info('Starting application in \n3\n2\n1')
version = "v1.0.7"
logger.info(f'OnTheSpot Version: {version}')

if config.get('version') != version:
config.set("version", version)

# Migration (>v1.0.3)
if isinstance(config.get("file_hertz"), str):
config.set("file_hertz", int(config.get("file_hertz")))

# Migration (>v1.0.4)
if config.get('theme') == 'dark':
config.set('theme', f'background-color: #282828; color: white;')
elif config.get('theme') == 'light':
config.set('theme', f'background-color: white; color: black;')

# Migration (>v1.0.5)
cfg_copy = config.get('accounts').copy()
for account in cfg_copy:
if account['uuid'] == 'public_youtube':
account['uuid'] = 'public_youtube_music'
account['service'] = 'youtube_music'
config.set('accounts', cfg_copy)

# Migration (>v1.0.7)
config.set('active_account_number', config.get('parsing_acc_sn'))
config.set('thumbnail_size', config.get('search_thumb_height'))
config.set('disable_download_popups', config.get('disable_bulk_dl_notices'))
config.set('raw_media_download', config.get('force_raw'))
config.set('download_chunk_size', config.get('chunk_size'))
config.set('rotate_active_account_number', config.get('rotate_acc_sn'))
config.set('audio_download_path', config.get('download_root'))
config.set('track_file_format', config.get('media_format'))
config.set('podcast_file_format', config.get('podcast_media_format'))
config.set('video_download_path', config.get('generic_download_root'))
config.set('create_m3u_file', config.get('create_m3u_playlists'))
config.set('m3u_path_formatter', config.get('m3u_name_formatter'))
config.set('enable_search_podcasts', config.get('enable_search_shows'))
config.set('extinf_separator', config.get('ext_seperator'))
config.set('extinf_label', config.get('ext_path'))
config.set('download_lyrics', config.get('inp_enable_lyrics'))
config.set('save_lrc_file', config.get('use_lrc_file'))
config.set('only_download_synced_lyrics', config.get('only_synced_lyrics'))
config.set('preferred_video_resolution', config.get('maximum_generic_resolution'))
config.set('use_custom_file_bitrate', True)

# Language
if config.get("language_index") == 0:
config.set("language", "en_US")
elif config.get("language_index") == 1:
config.set("language", "de_DE")
elif config.get("language_index") == 2:
config.set("language", "pt_PT")
else:
logger.info(f'Unknown language index: {config.get("language_index")}')
config.set("language", "en_US")

config.update()
config.migration()
logger.info(f'OnTheSpot Version: {config.get("version")}')

app = QApplication(sys.argv)

Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def get_account_token(item_service):
if item_service == account_pool[index]['service']:
if config.get("rotate_active_account_number"):
config.set('active_account_number', index)
#config.update()
#config.save()
return globals()[f"{item_service}_get_token"](index)
2 changes: 1 addition & 1 deletion src/onthespot/api/apple_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def apple_music_add_account(media_user_token):
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def apple_music_login_user(account):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/bandcamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def bandcamp_add_account():
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def bandcamp_get_search_results(_, search_term, content_types):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/crunchyroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def crunchyroll_add_account(email, password):
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def crunchyroll_get_token(parsing_index):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def deezer_add_account(arl):
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def deezer_get_album_track_ids(_, album_id):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def generic_add_account():
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def generic_get_track_metadata(_, url):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/qobuz.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def qobuz_add_account(email, password):
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()

except Exception as e:
logger.error(f"Unknown Exception: {str(e)}")
Expand Down
4 changes: 2 additions & 2 deletions src/onthespot/api/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def soundcloud_login_user(account):
account['login']['client_id'] = client_id
account['login']['app_version'] = app_version
config.set('accounts', cfg_copy)
config.update()
config.save()

account_pool.append({
"uuid": "public_soundcloud",
Expand Down Expand Up @@ -119,7 +119,7 @@ def soundcloud_add_account():
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def soundcloud_get_token(parsing_index):
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def spotify_new_session():
zs.close()
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()
logger.info("New account added to config.")
return True

Expand Down
4 changes: 2 additions & 2 deletions src/onthespot/api/tidal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def tidal_add_account_pt2(device_code):
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()
return True


Expand Down Expand Up @@ -100,7 +100,7 @@ def tidal_login_user(account):
acc['login']['expires_in'] = auth_data["expires_in"] + time.time()
account = acc
config.set('accounts', cfg_copy)
config.update()
config.save()

account_pool.append({
"uuid": account['uuid'],
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/youtube_music.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def youtube_music_add_account():
}
cfg_copy.append(new_user)
config.set('accounts', cfg_copy)
config.update()
config.save()


def youtube_music_get_search_results(_, search_term, content_types):
Expand Down
17 changes: 9 additions & 8 deletions src/onthespot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@

def parse_args():
parser = argparse.ArgumentParser(description="OnTheSpot CLI Downloader")

parser.add_argument('--download', help="Rechercher et télécharger automatiquement un élément via une requête")

args, unknown_args = parser.parse_known_args()

overrides = {}
Expand Down Expand Up @@ -86,10 +86,11 @@ def run(self):
pending[local_id] = item

def main():
config.migration()
print(f'OnTheSpot Version: {config.get("version")}')
args, cli_overrides = parse_args()
config.apply_overrides(cli_overrides)

print("Final configuration after overriding:")
for key, value in cli_overrides.items():
print(f"{key}={value}")

Expand Down Expand Up @@ -155,7 +156,7 @@ def do_help(self, arg):
def do_config(self, arg):
parts = arg.split()
if arg == "reset_settings":
config.rollback()
config.reset()
print('\033[32mReset settings, please restart the app.\033[0m')

if arg == "list_accounts":
Expand All @@ -177,7 +178,7 @@ def add_spotify_account_worker():
if session == True:
print("\033[32mAccount added, please restart the app.\033[0m")
config.set('active_account_number', config.get('active_account_number') + 1)
config.update()
config.save()
elif session == False:
print("\033[32mAccount already exists.\033[0m")

Expand All @@ -198,7 +199,7 @@ def add_spotify_account_worker():
try:
account_number = int(parts[1])
config.set('active_account_number', account_number)
config.update()
config.save()
print(f"\033[32mSelected account number: {account_number}\033[0m")
except ValueError:
print("\033[32mInvalid account number. Please enter a valid integer.\033[0m")
Expand All @@ -209,7 +210,7 @@ def add_spotify_account_worker():
accounts = config.get('accounts').copy()
del accounts[account_number]
config.set('accounts', accounts)
config.update()
config.save()
del account_pool[account_number]
print(f"\033[32mDeleted account number: {account_number}\033[0m")
except ValueError:
Expand Down Expand Up @@ -449,7 +450,7 @@ def display_game_over(win, score):
win.clear()
if score > config.get('snake_high_score', 0):
config.set('snake_high_score', score)
config.update()
config.save()
win.addstr(win.getmaxyx()[0] // 2 - 1, win.getmaxyx()[1] // 2 - 10, 'Game Over!', curses.color_pair(1))
win.addstr(win.getmaxyx()[0] // 2, win.getmaxyx()[1] // 2 - 10, f'Score: {score}', curses.A_BOLD)
win.addstr(win.getmaxyx()[0] // 2 + 1, win.getmaxyx()[1] // 2 - 10, f'High Score: {config.get('snake_high_score', 0)}', curses.A_BOLD)
Expand Down
12 changes: 6 additions & 6 deletions src/onthespot/gui/mainui.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ def open_theme_dialog(self):
# Light color, set dark font and progress bar
stylesheet = f'background-color: {color.name()}; color: black;'
config.set('theme', stylesheet)
config.update()
config.save()
self.centralwidget.setStyleSheet(stylesheet)
self.__splash_dialog.update_theme(stylesheet)

Expand Down Expand Up @@ -259,7 +259,7 @@ def set_table_props(self):


def reset_app_config(self):
config.rollback()
config.reset()
self.show_popup_dialog("The application setting was cleared successfully !\n Please restart the application.")


Expand Down Expand Up @@ -580,12 +580,12 @@ def user_table_remove_click(self):
accounts = config.get('accounts').copy()
del accounts[index]
config.set('accounts', accounts)
config.update()
config.save()

self.tbl_sessions.removeRow(index)
if config.get('active_account_number') == index or config.get('active_account_number') >= len(account_pool):
config.set('active_account_number', 0)
config.update()
config.save()
try:
self.tbl_sessions.cellWidget(0, 0).setChecked(True)
except AttributeError:
Expand Down Expand Up @@ -798,7 +798,7 @@ def add_spotify_account_worker(self):
self.show_popup_dialog(self.tr("Account added, please restart the app."))
self.btn_login_add.setText(self.tr("Please Restart The App"))
config.set('active_account_number', len(account_pool))
config.update()
config.save()
else:
self.show_popup_dialog(self.tr("Account already exists."))
self.btn_login_add.setText(self.tr("Add Account"))
Expand All @@ -822,7 +822,7 @@ def add_tidal_account_worker(self, device_code):
self.show_popup_dialog(self.tr("Account added, please restart the app."))
self.btn_login_add.setText(self.tr("Please Restart The App"))
config.set('active_account_number', len(account_pool))
config.update()
config.save()
else:
self.show_popup_dialog(self.tr("Account already exists."))
self.btn_login_add.setText(self.tr("Add Account"))
Expand Down
10 changes: 5 additions & 5 deletions src/onthespot/gui/qtui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<string notr="true"/>
</property>
<property name="currentIndex">
<number>1</number>
<number>2</number>
</property>
<widget class="QWidget" name="search">
<attribute name="title">
Expand Down Expand Up @@ -716,7 +716,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<y>-1960</y>
<width>627</width>
<height>4132</height>
</rect>
Expand Down Expand Up @@ -2550,7 +2550,7 @@
<enum>Qt::RightToLeft</enum>
</property>
<property name="text">
<string>Download Synced Lyrics Only*</string>
<string>Only Download Synced Lyrics*</string>
</property>
</widget>
</item>
Expand Down Expand Up @@ -4729,8 +4729,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>641</width>
<height>405</height>
<width>140</width>
<height>1309</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,4 +326,4 @@ def save_config(self):
config.set('download_all_available_audio', self.download_all_available_audio.isChecked())
config.set('download_all_available_subtitles', self.download_all_available_subtitles.isChecked())

config.update()
config.save()
Loading

0 comments on commit c7657fa

Please sign in to comment.