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

EsupPortail / Esup-Pod / 5322792349

pending completion
5322792349

push

github

web-flow
Merge pull request #863 from EsupPortail/develop

#3.3.0

- Import external video from url, youtube, peertube and BigBlueButton
- Change xapi actor to deal with Moodle
- Update template to BS5.3 and improve compliance for W3C
- Use redis to cache session and improve logging
- refactor of encoding/transcripting to move it in separate application
- Fixbug on categories, recorder, user liste, tags cloud

1484 of 1484 new or added lines in 51 files covered. (100.0%)

9011 of 12517 relevant lines covered (71.99%)

0.76 hits per line

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

78.02
/pod/video_encode_transcript/utils.py
1
import os
1✔
2
import bleach
1✔
3
import time
1✔
4

5
from django.conf import settings
1✔
6
from django.utils.translation import ugettext_lazy as _
1✔
7
from django.core.mail import mail_admins
1✔
8
from django.core.mail import send_mail
1✔
9
from django.core.mail import mail_managers
1✔
10
from django.core.mail import EmailMultiAlternatives
1✔
11
from pod.video.models import Video
1✔
12
from .models import EncodingStep
1✔
13
from .models import EncodingLog
1✔
14

15
DEBUG = getattr(settings, "DEBUG", True)
1✔
16

17
TEMPLATE_VISIBLE_SETTINGS = getattr(
1✔
18
    settings,
19
    "TEMPLATE_VISIBLE_SETTINGS",
20
    {
21
        "TITLE_SITE": "Pod",
22
        "TITLE_ETB": "University name",
23
        "LOGO_SITE": "img/logoPod.svg",
24
        "LOGO_ETB": "img/esup-pod.svg",
25
        "LOGO_PLAYER": "img/pod_favicon.svg",
26
        "LINK_PLAYER": "",
27
        "FOOTER_TEXT": ("",),
28
        "FAVICON": "img/pod_favicon.svg",
29
        "CSS_OVERRIDE": "",
30
        "PRE_HEADER_TEMPLATE": "",
31
        "POST_FOOTER_TEMPLATE": "",
32
        "TRACKING_TEMPLATE": "",
33
    },
34
)
35

36
__TITLE_SITE__ = (
1✔
37
    TEMPLATE_VISIBLE_SETTINGS["TITLE_SITE"]
38
    if (TEMPLATE_VISIBLE_SETTINGS.get("TITLE_SITE"))
39
    else "Pod"
40
)
41

42
DEFAULT_FROM_EMAIL = getattr(settings, "DEFAULT_FROM_EMAIL", "noreply@univ.fr")
1✔
43

44
USE_ESTABLISHMENT_FIELD = getattr(settings, "USE_ESTABLISHMENT_FIELD", False)
1✔
45

46
MANAGERS = getattr(settings, "MANAGERS", {})
1✔
47

48
SECURE_SSL_REDIRECT = getattr(settings, "SECURE_SSL_REDIRECT", False)
1✔
49
VIDEOS_DIR = getattr(settings, "VIDEOS_DIR", "videos")
1✔
50

51

52
# ##########################################################################
53
# ENCODE VIDEO : GENERIC FUNCTIONS
54
# ##########################################################################
55

56

57
def change_encoding_step(video_id, num_step, desc):
1✔
58
    """Change encoding step."""
59
    encoding_step, created = EncodingStep.objects.get_or_create(
1✔
60
        video=Video.objects.get(id=video_id)
61
    )
62
    encoding_step.num_step = num_step
1✔
63
    encoding_step.desc_step = desc[:255]
1✔
64
    encoding_step.save()
1✔
65

66
    if DEBUG:
1✔
67
        print("step: %d - desc: %s" % (num_step, desc))
1✔
68

69

70
def add_encoding_log(video_id, log):
1✔
71
    """Add message in video_id encoding log."""
72
    encoding_log, created = EncodingLog.objects.get_or_create(
1✔
73
        video=Video.objects.get(id=video_id)
74
    )
75
    if created:
1✔
76
        encoding_log.log = log
1✔
77
    else:
78
        encoding_log.log += "\n\n%s" % log
×
79
    encoding_log.save()
1✔
80
    if DEBUG:
1✔
81
        print(log)
1✔
82

83

84
def check_file(path_file):
1✔
85
    """Check if path_file is accessible and is not null."""
86
    if os.access(path_file, os.F_OK) and os.stat(path_file).st_size > 0:
1✔
87
        return True
1✔
88
    return False
1✔
89

90

91
def create_outputdir(video_id, video_path):
1✔
92
    """ENCODE VIDEO: CREATE OUTPUT DIR."""
93
    dirname = os.path.dirname(video_path)
×
94
    output_dir = os.path.join(dirname, "%04d" % video_id)
×
95
    if not os.path.exists(output_dir):
×
96
        os.makedirs(output_dir)
×
97
    return output_dir
×
98

99

100
###############################################################
101
# EMAIL
102
###############################################################
103

104

105
def send_email_item(msg, item, item_id):
1✔
106
    """Send email notification when encoding fails for a specific item."""
