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

EsupPortail / Esup-Pod / 8113794445

01 Mar 2024 03:58PM UTC coverage: 69.889%. First build
8113794445

Pull #1056

github

web-flow
Merge e3b9513f3 into ab939b862
Pull Request #1056: [DONE] Fix remote encoding and other stuff

46 of 164 new or added lines in 9 files covered. (28.05%)

9911 of 14181 relevant lines covered (69.89%)

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
×
NEW
10
import requests
×
11
# call local settings directly
12
# no need to load pod application to send statement
13
try:
×
14
    from ..custom import settings_local
×
15
except ImportError:
×
16
    from .. import settings as settings_local
×
17

18
logger = logging.getLogger(__name__)
×
19

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

NEW
26
admins_email = [ad[1] for ad in ADMINS]
×
27

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

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

NEW
40
POD_API_URL = getattr(
×
41
    settings_local, "POD_API_URL", ""
42
)
NEW
43
POD_API_TOKEN = getattr(
×
44
    settings_local, "POD_API_TOKEN", ""
45
)
46

47
ENCODING_TRANSCODING_CELERY_BROKER_URL = getattr(
×
48
    settings_local, "ENCODING_TRANSCODING_CELERY_BROKER_URL", ""
49
)
50

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

59

60
# celery \
61
# -A pod.video_encode_transcript.transcripting_tasks worker \
62
# -l INFO -Q transcripting
63
@transcripting_app.task
×
64
def start_transcripting_task(video_id, mp3filepath, duration, lang):
×
65
    """Start the transcripting of the video."""
66
    from .transcript_model import start_transcripting
×
67
    from ..main.settings import MEDIA_ROOT
×
68

69
    print("Start the transcripting of the video %s" % video_id)
×
70
    print(video_id, mp3filepath, duration, lang)
×
71
    msg, text_webvtt = start_transcripting(mp3filepath, duration, lang)
×
72
    print("End of the transcripting of the video")
×
73
    media_temp_dir = os.path.join(MEDIA_ROOT, "temp")
×
74
    if not os.path.exists(media_temp_dir):
×
75
        os.mkdir(media_temp_dir)
×
76
    temp_vtt_file = NamedTemporaryFile(dir=media_temp_dir, delete=False, suffix=".vtt")
×
77
    text_webvtt.save(temp_vtt_file.name)
×
NEW
78
    print("End of the transcoding of the video")
×
NEW
79
    Headers = {"Authorization" : "Token %s" % POD_API_TOKEN}
×
NEW
80
    url = POD_API_URL.strip("/") + "/store_remote_transcripted_video/?id=%s" % video_id
×
NEW
81
    data = {
×
82
        "video_id": video_id,
83
        "msg": msg,
84
        "temp_vtt_file": temp_vtt_file.name
85
    }
NEW
86
    try:
×
NEW
87
        response = requests.post(url, json=data, headers=Headers)
×
NEW
88
        if response.status_code != 200:
×
NEW
89
            msg = "Calling store remote transcoding error : {} {}".format(
×
90
                response.status_code,
91
                response.reason
92
            )
NEW
93
            logger.error(msg + "\n" + str(response.content))
×
94
        else:
NEW
95
            logger.info("Call importing transcript task ok")
×
NEW
96
    except (
×
97
        requests.exceptions.HTTPError,
98
        requests.exceptions.ConnectionError,
99
        requests.exceptions.InvalidURL,
100
        requests.exceptions.Timeout
101
    ) as exception:
NEW
102
        msg = "Exception: {}".format(type(exception).__name__)
×
NEW
103
        msg += "\nException message: {}".format(exception)
×
NEW
104
        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