Skip to content
This repository was archived by the owner on Aug 1, 2021. It is now read-only.

Commit

Permalink
updated code quality for subtitles, fixed #487 issue with memory leak…
Browse files Browse the repository at this point in the history
…s in subtitles downloading
  • Loading branch information
r0oth3x49 committed Sep 17, 2020
1 parent e258e2a commit 1ade2be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions udemy-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,13 @@ def main():
if args.assets_only:
dl_lecture = False
dl_subtitles = False
args.skip_hls_stream = True
if args.skip_assets:
dl_assets = False
if args.caption_only:
dl_lecture = False
dl_assets = False
args.skip_hls_stream = True
if args.skip_captions:
dl_subtitles = False
if not args.info:
Expand Down
15 changes: 9 additions & 6 deletions udemy/vtt2srt.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"""
from udemy.utils import unescapeHTML
from udemy.compat import os, re, codecs
from udemy.compat import os, re # , codecs


class WebVtt2Srt(object):
Expand All @@ -33,21 +33,24 @@ class WebVtt2Srt(object):
_TIMECODE = r"(?i)(?P<appeartime>(?:(?:\d{1,2}:)){1,2}\d{2}[\.,]\d+)\s*-->\s*(?i)(?P<disappertime>(?:(?:\d{1,2}:)){1,2}\d{2}[\.,]\d+)"

def _vttcontents(self, fname):
content = []
try:
f = codecs.open(filename=fname, encoding="utf-8", errors="ignore")
# f = codecs.open(filename=fname, encoding="utf-8", errors="ignore")
with open(fname, encoding="utf-8", errors="ignore") as f:
content = [line for line in (l.strip() for l in f)]
except Exception as error: # pylint: disable=W
return {
"status": "False",
"msg": f"failed to open file : error: {error} ..",
}
content = [line for line in (l.strip() for l in f)]
f.close()
# content = [line for line in (l.strip() for l in f)]
# f.close()
return content

def _write_srtcontent(self, fname, content):
with codecs.open(filename=fname, mode="a", encoding="utf-8") as fd:
with open(fname, mode="a", encoding="utf-8", errors="ignore") as fd:
fd.write(content)
fd.close()
# fd.close()

def _locate_timecode(self, content):
loc = ""
Expand Down

0 comments on commit 1ade2be

Please sign in to comment.