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

EsupPortail / Esup-Pod / 13852636957

24 Jan 2025 03:58PM UTC coverage: 70.238% (-0.1%) from 70.375%
13852636957

push

github

Badatos
Merge branch 'main' into pod_V4

# Conflicts:
#	.env.dev-exemple
#	dockerfile-dev-with-volumes/README.adoc
#	pod/main/test_settings.py
#	pod/video/models.py
#	pod/video/utils.py
#	requirements.txt

93 of 150 new or added lines in 24 files covered. (62.0%)

12 existing lines in 7 files now uncovered.

11932 of 16988 relevant lines covered (70.24%)

0.7 hits per line

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

74.7
/pod/video_encode_transcript/encoding_utils.py
1
import subprocess
1✔
2
import shlex
1✔
3
import json
1✔
4
from collections import OrderedDict
1✔
5
from timeit import default_timer as timer
1✔
6
import os
1✔
7

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

13

14
def sec_to_timestamp(total_seconds):
1✔
15
    """Format time for webvtt caption."""
16
    hours = int(total_seconds / 3600)
×
17
    minutes = int(total_seconds / 60 - hours * 60)
×
18
    seconds = total_seconds - hours * 3600 - minutes * 60
×
19
    return "{:02d}:{:02d}:{:06.3f}".format(hours, minutes, seconds)
×
20

21

22
def get_dressing_position_value(position: str, height: str) -> str:
1✔
23
    """
24
    Obtain dimensions proportional to the video format.
25

26
    Args:
27
        position (str): property "position" of the dressing object.
28
        height (str): height of the source video.
29

30
    Returns:
31
        str: params for the ffmpeg command.
32
    """
33
    height = str(float(height) * 0.05)
1✔
34
    if position == "top_right":
1✔
35
        return "overlay=main_w-overlay_w-" + height + ":" + height
1✔
36
    elif position == "top_left":
1✔
37
        return "overlay=" + height + ":" + height
1✔
38
    elif position == "bottom_right":
1✔
39
        return "overlay=main_w-overlay_w-" + height + ":main_h-overlay_h-" + height
1✔
40
    elif position == "bottom_left":
1✔
41
        return "overlay=" + height + ":main_h-overlay_h-" + height
1✔
42

43

44
def get_renditions():
1✔
45
    try:
1✔
46
        from .models import VideoRendition
1✔
47
        from django.core import serializers
1✔
48

49
        renditions = json.loads(
1✔
50
            serializers.serialize("json", VideoRendition.objects.all())
51
        )
52
        video_rendition = []
1✔
53
        for rend in renditions:
1✔
54
            video_rendition.append(rend["fields"])
1✔
55
        return video_rendition
1✔
56
    except ImportError:
×
57
        return VIDEO_RENDITIONS
×
58

59

60
def check_file(path_file):
1✔
61
    if os.access(path_file, os.F_OK) and os.stat(path_file).st_size > 0:
1✔
62
        return True
1✔
63
    return False
1✔
64

65

66
def get_list_rendition():
1✔
67
    list_rendition = {}
1✔
68
    renditions = get_renditions()
1✔
69
    for rend in renditions:
1✔
70
        list_rendition[int(rend["resolution"].split("x")[1])] = rend
1✔
71
    list_rendition = OrderedDict(sorted(list_rendition.items(), key=lambda t: t[0]))
1✔
72
    return list_rendition
1✔
73

74

75
def get_info_from_video(probe_cmd):
1✔
76
    info = None
1✔
77
    msg = ""
1✔
78
    try:
1✔
79
        output = subprocess.check_output(shlex.split(probe_cmd), stderr=subprocess.PIPE)
1✔
80
        info = json.loads(output)
1✔
81
    except subprocess.CalledProcessError as e:
×
82
        # raise RuntimeError('ffprobe returned non-zero status: {}'.format(
83
        # e.stderr))
84
        msg += 20 * "////" + "\n"
×
85
        msg += "Runtime Error: {0}\n".format(e)
×
86
    except OSError as err:
×
87
        # raise OSError(e.errno, 'ffprobe not found: {}'.format(e.strerror))
88
        msg += 20 * "////" + "\n"
×
89
        msg += "OS error: {0}\n".format(err)
×
90
    return info, msg
1✔
91

92

93
def launch_cmd(cmd):
1✔
94
    if cmd == "":
1✔
95
        return False, "No cmd to launch"
×
96
    msg = ""
1✔
97
    encode_start = timer()
1✔
98
    return_value = False
1✔
99
    try:
1✔
100
        output = subprocess.run(
1✔
101
            shlex.split(cmd),
102
            stdout=subprocess.PIPE,
103
            stderr=subprocess.STDOUT,
104
        )
105
        encode_end = timer() - encode_start
1✔
106
        msg += cmd + "\n"
1✔
107
        msg += "Encode file in {:.3}s.\n".format(encode_end)
1✔
108
        # msg += "\n".join(output.stdout.decode().split('\n'))
109
        try:
1✔
110
            msg += output.stdout.decode("utf-8")
1✔
111
        except UnicodeDecodeError:
×
112
            pass
×
113
        msg += "\n"
1✔
114
        if output.returncode != 0:
1✔
UNCOV
115
            msg += "ERROR RETURN CODE %s for command %s" % (output.returncode, cmd)
×
116
        else:
117
            return_value = True
1✔
118
    except (subprocess.CalledProcessError, OSError) as e:
×
119
        # raise RuntimeError('ffmpeg returned non-zero status: {}'.format(
120
        # e.stderr))
121
        msg += 20 * "////" + "\n"
×
122
        msg += "Runtime or OsError Error: {0}\n".format(e)
×
123
    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