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

Sourcery refactored main branch #28

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion FFRipper
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ from gi.repository import Gtk
from ffripper.ui import main

builder = Gtk.Builder()
builder.add_from_file("{}/data/ffripper.glade".format(os.path.dirname(os.path.realpath(__file__))))
builder.add_from_file(
f"{os.path.dirname(os.path.realpath(__file__))}/data/ffripper.glade"
)

Comment on lines -30 to +33
Copy link
Author

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:


main(builder, "../data/")
12 changes: 7 additions & 5 deletions ffripper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,20 @@
A fast, powerful and simple-to-use graphical CD ripper
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 34-38 refactored with the following changes:


__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]"
Expand Down
65 changes: 50 additions & 15 deletions ffripper/disc_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CdDiscParser.parse_for_tracks refactored with the following changes:

return tracks

def parse_for_cover(self):
Expand Down
12 changes: 7 additions & 5 deletions ffripper/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Image.bytes2png refactored with the following changes:

"""
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

4 changes: 2 additions & 2 deletions ffripper/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Player.set_file refactored with the following changes:


def set_volume(self, volume):
"""
Expand Down Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Player.__on_message refactored with the following changes:


def get_duration(self):
"""
Expand Down
14 changes: 5 additions & 9 deletions ffripper/process_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CopyProcessor.create_album_directory refactored with the following changes:

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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CopyProcessor.create_artist_directory refactored with the following changes:

self.mkdir(self.output_location)

@staticmethod
Expand All @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CopyProcessor.run refactored with the following changes:

cover_art_stream = (
"" if self.cover is None else "-i \"{0}\"".format(self.cover)
)
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CopyProcessor.rm_cover refactored with the following changes:

if os.path.exists(path): # Else it has been deleted from outside
os.remove(path)
12 changes: 4 additions & 8 deletions ffripper/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FFmpegProgress.parse_output refactored with the following changes:

This removes the following comments ( why? ):

# depending on ffmpeg version
# time can be of format 'time=hh:mm:ss.ts' or 'time=ss.ts'

if ':' in time:
time = duration_in_seconds(time)
now_sec = int(float(time))
Expand Down
14 changes: 7 additions & 7 deletions ffripper/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MyCopyListener.__main_thread_updater refactored with the following changes:

window.progressbar.set_fraction(window.progressbar.get_fraction() + percentage)

@staticmethod
Expand Down Expand Up @@ -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]}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RipperWindow.set_player refactored with the following changes:


def set_cover_image(self):
try:
Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RipperWindow.on_tree_view_columns_changed refactored with the following changes:

self.player_button.set_image(self.pause_image)
self.player.play()

Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

logger.info("Started FFRipper")
Gtk.main()
4 changes: 1 addition & 3 deletions ffripper/ui_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function UiObjects.chooser refactored with the following changes:

dialog.destroy()
return folder

Expand Down