-
Notifications
You must be signed in to change notification settings - Fork 0
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
Sourcery refactored main branch #28
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,18 +24,20 @@ | |
A fast, powerful and simple-to-use graphical CD ripper | ||
""" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
|
||
__major__ = 0 | ||
__minor__ = 1 | ||
__release__ = 0 | ||
__prerelease__ = "" # alpha, beta, rc etc. | ||
|
||
# package information | ||
__name__ = "ffripper" | ||
if __release__ == 0: | ||
__version__ = "{0}.{1}".format(__major__, __minor__) | ||
else: | ||
__version__ = "{0}.{1}.{2}".format(__major__, __minor__, __release__) | ||
__version__ += __prerelease__ | ||
__version__ = ( | ||
"{0}.{1}".format(__major__, __minor__) | ||
if __release__ == 0 | ||
else "{0}.{1}.{2}".format(__major__, __minor__, __release__) | ||
) + __prerelease__ | ||
|
||
__description__ = "Fast audio-cd ripper" | ||
__author__ = "Stefan Garlonta" | ||
__author_email__ = "[email protected]" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,22 +68,57 @@ def parse_for_tracks(self): | |
if self.dict['disc']['release-list'][0]['medium-list'][i]['disc-list'][f]['id'] == self.disc_id: | ||
self._mb_id = self.dict['disc']['release-list'][0]['id'] | ||
self._release = self.dict['disc']['release-list'][0]['medium-list'][i] | ||
for j in range(len(self.dict['disc']['release-list'][0]['medium-list'][i]['track-list'])): | ||
tracks.append( | ||
TrackInfo(self.dict['disc']['release-list'][0]['medium-list'][i]['track-list'][j] | ||
['recording']["title"], | ||
self.dict['disc']['release-list'][0]['medium-list'][i]['track-list'][j][ | ||
'length'], | ||
self.dict['disc']['release-list'][0]['date'], | ||
self.dict['disc']['release-list'][0]['medium-list'][i]['track-list'] | ||
[j]['recording']['artist-credit'][0]['artist']['name'])) | ||
tracks.extend( | ||
TrackInfo( | ||
self.dict['disc']['release-list'][0][ | ||
'medium-list' | ||
][i]['track-list'][j]['recording']["title"], | ||
self.dict['disc']['release-list'][0][ | ||
'medium-list' | ||
][i]['track-list'][j]['length'], | ||
self.dict['disc']['release-list'][0]['date'], | ||
self.dict['disc']['release-list'][0][ | ||
'medium-list' | ||
][i]['track-list'][j]['recording'][ | ||
'artist-credit' | ||
][ | ||
0 | ||
][ | ||
'artist' | ||
][ | ||
'name' | ||
], | ||
) | ||
for j in range( | ||
len( | ||
self.dict['disc']['release-list'][0][ | ||
'medium-list' | ||
][i]['track-list'] | ||
) | ||
) | ||
) | ||
|
||
except IndexError: | ||
for i in range(len(self.dict['disc']['release-list'][0]['medium-list'][0]['track-list'])): | ||
tracks.append( | ||
TrackInfo(self.dict['disc']['release-list'][0]['medium-list'][0]['track-list'][i]['recording'][ | ||
"title"], | ||
self.dict['disc']['release-list'][0]['medium-list'][0]['track-list'][i]['length'], | ||
self.dict['disc']['release-list'][0]['date'], None)) | ||
tracks.extend( | ||
TrackInfo( | ||
self.dict['disc']['release-list'][0]['medium-list'][0][ | ||
'track-list' | ||
][i]['recording']["title"], | ||
self.dict['disc']['release-list'][0]['medium-list'][0][ | ||
'track-list' | ||
][i]['length'], | ||
self.dict['disc']['release-list'][0]['date'], | ||
None, | ||
) | ||
for i in range( | ||
len( | ||
self.dict['disc']['release-list'][0]['medium-list'][0][ | ||
'track-list' | ||
] | ||
) | ||
) | ||
) | ||
|
||
Comment on lines
-71
to
+121
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return tracks | ||
|
||
def parse_for_cover(self): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,19 +53,21 @@ def bytes2pixbuf(data, | |
return _loader.get_pixbuf() | ||
|
||
@staticmethod | ||
def bytes2png(data, output_dir, filename): # type: (bytes, str, str) -> str | ||
def bytes2png(data, output_dir, filename): # type: (bytes, str, str) -> str | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
""" | ||
writes raw bytes to .png file | ||
:param data: raw bytes | ||
:param output_dir: path to output folder | ||
:param filename: name of the file (file extension is added automatically) | ||
:return: the full path to image | ||
""" | ||
_result_file = output_dir + "/" + filename | ||
_result_file = f"{output_dir}/{filename}" | ||
try: | ||
_image = PilImage.open(io.BytesIO(data)) | ||
_image.save(_result_file + '.png', 'PNG') | ||
return _result_file + ".png" | ||
_image.save(f'{_result_file}.png', 'PNG') | ||
return f"{_result_file}.png" | ||
except PermissionError as e: | ||
raise RipperError(Reason.PERMISIONERROR, "Unable to write to {}".format(output_dir)) from e | ||
raise RipperError( | ||
Reason.PERMISIONERROR, f"Unable to write to {output_dir}" | ||
) from e | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ def set_file(self, filepath: str): | |
:param filepath: str (path to audio file) | ||
""" | ||
self.filepath = filepath | ||
self._player.set_property("uri", "file://" + self.filepath) | ||
self._player.set_property("uri", f"file://{self.filepath}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def set_volume(self, volume): | ||
""" | ||
|
@@ -97,7 +97,7 @@ def __on_message(self, bus, message): | |
elif t == Gst.MessageType.ERROR: | ||
self._player.set_state(Gst.State.NULL) | ||
err, debug = message.parse_error() | ||
print("Error: %s" % err, debug) | ||
print(f"Error: {err}", debug) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def get_duration(self): | ||
""" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,17 +60,13 @@ def __init__(self, input_location, output_location, file_format, listener, metad | |
def create_album_directory(self): | ||
if self.album_directory: | ||
self.output_location = os.path.join(self.output_location, self.meta.get_album()) | ||
logger.info("Creating Path {}".format( | ||
self.output_location | ||
)) | ||
logger.info(f"Creating Path {self.output_location}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.mkdir(self.output_location) | ||
|
||
def create_artist_directory(self): | ||
if self.artist_directory: | ||
self.output_location = os.path.join(self.output_location, self.meta.get_artist()) | ||
logger.info("Creating Path {}".format( | ||
self.output_location | ||
)) | ||
logger.info(f"Creating Path {self.output_location}") | ||
Comment on lines
-71
to
+69
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.mkdir(self.output_location) | ||
|
||
@staticmethod | ||
|
@@ -96,14 +92,14 @@ def filter_files_by_extension(listed_dir, extension): | |
] | ||
|
||
def run(self): | ||
logger.info("Started at {}".format(time.time())) | ||
logger.info(f"Started at {time.time()}") | ||
start_time = [] | ||
self.create_dirs() | ||
for i in range(len(self.audio_files)): | ||
if not self.should_continue: | ||
return | ||
start_time.append(time.time()) | ||
logger.debug("{}: starting subprocess {}".format(time.time(), i)) | ||
logger.debug(f"{time.time()}: starting subprocess {i}") | ||
Comment on lines
-99
to
+102
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
cover_art_stream = ( | ||
"" if self.cover is None else "-i \"{0}\"".format(self.cover) | ||
) | ||
|
@@ -147,6 +143,6 @@ def create_dirs(self): | |
self.create_album_directory() | ||
|
||
def rm_cover(self): | ||
path = os.path.join(self.base_location + "/cover.png") | ||
path = os.path.join(f"{self.base_location}/cover.png") | ||
Comment on lines
-150
to
+146
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
if os.path.exists(path): # Else it has been deleted from outside | ||
os.remove(path) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,14 +52,10 @@ def parse_output(self): | |
break | ||
myline += out | ||
if out in ('\r', '\n'): | ||
m = re.search("Duration: ([0-9:.]+)", myline) | ||
if m: | ||
total = duration_in_seconds(m.group(1)) | ||
n = re.search("time=([0-9:]+)", myline) | ||
# time can be of format 'time=hh:mm:ss.ts' or 'time=ss.ts' | ||
# depending on ffmpeg version | ||
if n: | ||
time = n.group(1) | ||
if m := re.search("Duration: ([0-9:.]+)", myline): | ||
total = duration_in_seconds(m[1]) | ||
if n := re.search("time=([0-9:]+)", myline): | ||
time = n[1] | ||
Comment on lines
-55
to
+58
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
This removes the following comments ( why? ):
|
||
if ':' in time: | ||
time = duration_in_seconds(time) | ||
now_sec = int(float(time)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,8 +80,8 @@ def on_copy_item(count): | |
@staticmethod | ||
def __main_thread_updater(count): | ||
percentage = count / 100 | ||
logger.debug("Current fraction: {}%".format(window.progressbar.get_fraction() * 100)) | ||
logger.debug("Fraction: {}".format(percentage)) | ||
logger.debug(f"Current fraction: {window.progressbar.get_fraction() * 100}%") | ||
logger.debug(f"Fraction: {percentage}") | ||
Comment on lines
-83
to
+84
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
window.progressbar.set_fraction(window.progressbar.get_fraction() + percentage) | ||
|
||
@staticmethod | ||
|
@@ -177,7 +177,7 @@ def __create_year_column(self): | |
|
||
def set_player(self): | ||
if self.is_disc(): | ||
self.player.set_file(self.disc.mount_point + "/" + self.disc_tracks[0]) | ||
self.player.set_file(f"{self.disc.mount_point}/{self.disc_tracks[0]}") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def set_cover_image(self): | ||
try: | ||
|
@@ -384,10 +384,10 @@ def refresh_button(self, player): | |
self.player_button.set_image(self.play_image) | ||
|
||
def on_tree_view_columns_changed(self, widget, row, column): | ||
logger.debug("Changed row: {}".format(row)) | ||
logger.debug(f"Changed row: {row}") | ||
self.player.reset() | ||
index = int(row.get_indices()[0]) | ||
self.player.set_file(self.disc.mount_point + "/" + self.disc_tracks[index]) | ||
self.player.set_file(f"{self.disc.mount_point}/{self.disc_tracks[index]}") | ||
Comment on lines
-387
to
+390
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self.player_button.set_image(self.pause_image) | ||
self.player.play() | ||
|
||
|
@@ -466,9 +466,9 @@ def is_disc(self): | |
|
||
def main(builder, data): | ||
global window | ||
window = RipperWindow(builder, data + "settings.yaml") | ||
window = RipperWindow(builder, f"{data}settings.yaml") | ||
load = Loader() | ||
load.load_formats(formats) | ||
load.load_settings(data + "settings.yaml") | ||
load.load_settings(f"{data}settings.yaml") | ||
Comment on lines
-469
to
+472
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
logger.info("Started FFRipper") | ||
Gtk.main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,10 +62,8 @@ def chooser(): | |
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK | ||
) | ||
dialog.set_default_size(800, 400) | ||
folder = None | ||
response = dialog.run() | ||
if response == Gtk.ResponseType.OK: | ||
folder = dialog.get_filename() | ||
folder = dialog.get_filename() if response == Gtk.ResponseType.OK else None | ||
Comment on lines
-65
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
dialog.destroy() | ||
return folder | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines
30-30
refactored with the following changes:use-fstring-for-formatting
)