-
Notifications
You must be signed in to change notification settings - Fork 111
/
Copy pathutils.py
81 lines (59 loc) · 1.99 KB
/
utils.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import uuid
from hashlib import sha1
state_index={'all': 0, 'downloading': 1, 'paused': 2, 'finished': 3, 'invalid': 4}
state_name=['all', 'downloading', 'paused', 'finished', 'invalid']
def new_uuid():
return str(uuid.uuid4().hex)
def url2tid(url):
return sha1(url.encode()).hexdigest()
class YoutubeDLWebUI(Exception):
"""Base exception for YoutubeDL errors."""
pass
class TaskError(YoutubeDLWebUI):
"""Error related to download tasks."""
def __init__(self, msg, tid=None):
if tid: msg += ' tid={}'.format(tid)
super(TaskError, self).__init__(msg)
self.msg = msg
def __str__(self):
return repr(self.msg)
class TaskInexistenceError(TaskError):
def __init__(self, msg, tid=None, url=None, state=None):
msg = 'Task does not exist'
if tid:
msg += ' tid={}'.format(tid)
if url:
msg += ' url={}'.format(url)
if state:
msg += ' state={}'.format(state)
super(TaskInexistenceError, self).__init__(msg)
self.msg = msg
class TaskExistenceError(TaskError):
def __init__(self, msg, tid=None, url=None, state=None):
msg = 'Task already exists'
if tid:
msg += ' tid={}'.format(tid)
if url:
msg += ' url={}'.format(url)
if state:
msg += ' state={}'.format(state)
super(TaskExistenceError, self).__init__(msg)
self.msg = msg
class YDLManagerError(YoutubeDLWebUI):
"""Error related to youtube-dl manager."""
def __init__(self, msg, tid=None, url=None, state=None):
if tid:
msg += ' tid={}'.format(tid)
if url:
msg += ' url={}'.format(url)
if state:
msg += ' state={}'.format(state)
super(YDLManagerError, self).__init__(msg)
self.tid = tid
self.url = url
self.state = state
self.msg = msg
def __str__(self):
return repr(self.msg)