refactor: Rename constants.string into tr.
This commit is contained in:
@ -75,7 +75,7 @@ class FileItem(BaseItem):
|
||||
if not os.path.exists(self.uri()):
|
||||
self.log.info(
|
||||
"file: music file missed for %s" % self.format_debug_string())
|
||||
raise ValidationFailedError(constants.strings('file_missed', file=self.path))
|
||||
raise ValidationFailedError(constants.tr('file_missed', file=self.path))
|
||||
|
||||
if self.duration == 0:
|
||||
self.duration = util.get_media_duration(self.uri())
|
||||
@ -185,14 +185,14 @@ class FileItem(BaseItem):
|
||||
)
|
||||
|
||||
def format_song_string(self, user):
|
||||
return constants.strings("file_item",
|
||||
title=self.title,
|
||||
artist=self.artist if self.artist else '??',
|
||||
user=user
|
||||
)
|
||||
return constants.tr("file_item",
|
||||
title=self.title,
|
||||
artist=self.artist if self.artist else '??',
|
||||
user=user
|
||||
)
|
||||
|
||||
def format_current_playing(self, user):
|
||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
||||
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||
if self.thumbnail:
|
||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||
self.thumbnail + '"/>'
|
||||
@ -208,4 +208,4 @@ class FileItem(BaseItem):
|
||||
return title
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("file")
|
||||
return constants.tr("file")
|
||||
|
@ -147,18 +147,18 @@ class RadioItem(BaseItem):
|
||||
)
|
||||
|
||||
def format_song_string(self, user):
|
||||
return constants.strings("radio_item",
|
||||
url=self.url,
|
||||
title=get_radio_title(self.url), # the title of current song
|
||||
name=self.title, # the title of radio station
|
||||
user=user
|
||||
)
|
||||
return constants.tr("radio_item",
|
||||
url=self.url,
|
||||
title=get_radio_title(self.url), # the title of current song
|
||||
name=self.title, # the title of radio station
|
||||
user=user
|
||||
)
|
||||
|
||||
def format_current_playing(self, user):
|
||||
return constants.strings("now_playing", item=self.format_song_string(user))
|
||||
return constants.tr("now_playing", item=self.format_song_string(user))
|
||||
|
||||
def format_title(self):
|
||||
return self.title if self.title else self.url
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("radio")
|
||||
return constants.tr("radio")
|
||||
|
18
media/url.py
18
media/url.py
@ -99,7 +99,7 @@ class URLItem(BaseItem):
|
||||
# Check the length, useful in case of playlist, it wasn't checked before)
|
||||
log.info(
|
||||
"url: " + self.url + " has a duration of " + str(self.duration / 60) + " min -- too long")
|
||||
raise ValidationFailedError(constants.strings('too_long', song=self.title))
|
||||
raise ValidationFailedError(constants.tr('too_long', song=self.title))
|
||||
else:
|
||||
self.ready = "validated"
|
||||
self.version += 1 # notify wrapper to save me
|
||||
@ -138,7 +138,7 @@ class URLItem(BaseItem):
|
||||
if not succeed:
|
||||
self.ready = 'failed'
|
||||
self.log.error("url: error while fetching info from the URL")
|
||||
raise ValidationFailedError(constants.strings('unable_download', item=self.format_title()))
|
||||
raise ValidationFailedError(constants.tr('unable_download', item=self.format_title()))
|
||||
|
||||
def _download(self):
|
||||
media.system.clear_tmp_folder(var.tmp_folder, var.config.getint('bot', 'tmp_folder_max_size'))
|
||||
@ -193,7 +193,7 @@ class URLItem(BaseItem):
|
||||
os.remove(f)
|
||||
self.ready = "failed"
|
||||
self.downloading = False
|
||||
raise PreparationFailedError(constants.strings('unable_download', item=self.format_title()))
|
||||
raise PreparationFailedError(constants.tr('unable_download', item=self.format_title()))
|
||||
|
||||
def _read_thumbnail_from_file(self, path_thumbnail):
|
||||
if os.path.isfile(path_thumbnail):
|
||||
@ -226,14 +226,14 @@ class URLItem(BaseItem):
|
||||
|
||||
def format_song_string(self, user):
|
||||
if self.ready in ['validated', 'yes']:
|
||||
return constants.strings("url_item",
|
||||
title=self.title if self.title else "??",
|
||||
url=self.url,
|
||||
user=user)
|
||||
return constants.tr("url_item",
|
||||
title=self.title if self.title else "??",
|
||||
url=self.url,
|
||||
user=user)
|
||||
return self.url
|
||||
|
||||
def format_current_playing(self, user):
|
||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
||||
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||
|
||||
if self.thumbnail:
|
||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||
@ -246,4 +246,4 @@ class URLItem(BaseItem):
|
||||
return self.title if self.title.strip() else self.url
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("url")
|
||||
return constants.tr("url")
|
||||
|
@ -96,15 +96,15 @@ class PlaylistURLItem(URLItem):
|
||||
)
|
||||
|
||||
def format_song_string(self, user):
|
||||
return constants.strings("url_from_playlist_item",
|
||||
title=self.title,
|
||||
url=self.url,
|
||||
playlist_url=self.playlist_url,
|
||||
playlist=self.playlist_title,
|
||||
user=user)
|
||||
return constants.tr("url_from_playlist_item",
|
||||
title=self.title,
|
||||
url=self.url,
|
||||
playlist_url=self.playlist_url,
|
||||
playlist=self.playlist_title,
|
||||
user=user)
|
||||
|
||||
def format_current_playing(self, user):
|
||||
display = constants.strings("now_playing", item=self.format_song_string(user))
|
||||
display = constants.tr("now_playing", item=self.format_song_string(user))
|
||||
|
||||
if self.thumbnail:
|
||||
thumbnail_html = '<img width="80" src="data:image/jpge;base64,' + \
|
||||
@ -114,4 +114,4 @@ class PlaylistURLItem(URLItem):
|
||||
return display
|
||||
|
||||
def display_type(self):
|
||||
return constants.strings("url_from_playlist")
|
||||
return constants.tr("url_from_playlist")
|
||||
|
Reference in New Issue
Block a user