@@ -5,6 +5,7 @@ import okhttp3.OkHttpClient
55import org.openedx.core.module.download.AbstractDownloader
66import org.openedx.core.utils.Directories
77import org.openedx.core.utils.IOUtils
8+ import org.openedx.core.utils.Logger
89import org.openedx.core.utils.Sha1Util
910import org.openedx.foundation.utils.FileUtil
1011import subtitleFile.FormatSRT
@@ -21,6 +22,8 @@ class TranscriptManager(
2122 val fileUtil : FileUtil
2223) {
2324
25+ private val logger = Logger (TAG )
26+
2427 private val transcriptDownloader = object : AbstractDownloader () {
2528 override val client: OkHttpClient
2629 get() = OkHttpClient .Builder ().build()
@@ -62,17 +65,18 @@ class TranscriptManager(
6265 }
6366
6467 private suspend fun startTranscriptDownload (downloadLink : String ) {
65- if (! has(downloadLink)) {
66- val file = File (getTranscriptDir(), Sha1Util .SHA1 (downloadLink))
67- val result = transcriptDownloader.download(
68- downloadLink,
69- file.path
70- )
71- if (result == AbstractDownloader .DownloadResult .SUCCESS ) {
72- getInputStream(downloadLink)?.let {
73- val transcriptTimedTextObject =
74- convertIntoTimedTextObject(it)
75- transcriptObject = transcriptTimedTextObject
68+ if (has(downloadLink)) return
69+ val file = File (getTranscriptDir(), Sha1Util .SHA1 (downloadLink))
70+ val result = transcriptDownloader.download(
71+ downloadLink,
72+ file.path
73+ )
74+ if (result == AbstractDownloader .DownloadResult .SUCCESS ) {
75+ getInputStream(downloadLink)?.let {
76+ try {
77+ transcriptObject = convertIntoTimedTextObject(it)
78+ } catch (e: NullPointerException ) {
79+ logger.e(throwable = e, submitCrashReport = true )
7680 }
7781 }
7882 }
@@ -86,7 +90,7 @@ class TranscriptManager(
8690 try {
8791 transcriptObject = convertIntoTimedTextObject(transcriptInputStream)
8892 } catch (e: Exception ) {
89- e.printStackTrace( )
93+ logger.e(throwable = e, submitCrashReport = true )
9094 }
9195 } else {
9296 startTranscriptDownload(transcriptUrl)
@@ -127,6 +131,7 @@ class TranscriptManager(
127131 }
128132
129133 companion object {
134+ private const val TAG = " TranscriptManager"
130135 private const val FILE_VALIDITY_DURATION_HOURS = 5L
131136 }
132137}
0 commit comments