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

EsupPortail / Esup-Pod / 8755927956

19 Apr 2024 03:21PM UTC coverage: 70.223%. First build
8755927956

Pull #1085

github

web-flow
[DONE] Update settings.py (#1115)

bump pod version to 3.6.0
Pull Request #1085: [DONE - FREEZE] Develop #3.6.0

744 of 994 new or added lines in 37 files covered. (74.85%)

10530 of 14995 relevant lines covered (70.22%)

0.7 hits per line

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

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

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

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

19
logger = logging.getLogger(__name__)
×
20

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

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

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

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

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

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

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

56

57
# celery \
58
# -A pod.video_encode_transcript.transcripting_tasks worker \
59
# -l INFO -Q transcripting
60
@transcripting_app.task
×
61
def start_transcripting_task(video_id, mp3filepath, duration, lang):
×
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}
×
79
    try:
×
80
        response = requests.post(url, json=data, headers=Headers)
×
81
        if response.status_code != 200:
×
NEW
82
            msg = "Calling store remote transcoding error: {} {}".format(
×
83
                response.status_code, response.reason
84
            )
85
            logger.error(msg + "\n" + str(response.content))
×
86
        else:
87
            logger.info("Call importing transcript task ok")
×
88
    except (
×
89
        requests.exceptions.HTTPError,
90
        requests.exceptions.ConnectionError,
91
        requests.exceptions.InvalidURL,
92
        requests.exceptions.Timeout,
93
    ) as exception:
94
        msg = "Exception: {}".format(type(exception).__name__)
×
95
        msg += "\nException message: {}".format(exception)
×
96
        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

© 2025 Coveralls, Inc