Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4c563fa

Browse files
author
Sourcery AI
committed
'Refactored by Sourcery'
1 parent 70f06ba commit 4c563fa

File tree

7 files changed

+51
-56
lines changed

7 files changed

+51
-56
lines changed

‎ffmpeg_streaming/_clouds.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def download(self, filename=None, **options):
7878
try:
7979
with filename as f:
8080
self.s3.download_fileobj(bucket_name, key, f)
81-
logging.info("The "+filename.name+" file was downloaded")
81+
logging.info(f'The {filename.name}file was downloaded')
8282
except self.err as e:
8383
logging.error(e)
8484
raise RuntimeError(e)
@@ -174,7 +174,7 @@ def download(self, filename=None, **options):
174174

175175
try:
176176
self.block_blob_service.get_blob_to_path(container, blob, filename)
177-
logging.info("The "+filename+" file was downloaded")
177+
logging.info(f'The {filename}file was downloaded')
178178
except:
179179
error = "An error occurred while downloading the file"
180180
logging.error(error)

‎ffmpeg_streaming/_command_builder.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def _get_audio_bitrate(rep, index: int = None):
4040
@TODO: add documentation
4141
"""
4242
if rep.bitrate.audio_ is not None and rep.bitrate.audio_ != 0:
43-
opt = 'b:a' if index is None else 'b:a:'+str(index)
43+
opt = 'b:a' if index is None else f'b:a:{index}'
4444
return {opt: rep.bitrate.audio}
4545

4646
return {}
@@ -52,9 +52,10 @@ def _get_dash_stream(key, rep):
5252
"""
5353
args = {
5454
'map': 0,
55-
's:v:'+str(key): rep.size,
56-
'b:v:'+str(key): rep.bitrate.calc_video()
55+
f's:v:{str(key)}': rep.size,
56+
f'b:v:{str(key)}': rep.bitrate.calc_video(),
5757
}
58+
5859
args.update(_get_audio_bitrate(rep, key))
5960
args.update(rep.options)
6061
return cnv_options_to_args(args)

‎ffmpeg_streaming/_hls_helper.py‎

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ def update_suffix(self):
6464
@TODO: add documentation
6565
"""
6666
unique = uuid.uuid4()
67-
self.path = self.c_path+"-"+str(unique)
68-
self.url = self.c_url+"-"+str(unique)
67+
self.path = f'{self.c_path}-{str(unique)}'
68+
self.url = f'{self.c_url}-{str(unique)}'
6969

7070
def rotate_key(self, line: str):
7171
"""
@@ -88,11 +88,12 @@ def sub_info(rep, sub_path) -> list:
8888
"""
8989
tag = '#EXT-X-MEDIA:'
9090
info = [
91-
f'TYPE=SUBTITLES',
92-
f'GROUP-ID="subs"',
93-
f'NAME="subtitles"',
94-
f'URI="'+sub_path+'"'
91+
'TYPE=SUBTITLES',
92+
'GROUP-ID="subs"',
93+
'NAME="subtitles"',
94+
f'URI="{sub_path}'+'"',
9595
]
96+
9697
return [tag + ",".join(info)]
9798

9899
def stream_info(rep, sub_exists) -> list:
@@ -106,7 +107,7 @@ def stream_info(rep, sub_exists) -> list:
106107
f'NAME="{rep.size.height}"'
107108
]
108109
if sub_exists:
109-
info.append(f'SUBTITLES="subs"')
110+
info.append('SUBTITLES="subs"')
110111
custom = rep.options.pop('stream_info', [])
111112

112113
return [tag + ",".join(info + custom)]
@@ -133,8 +134,9 @@ def _content(self) -> str:
133134
content = ['#EXTM3U'] + self._get_version() + self.media.options.get('description', [])
134135

135136
for rep in self.media.reps:
136-
sub_exists=os.path.isfile(os.path.dirname(self.media.output_)+'/'+self.sub_path(rep)[0])
137-
if(sub_exists):
137+
if sub_exists := os.path.isfile(
138+
os.path.dirname(self.media.output_) + '/' + self.sub_path(rep)[0]
139+
):
138140
content += sub_info(rep,self.sub_path(rep)[0]) + stream_info(rep,sub_exists) + self.stream_path(rep)
139141
else:
140142
content += stream_info(rep,sub_exists) + self.stream_path(rep)
@@ -146,7 +148,7 @@ def _get_version(self) -> list:
146148
@TODO: add documentation
147149
"""
148150
version = "7" if self.media.options.get('hls_segment_type', '') == 'fmp4' else "3"
149-
return ['#EXT-X-VERSION:'+version]
151+
return [f'#EXT-X-VERSION:{version}']
150152

151153
def stream_path(self, rep):
152154
"""

‎ffmpeg_streaming/_input.py‎

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,17 @@ def __init__(self, video, options):
2626
self.video = video
2727

2828
def _linux(self):
29-
is_screen = self.options.pop('screen', False)
30-
if is_screen:
31-
cap = 'x11grab'
32-
else:
33-
cap = 'v4l2'
34-
29+
cap = 'x11grab' if (is_screen := self.options.pop('screen', False)) else 'v4l2'
3530
return {
3631
'f': cap,
3732
'i': self.video
3833
}
3934

4035
def _windows(self):
41-
self.video = 'video='+str(self.video)
36+
self.video = f'video={str(self.video)}'
4237
windows_audio = self.options.pop('windows_audio', None)
4338
if windows_audio is not None:
44-
self.video = self.video+':audio='+str(windows_audio)
39+
self.video = f'{self.video}:audio={str(windows_audio)}'
4540

4641
return {
4742
'f': 'dshow',
@@ -59,7 +54,7 @@ def _unknown():
5954
raise OSError("Unreported OS!")
6055

6156
def __iter__(self):
62-
yield from getattr(self, '_'+get_os())().items()
57+
yield from getattr(self, f'_{get_os()}')().items()
6358

6459

6560
def get_from_cloud(_cloud: Clouds, options: dict):
@@ -69,10 +64,7 @@ def get_from_cloud(_cloud: Clouds, options: dict):
6964
global cloud
7065
if cloud is None:
7166
save_to = options.pop('save_to', None)
72-
cloud = {
73-
'i': _cloud.download(save_to, **options),
74-
'is_tmp': True if save_to is None else False
75-
}
67+
cloud = {'i': _cloud.download(save_to, **options), 'is_tmp': save_to is None}
7668

7769
return cloud
7870

‎ffmpeg_streaming/_media.py‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,7 @@ def run(self, ffmpeg_bin, monitor: callable = None, **options):
115115
"""
116116
@TODO: add documentation
117117
"""
118-
async_run = options.pop('async_run', True)
119-
120-
if async_run:
118+
if async_run := options.pop('async_run', True):
121119
asyncio.run(self.async_run(ffmpeg_bin, monitor, **options))
122120
else:
123121
self._run(ffmpeg_bin, monitor, **options)
@@ -150,7 +148,12 @@ def add_filter(self, *_filter: str):
150148
@TODO: add documentation
151149
"""
152150
_filters = self.options.pop('filter_complex', None)
153-
_filters = _filters + "," + ",".join(list(_filter)) if _filters is not None else ",".join(list(_filter))
151+
_filters = (
152+
f'{_filters},' + ",".join(list(_filter))
153+
if _filters is not None
154+
else ",".join(list(_filter))
155+
)
156+
154157
self.options.update({'filter_complex': _filters})
155158

