• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

EsupPortail / Esup-Pod / 9664421460

25 Jun 2024 02:31PM UTC coverage: 70.938%. First build
9664421460

Pull #1139

github

web-flow
Merge 0834a594a into 46941e1c4
Pull Request #1139: [WIP] Ptitloup/remote encoding fix

3 of 16 new or added lines in 3 files covered. (18.75%)

12031 of 16960 relevant lines covered (70.94%)

0.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

47.27
/pod/video_encode_transcript/transcripting_tasks.py
1
"""Esup-Pod transcripting tasks."""
2

3
# pip3 install celery==5.4.0
4
# pip3 install webvtt-py
5
# pip3 install redis==4.5.4
6
from celery import Celery
1✔
7
from tempfile import NamedTemporaryFile
1✔
8
import logging
1✔
9
import os
1✔
10
import requests
1✔
11

12
# call local settings directly
13
# no need to load pod application to send statement
14
try:
1✔
15
    from ..custom import settings_local
1✔
16
except ImportError:
×
17
    from .. import settings as settings_local
×
18

19
logger = logging.getLogger(__name__)
1✔
20

21
EMAIL_HOST = getattr(settings_local, "EMAIL_HOST", "")
1✔
22
DEFAULT_FROM_EMAIL = getattr(settings_local, "DEFAULT_FROM_EMAIL", "")
1✔
23
ADMINS = getattr(settings_local, "ADMINS", ())
1✔
24
DEBUG = getattr(settings_local, "DEBUG", True)
1✔
25
TEST_REMOTE_ENCODE = getattr(settings_local, "TEST_REMOTE_ENCODE", False)
1✔
26

27
admins_email = [ad[1] for ad in ADMINS]
1✔
28

29
if DEBUG:
1✔
30
    logger.setLevel(logging.DEBUG)
1✔
31

32
smtp_handler = logging.handlers.SMTPHandler(
1✔
33
    mailhost=EMAIL_HOST,
34
    fromaddr=DEFAULT_FROM_EMAIL,
35
    toaddrs=admins_email,
36
    subject="[POD TRANSCRIPT] Transcripting Log Mail",
37
)
38
if not TEST_REMOTE_ENCODE:
1✔
39
    logger.addHandler(smtp_handler)
×
40

41
POD_API_URL = getattr(settings_local, "POD_API_URL", "")
1✔
42
POD_API_TOKEN = getattr(settings_local, "POD_API_TOKEN", "")
1✔
43

44
ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
1✔
45
    settings_local, "ENCODING_TRANSCODING_CELERY_BROKER_URL", ""
46
)
47

48
transcripting_app = Celery(
1✔
49
    "transcripting_tasks", broker=ENCODING_TRANSCODING_CELERY_BROKER_URL
50
)
51
transcripting_app.conf.task_routes = {
1✔
52
    "pod.video_encode_transcript.transcripting_tasks.*": {"queue": "transcripting"}
53
}
54
transcripting_app.autodiscover_tasks(packages=None, related_name="", force=False)
1✔
55

56

57
# celery \
58
# -A pod.video_encode_transcript.transcripting_tasks worker \
59
# -l INFO -Q transcripting
60
@transcripting_app.task(bind=True)
1✔
61
def start_transcripting_task(self, video_id, mp3filepath, duration, lang):
1✔
62
    """Start the transcripting of the video."""
63
    from .transcript_model import start_transcripting
×
64
    from ..main.settings import MEDIA_ROOT
×
65

66
    print("Start the transcripting of the video %s" % video_id)
×
67
    print(video_id, mp3filepath, duration, lang)
×
68
    msg, text_webvtt = start_transcripting(mp3filepath, duration, lang)
×
69
    print("End of the transcripting of the video")
×
70
    media_temp_dir = os.path.join(MEDIA_ROOT, "temp")
×
71
    if not os.path.exists(media_temp_dir):
×
72
        os.mkdir(media_temp_dir)
×
73
    temp_vtt_file = NamedTemporaryFile(dir=media_temp_dir, delete=False, suffix=".vtt")
×
74
    text_webvtt.save(temp_vtt_file.name)
×
75
    print("End of the transcoding of the video")
×
76
    Headers = {"Authorization": "Token %s" % POD_API_TOKEN}
×
77
    url = POD_API_URL.strip("/") + "/store_remote_transcripted_video/?id=%s" % video_id
×
78
    data = {"video_id": video_id, "msg": msg, "temp_vtt_file": temp_vtt_file.name}
×
NEW
79
    msg = "Task id : %s\n" % self.request.id
×
80
    try:
×
81
        response = requests.post(url, json=data, headers=Headers)
×
82
        if response.status_code != 200:
×
NEW
83
            msg += "Calling store remote transcoding error: {} {}".format(
×
84
                response.status_code, response.reason
85
            )
86
            logger.error(msg + "\n" + str(response.content))
×
87
        else:
NEW
88
            logger.info(msg + "Call importing transcript task ok")
×
89
    except (
×
90
        requests.exceptions.HTTPError,
91
        requests.exceptions.ConnectionError,
92
        requests.exceptions.InvalidURL,
93
        requests.exceptions.Timeout,
94
    ) as exception:
NEW
95
        msg += "Exception: {}".format(type(exception).__name__)
×
96
        msg += "\nException message: {}".format(exception)
×
97
        logger.error(msg)
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc