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

EsupPortail / Esup-Pod / 5241142798

pending completion
5241142798

Pull #880

github

web-flow
Merge 3d15d39c9 into 77b7abf46
Pull Request #880: [DONE] Add the remaining encodage code in the video to video_encode

211 of 211 new or added lines in 17 files covered. (100.0%)

8904 of 12380 relevant lines covered (71.92%)

0.72 hits per line

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

75.95
/pod/video_encode_transcript/utils.py
1
import os
1✔
2
import bleach
1✔
3

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

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

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

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

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

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

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

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

50

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

55

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

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

68

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

82

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

89

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

98

99
def send_email_encoding(video_to_encode):
1✔
100
    """Send email on encoding completion."""
101
    subject_prefix = _("Encoding")
1✔
102
    send_notification_email(video_to_encode, subject_prefix)
1✔
103

104

105
def send_email(msg, video_id):
1✔
106
    """Send email notification when video encoding failed."""
107
    send_email_item(msg, "Video", video_id)
1✔
108

109

110
def send_email_transcript(video_to_encode):
1✔
111
    """Send email on transcripting completion."""
112
    subject_prefix = _("Transcripting")
×
113
    send_notification_email(video_to_encode, subject_prefix)
×
114

115

116
def send_notification_email(video_to_encode, subject_prefix):
1✔
117
    """Send email notification on video encoding or transcripting completion."""
118
    if DEBUG:
1✔
119
        print("SEND EMAIL ON %s COMPLETION" % subject_prefix.upper())
1✔
120
    url_scheme = "https" if SECURE_SSL_REDIRECT else "http"
1✔
121
    content_url = "%s:%s" % (url_scheme, video_to_encode.get_full_url())
1✔
122
    subject = "[%s] %s" % (
1✔
123
        __TITLE_SITE__,
124
        _("%(subject)s #%(content_id)s completed")
125
        % {"subject": subject_prefix, "content_id": video_to_encode.id},
126
    )
127

128
    html_message = (
1✔
129
        '<p>%s</p><p>%s</p><p>%s<br><a href="%s"><i>%s</i></a>\
130
                </p><p>%s</p>'
131
        % (
132
            _("Hello,"),
133
            _(
134
                "The %(content_type)s ā€œ%(content_title)sā€ has been %(action)s"
135
                + ", and is now available on %(site_title)s."
136
            )
137
            % {
138
                "content_type": (
139
                    _("content") if subject_prefix == _("Transcripting") else _("video")
140
                ),
141
                "content_title": "<b>%s</b>" % video_to_encode.title,
142
                "action": (
143
                    _("automatically transcript")
144
                    if (subject_prefix == _("Transcripting"))
145
                    else _("encoded to Web formats")
146
                ),
147
                "site_title": __TITLE_SITE__,
148
            },
149
            _("You will find it here:"),
150
            content_url,
151
            content_url,
152
            _("Regards."),
153
        )
154
    )
155

156
    full_html_message = html_message + "<br>%s%s<br>%s%s" % (
1✔
157
        _("Post by:"),
158
        video_to_encode.owner,
159
        _("the:"),
160
        video_to_encode.date_added,
161
    )
162

163
    message = bleach.clean(html_message, tags=[], strip=True)
1✔
164
    full_message = bleach.clean(full_html_message, tags=[], strip=True)
1✔
165

166
    from_email = DEFAULT_FROM_EMAIL
1✔
167
    to_email = []
1✔
168
    to_email.append(video_to_encode.owner.email)
1✔
169

170
    if (
1✔
171
        USE_ESTABLISHMENT_FIELD
172
        and MANAGERS
173
        and video_to_encode.owner.owner.establishment.lower() in dict(MANAGERS)
174
    ):
175
        bcc_email = []
×
176
        video_estab = video_to_encode.owner.owner.establishment.lower()
×
177
        manager = dict(MANAGERS)[video_estab]
×
178
        if type(manager) in (list, tuple):
×
179
            bcc_email = manager
×
180
        elif type(manager) == str:
×
181
            bcc_email.append(manager)
×
182
        msg = EmailMultiAlternatives(
×
183
            subject, message, from_email, to_email, bcc=bcc_email
184
        )
185
        msg.attach_alternative(html_message, "text/html")
×
186
        msg.send()
×
187
    else:
188
        mail_managers(
1✔
189
            subject,
190
            full_message,
191
            fail_silently=False,
192
            html_message=full_html_message,
193
        )
194
        if not DEBUG:
1✔
195
            send_mail(
×
196
                subject,
197
                message,
198
                from_email,
199
                to_email,
200
                fail_silently=False,
201
                html_message=html_message,
202
            )
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