156159
def watermarking(self, path, _filter='overlay=10:10'):
@@ -215,7 +218,12 @@ def flags(self, *flags: str):
215218
@TODO: add documentation
216219
"""
217220
hls_flags = self.options.pop('hls_flags', None)
218-
hls_flags = hls_flags + "+" + "+".join(list(flags)) if hls_flags is not None else "+".join(list(flags))
221+
hls_flags = (
222+
f'{hls_flags}+' + "+".join(list(flags))
223+
if hls_flags is not None
224+
else "+".join(list(flags))
225+
)
226+
219227
self.options.update({'hls_flags': hls_flags})
220228

221229
def finish_up(self):
@@ -244,7 +252,7 @@ def __init__(self, _inputs):
244252
self.inputs = _inputs
245253

246254
first_input = dict(copy.copy(_inputs.inputs[0]))
247-
self.input = first_input.get('i', None)
255+
self.input = first_input.get('i')
248256
self.input_temp = first_input.get('is_tmp', False)
249257

250258
def hls(self, _format: Format, **hls_options):

‎ffmpeg_streaming/_reperesentation.py‎

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ def min_bitrate(bitrate: int) -> int:
3030
"""
3131
@TODO: add documentation
3232
"""
33-
if bitrate < MINIMUM_BITRATE:
34-
return MINIMUM_BITRATE
35-
36-
return bitrate
33+
return max(bitrate, MINIMUM_BITRATE)
3734

3835

3936
def reduce_bitrate(bitrate: Bitrate, divide: int) -> Bitrate:
@@ -68,7 +65,7 @@ def __init__(self, original_size: Size, original_bitrate: Bitrate, _format: Form
6865
self._format = _format
6966
self.heights = heights if heights is not None else [2160, 1440, 1080, 720, 480, 360, 240, 144]
7067
self.bitrate = bitrate
71-
self.is_default = Trueifheights is not None and bitrate is not NoneelseFalse
68+
self.is_default = heights is not None and bitrate is not None
7269

7370
if heights is not None and bitrate is not None and len(heights) != len(bitrate):
7471
raise ValueError("The length of heights list must the same as length of bitrate")
@@ -90,14 +87,13 @@ def __next__(self):
9087
"""
9188
@TODO: add documentation
9289
"""
93-
if self.index < len(self.heights):
94-
height = self.heights[self.index]
95-
width = self.original_size.ratio.calculate_width(height, self._format.multiply())
96-
self.index += 1
97-
98-
return Representation(Size(width, height), cal_bitrate(self.bitrate, self.original_bitrate, self.index))
99-
else:
90+
if self.index >= len(self.heights):
10091
raise StopIteration
92+
height = self.heights[self.index]
93+
width = self.original_size.ratio.calculate_width(height, self._format.multiply())
94+
self.index += 1
95+
96+
return Representation(Size(width, height), cal_bitrate(self.bitrate, self.original_bitrate, self.index))
10197

10298

10399
__all__ = [

‎ffmpeg_streaming/_utiles.py‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ def mkdir(dirname: str) -> None:
3636
os.makedirs(dirname)
3737
except OSError as exc:
3838
logging.info(exc)
39-
pass
4039

4140

4241
def rm(path: str) -> None:
@@ -47,7 +46,6 @@ def rm(path: str) -> None:
4746
os.remove(path)
4847
except OSError as exc:
4948
logging.info(exc)
50-
pass
5149

5250

5351
def clean_args(args: list) -> list:
@@ -105,16 +103,14 @@ def get_os():
105103
"""
106104
@TODO: add documentation
107105
"""
108-
if platform =="linux"orplatform=="linux2":
109-
os_name= 'linux'
106+
if platform in ["linux", "linux2"]:
107+
return 'linux'
110108
elif platform == "darwin":
111-
os_name= 'os_x'
112-
elif platform =="win32"orplatform=="Windows":
113-
os_name= 'windows'
109+
return 'os_x'
110+
elif platform in ["win32", "Windows"]:
111+
return 'windows'
114112
else:
115-
os_name = 'unknown'
116-
117-
return os_name
113+
return 'unknown'
118114

119115

120116
def cnv_options_to_args(options: dict):

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /