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

EsupPortail / Esup-Pod / 13964928276

20 Mar 2025 08:26AM UTC coverage: 70.106%. First build
13964928276

Pull #1280

github

web-flow
Merge a06fb2670 into 749de494a
Pull Request #1280: Replace credit_videofile by credit_video_dir

83 of 105 new or added lines in 12 files covered. (79.05%)

11984 of 17094 relevant lines covered (70.11%)

0.7 hits per line

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

73.96
/pod/video_encode_transcript/encoding_utils.py
1
from collections import OrderedDict
1✔
2
from timeit import default_timer as timer
1✔
3

4
import json
1✔
5
import os
1✔
6
import shlex
1✔
7
import subprocess
1✔
8
import logging
1✔
9

10
try:
1✔
11
    from .encoding_settings import VIDEO_RENDITIONS
1✔
12
except (ImportError, ValueError):
×
13
    from encoding_settings import VIDEO_RENDITIONS
×
14

15
try:
1✔
16
    from django.conf import settings
1✔
17

18
    VIDEO_RENDITIONS = getattr(settings, "VIDEO_RENDITIONS", VIDEO_RENDITIONS)
1✔
19
    DEBUG = getattr(settings, "DEBUG", True)
1✔
20
except ImportError:  # pragma: no cover
21
    DEBUG = True
22
    pass
23

24
logger = logging.getLogger(__name__)
1✔
25
if DEBUG:
1✔
26
    logger.setLevel(logging.DEBUG)
1✔
27

28

29
def sec_to_timestamp(total_seconds) -> str:
1✔
30
    """Format time for webvtt caption."""
31
    hours = int(total_seconds / 3600)
×
32
    minutes = int(total_seconds / 60 - hours * 60)
×
33
    seconds = total_seconds - hours * 3600 - minutes * 60
×
34
    return "{:02d}:{:02d}:{:06.3f}".format(hours, minutes, seconds)
×
35

36

37
def get_dressing_position_value(position: str, height: str) -> str:
1✔
38
    """
39
    Obtain dimensions proportional to the video format.
40

41
    Args:
42
        position (str): property "position" of the dressing object.
43
        height (str): height of the source video.
44

45
    Returns:
46
        str: params for the ffmpeg command.
47
    """
48
    height = str(float(height) * 0.05)
1✔
49
    if position == "top_right":
1✔
50
        return "overlay=main_w-overlay_w-" + height + ":" + height
1✔
51
    elif position == "top_left":
1✔
52
        return "overlay=" + height + ":" + height
1✔
53
    elif position == "bottom_right":
1✔
54
        return "overlay=main_w-overlay_w-" + height + ":main_h-overlay_h-" + height
1✔
55
    elif position == "bottom_left":
1✔
56
        return "overlay=" + height + ":main_h-overlay_h-" + height
1✔
57

58

59
def get_renditions():
1✔
60
    try:
1✔
61
        from .models import VideoRendition
1✔
62
        from django.core import serializers
1✔
63

64
        renditions = json.loads(
1✔
65
            serializers.serialize("json", VideoRendition.objects.all())
66
        )
67
        video_rendition = []
1✔
68
        for rend in renditions:
1✔
69
            video_rendition.append(rend["fields"])
1✔
70
        return video_rendition
1✔
71
    except ImportError:
×
72
        return VIDEO_RENDITIONS
×
73

74

75
def check_file(path_file) -> bool:
1✔
76
    if os.access(path_file, os.F_OK) and os.stat(path_file).st_size > 0:
1✔
77
        return True
1✔
78
    return False
1✔
79

80

81
def get_list_rendition():
1✔
82
    list_rendition = {}
1✔
83
    renditions = get_renditions()
1✔
84
    for rend in renditions:
1✔
85
        list_rendition[int(rend["resolution"].split("x")[1])] = rend
1✔
86
    list_rendition = OrderedDict(sorted(list_rendition.items(), key=lambda t: t[0]))
1✔
87
    return list_rendition
1✔
88

89

90
def get_info_from_video(probe_cmd):
1✔
91
    info = None
1✔
92
    msg = ""
1✔
93
    try:
1✔
94
        output = subprocess.check_output(shlex.split(probe_cmd), stderr=subprocess.PIPE)
1✔
95
        info = json.loads(output)
1✔
96
    except subprocess.CalledProcessError as e:
×
97
        # raise RuntimeError('ffprobe returned non-zero status: {}'.format(
98
        # e.stderr))
99
        msg += 20 * "////" + "\n"
×
100
        msg += "Runtime Error: {0}\n".format(e)
×
101
    except OSError as err:
×
102
        # raise OSError(e.errno, 'ffprobe not found: {}'.format(e.strerror))
103
        msg += 20 * "////" + "\n"
×
104
        msg += "OS error: {0}\n".format(err)
×
105
    return info, msg
1✔
106

107

108
def launch_cmd(cmd):
1✔
109
    if cmd == "":
1✔
NEW
110
        msg = "No cmd to launch"
×
NEW
111
        logger.warning(msg)
×
NEW
112
        return False, msg
×
113
    msg = ""
1✔
114
    encode_start = timer()
1✔
115
    return_value = False
1✔
116
    try:
1✔
117
        logger.debug("launch_cmd: %s" % cmd)
1✔
118
        output = subprocess.run(
1✔
119
            shlex.split(cmd),
120
            stdout=subprocess.PIPE,
121
            stderr=subprocess.STDOUT,
122
        )
123
        encode_end = timer() - encode_start
1✔
124
        msg += cmd + "\n"
1✔
125
        msg += "Encode file in {:.3}s.\n".format(encode_end)
1✔
126
        # msg += "\n".join(output.stdout.decode().split('\n'))
127
        try:
1✔
128
            msg += output.stdout.decode("utf-8")
1✔
129
        except UnicodeDecodeError:
×
130
            pass
×
131
        msg += "\n"
1✔
132
        if output.returncode != 0:
1✔
133
            msg += "ERROR RETURN CODE %s for command %s" % (output.returncode, cmd)
×
134
        else:
135
            return_value = True
1✔
136
    except (subprocess.CalledProcessError, OSError) as e:
×
137
        # raise RuntimeError('ffmpeg returned non-zero status: {}'.format(
138
        # e.stderr))
139
        msg += 20 * "////" + "\n"
×
NEW
140
        err_msg = "Runtime or OS Error: {0}\n".format(e)
×
NEW
141
        msg += err_msg
×
NEW
142
        logger.error(err_msg)
×
143
    return return_value, msg
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