107
    subject = "[" + __TITLE_SITE__ + "] Error Encoding %s id:%s" % (item, item_id)
1✔
108
    message = "Error Encoding  %s id : %s\n%s" % (item, item_id, msg)
1✔
109
    html_message = "<p>Error Encoding %s id : %s</p><p>%s</p>" % (
1✔
110
        item,
111
        item_id,
112
        msg.replace("\n", "<br>"),
113
    )
114
    mail_admins(subject, message, fail_silently=False, html_message=html_message)
1✔
115

116

117
def send_email_recording(msg, recording_id):
1✔
118
    """Send email notification when recording encoding failed."""
119
    send_email_item(msg, "Recording", recording_id)
×
120

121

122
def send_email_encoding(video_to_encode):
1✔
123
    """Send email on encoding completion."""
124
    subject_prefix = _("Encoding")
1✔
125
    send_notification_email(video_to_encode, subject_prefix)
1✔
126

127

128
def send_email(msg, video_id):
1✔
129
    """Send email notification when video encoding failed."""
130
    send_email_item(msg, "Video", video_id)
1✔
131

132

133
def send_email_transcript(video_to_encode):
1✔
134
    """Send email on transcripting completion."""
135
    subject_prefix = _("Transcripting")
×
136
    send_notification_email(video_to_encode, subject_prefix)
×
137

138

139
def send_notification_email(video_to_encode, subject_prefix):
1✔
140
    """Send email notification on video encoding or transcripting completion."""
141
    if DEBUG:
1✔
142
        print("SEND EMAIL ON %s COMPLETION" % subject_prefix.upper())
1✔
143
    url_scheme = "https" if SECURE_SSL_REDIRECT else "http"
1✔
144
    content_url = "%s:%s" % (url_scheme, video_to_encode.get_full_url())
1✔
145
    subject = "[%s] %s" % (
1✔
146
        __TITLE_SITE__,
147
        _("%(subject)s #%(content_id)s completed")
148
        % {"subject": subject_prefix, "content_id": video_to_encode.id},
149
    )
150

151
    html_message = (
1✔
152
        '<p>%s</p><p>%s</p><p>%s<br><a href="%s"><i>%s</i></a>\
153
                </p><p>%s</p>'
154
        % (
155
            _("Hello,"),
156
            _(
157
                "The %(content_type)s ā€œ%(content_title)sā€ has been %(action)s"
158
                + ", and is now available on %(site_title)s."
159
            )
160
            % {
161
                "content_type": (
162
                    _("content") if subject_prefix == _("Transcripting") else _("video")
163
                ),
164
                "content_title": "<b>%s</b>" % video_to_encode.title,
165
                "action": (
166
                    _("automatically transcript")
167
                    if (subject_prefix == _("Transcripting"))
168
                    else _("encoded to Web formats")
169
                ),
170
                "site_title": __TITLE_SITE__,
171
            },
172
            _("You will find it here:"),
173
            content_url,
174
            content_url,
175
            _("Regards."),
176
        )
177
    )
178

179
    full_html_message = html_message + "<br>%s%s<br>%s%s" % (
1✔
180
        _("Post by:"),
181
        video_to_encode.owner,
182
        _("the:"),
183
        video_to_encode.date_added,
184
    )
185

186
    message = bleach.clean(html_message, tags=[], strip=True)
1✔
187
    full_message = bleach.clean(full_html_message, tags=[], strip=True)
1✔
188

189
    from_email = DEFAULT_FROM_EMAIL
1✔
190
    to_email = []
1✔
191
    to_email.append(video_to_encode.owner.email)
1✔
192

193
    if (
1✔
194
        USE_ESTABLISHMENT_FIELD
195
        and MANAGERS
196
        and video_to_encode.owner.owner.establishment.lower() in dict(MANAGERS)
197
    ):
198
        bcc_email = []
×
199
        video_estab = video_to_encode.owner.owner.establishment.lower()
×
200
        manager = dict(MANAGERS)[video_estab]
×
201
        if type(manager) in (list, tuple):
×
202
            bcc_email = manager
×
203
        elif type(manager) == str:
×
204
            bcc_email.append(manager)
×
205
        msg = EmailMultiAlternatives(
×
206
            subject, message, from_email, to_email, bcc=bcc_email
207
        )
208
        msg.attach_alternative(html_message, "text/html")
×
209
        msg.send()
×
210
    else:
211
        mail_managers(
1✔
212
            subject,
213
            full_message,
214
            fail_silently=False,
215
            html_message=full_html_message,
216
        )
217
        if not DEBUG:
1✔
218
            send_mail(
×
219
                subject,
220
                message,
221
                from_email,
222
                to_email,
223
                fail_silently=False,
224
                html_message=html_message,
225
            )
226

227

228
def time_to_seconds(a_time):
1✔
229
    """Convert a time to seconds."""
230
    seconds = time.strptime(str(a_time), "%H:%M:%S")
1✔
231
    seconds = seconds.tm_sec + seconds.tm_min * 60 + seconds.tm_hour * 3600
1✔
232
    return seconds
1✔
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