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

EsupPortail / Esup-Pod / 8023477126

23 Feb 2024 06:28PM UTC coverage: 70.223% (-0.3%) from 70.49%
8023477126

Pull #1056

github

web-flow
Merge 0690d3578 into f8e2c5049
Pull Request #1056: [WIP] Fix remote encoding and other stuff

46 of 158 new or added lines in 9 files covered. (29.11%)

19 existing lines in 8 files now uncovered.

9872 of 14058 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
×
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)
×
24

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

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

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

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

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

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

57

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

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