-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.py
More file actions
83 lines (58 loc) · 2.5 KB
/
misc.py
File metadata and controls
83 lines (58 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import random
from config import *
def make_image_path(movie_id, image):
return f'/static/movies/{movie_id}/img/{image}'
def build_master_src(movie_id, series_id):
return f'/static/movies/{movie_id}/{series_id}/master.m3u8'
def generate_string(length=25):
DIGITS = '0123456789'
LETTERS = 'qwertyuiopasdfghjklzxcvbnm'
SYMBOLS = LETTERS + LETTERS.upper() + DIGITS
return ''.join([random.choice(SYMBOLS) for i in range(length)])
def sort_title_list_key(key) -> list:
import re
def convert(text):
return int(text) if text.isdigit() else text
return [convert(c) for c in re.split('([0-9]+)', key)]
def sort_series_list(series_list: list[dict]) -> None:
import re
def convert(text):
return int(text) if text.isdigit() else text
def alphanum_key(key):
return [convert(c) for c in re.split('([0-9]+)', key['title'])]
series_list.sort(key=alphanum_key)
def get_lang_full_name(lang: str):
local_lang_map = {
'ru': ('Russian', 'Русский'),
'rus': ('Russian', 'Русский'),
'en': ('English', 'Английский'),
'eng': ('English', 'Английский'),
'fr': ('French', 'Француский'),
'ja': ('Japanese', 'Японский'),
'jpn': ('Japanese', 'Японский'),
'zh': ('Chinese', 'Китайский')
}
if lang in local_lang_map:
return local_lang_map[lang][0]
if len(lang) == 3:
return get_lang_full_name(lang[:-1])
return lang.upper()
def find_series_by_id(series: str, seasons: dict) -> tuple:
for season_title, season_it in seasons.items():
for i in season_it:
if i['id'] == series:
return season_title, i.copy()
return '', {}
def change_series_json(season: str, series_id: str, new_data: dict, series_json: dict) -> dict:
for i in range(len(series_json['seasons'][season])):
if series_json['seasons'][season][i]['id'] == series_id:
series_json['seasons'][season][i] = new_data
return series_json
def calculate_avg_rating(ratings: list[dict]) -> float:
if not ratings:
return 0.0
return round(sum([i['rating'] for i in ratings]) / len(ratings), 2)
def build_streams_list(height: int) -> list[tuple]:
if height not in RESOLUTIONS:
return [(i, int(height / k)) for i, k in enumerate([1, 1.5, 2.25, 2.25 * 1.333333]) if int(height / k) >= 300]
return [(i, s) for i, s in enumerate(RESOLUTIONS[RESOLUTIONS.index(height):]) if s >= 300]