-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Sourcery refactored master branch #83
base: master
Are you sure you want to change the base?
Changes from 1 commit
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 |
---|---|---|
|
@@ -158,11 +158,11 @@ def build_playback_report(youtube: YouTube) -> None: | |
ts = int(dt.datetime.utcnow().timestamp()) | ||
fp = os.path.join(os.getcwd(), f"yt-video-{youtube.video_id}-{ts}.json.gz") | ||
|
||
js = youtube.js | ||
watch_html = youtube.watch_html | ||
vid_info = youtube.vid_info | ||
|
||
with gzip.open(fp, "wb") as fh: | ||
Comment on lines
-161
to
165
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 build_playback_report refactored with the following changes:
|
||
js = youtube.js | ||
watch_html = youtube.watch_html | ||
vid_info = youtube.vid_info | ||
|
||
fh.write( | ||
json.dumps( | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,17 +273,17 @@ def apply_descrambler(stream_data: Dict, key: str) -> None: | |
{'foo': [{'bar': '1', 'var': 'test'}, {'em': '5', 't': 'url encoded'}]} | ||
|
||
""" | ||
otf_type = "FORMAT_STREAM_TYPE_OTF" | ||
|
||
if key == "url_encoded_fmt_stream_map" and not stream_data.get( | ||
"url_encoded_fmt_stream_map" | ||
): | ||
"url_encoded_fmt_stream_map" | ||
): | ||
formats = json.loads(stream_data["player_response"])["streamingData"]["formats"] | ||
formats.extend( | ||
json.loads(stream_data["player_response"])["streamingData"][ | ||
"adaptiveFormats" | ||
] | ||
) | ||
otf_type = "FORMAT_STREAM_TYPE_OTF" | ||
|
||
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 apply_descrambler refactored with the following changes:
|
||
try: | ||
stream_data[key] = [ | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,7 +53,7 @@ def safe_filename(s: str, max_length: int = 255) -> str: | |
A sanitized string. | ||
""" | ||
# Characters in range 0-31 (0x00-0x1F) are not allowed in ntfs filenames. | ||
ntfs_characters = [chr(i) for i in range(0, 31)] | ||
ntfs_characters = [chr(i) for i in range(31)] | ||
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 safe_filename refactored with the following changes:
|
||
characters = [ | ||
r'"', | ||
r"\#", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,10 +131,7 @@ def get_format_profile(itag: int) -> Dict: | |
YouTube format identifier code. | ||
""" | ||
itag = int(itag) | ||
if itag in ITAGS: | ||
res, bitrate = ITAGS[itag] | ||
else: | ||
res, bitrate = None, None | ||
res, bitrate = ITAGS[itag] if itag in ITAGS else (None, None) | ||
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 get_format_profile refactored with the following changes:
|
||
return { | ||
"resolution": res, | ||
"abr": bitrate, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -230,7 +230,7 @@ def download( | |
|
||
bytes_remaining = self.filesize | ||
logger.debug( | ||
"downloading (%s total bytes) file to %s", self.filesize, file_path, | ||
'downloading (%s total bytes) file to %s', bytes_remaining, file_path | ||
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 Stream.download refactored with the following changes:
|
||
) | ||
|
||
with open(file_path, "wb") as fh: | ||
|
@@ -265,10 +265,7 @@ def stream_to_buffer(self, buffer: BinaryIO) -> None: | |
:rtype: io.BytesIO buffer | ||
""" | ||
bytes_remaining = self.filesize | ||
logger.info( | ||
"downloading (%s total bytes) file to buffer", self.filesize, | ||
) | ||
|
||
logger.info('downloading (%s total bytes) file to buffer', bytes_remaining) | ||
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 Stream.stream_to_buffer refactored with the following changes:
|
||
for chunk in request.stream(self.url): | ||
# reduce the (bytes) remainder by the length of the chunk. | ||
bytes_remaining -= len(chunk) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -368,15 +368,15 @@ def test_ffmpeg_process_res_should_download(_ffmpeg_downloader, youtube): | |
@mock.patch("pytube.cli.YouTube") | ||
@mock.patch("pytube.cli._ffmpeg_downloader") | ||
def test_ffmpeg_process_res_none_should_not_download(_ffmpeg_downloader, youtube): | ||
# Given | ||
target = "/target" | ||
Comment on lines
-371
to
-372
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 test_ffmpeg_process_res_none_should_not_download refactored with the following changes:
|
||
streams = MagicMock() | ||
youtube.streams = streams | ||
streams.filter.return_value.first.return_value = None | ||
audio_stream = MagicMock() | ||
streams.get_audio_only.return_value = audio_stream | ||
# When | ||
with pytest.raises(SystemExit): | ||
# Given | ||
target = "/target" | ||
cli.ffmpeg_process(youtube, "XYZp", target) | ||
# Then | ||
_ffmpeg_downloader.assert_not_called() | ||
|
@@ -405,8 +405,6 @@ def test_ffmpeg_process_audio_none_should_fallback_download( | |
@mock.patch("pytube.cli.YouTube") | ||
@mock.patch("pytube.cli._ffmpeg_downloader") | ||
def test_ffmpeg_process_audio_fallback_none_should_exit(_ffmpeg_downloader, youtube): | ||
# Given | ||
target = "/target" | ||
Comment on lines
-408
to
-409
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 test_ffmpeg_process_audio_fallback_none_should_exit refactored with the following changes:
|
||
streams = MagicMock() | ||
youtube.streams = streams | ||
stream = MagicMock() | ||
|
@@ -418,6 +416,8 @@ def test_ffmpeg_process_audio_fallback_none_should_exit(_ffmpeg_downloader, yout | |
streams.get_audio_only.return_value = None | ||
# When | ||
with pytest.raises(SystemExit): | ||
# Given | ||
target = "/target" | ||
cli.ffmpeg_process(youtube, "best", target) | ||
# Then | ||
_ffmpeg_downloader.assert_not_called() | ||
|
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.
Function Caption.download refactored with the following changes: