Skip to content

Commit 93d31c6

Browse files
committed
cleanup
1 parent 316a6e0 commit 93d31c6

File tree

23 files changed

+64
-134
lines changed

23 files changed

+64
-134
lines changed

plugin/e2_utils.py

-48
Original file line numberDiff line numberDiff line change
@@ -411,54 +411,6 @@ def setSetting(self, key, val):
411411
print(repr(self), e, 'cannot set setting:', key, ':', val)
412412

413413

414-
def unrar(rarPath, destDir, successCB, errorCB):
415-
def rarSubNameCB(result, retval, extra_args):
416-
if retval == 0:
417-
print('[Unrar] getting rar sub name', result)
418-
rarSubNames = result.split('\n')
419-
rarPath = extra_args[0]
420-
destDir = extra_args[1]
421-
try:
422-
for subName in rarSubNames:
423-
os.unlink(os.path.join(destDir, subName))
424-
except OSError as e:
425-
print(e)
426-
# unrar needs rar Extension?
427-
if os.path.splitext(rarPath)[1] != '.rar':
428-
oldRarPath = rarPath
429-
rarPath = os.path.splitext(rarPath)[0] + '.rar'
430-
shutil.move(oldRarPath, rarPath)
431-
cmdRarUnpack = 'unrar e "%s" %s' % (rarPath, destDir)
432-
Console().ePopen(toString(cmdRarUnpack), rarUnpackCB, (tuple(rarSubNames),))
433-
else:
434-
try:
435-
os.unlink(extra_args[0])
436-
except OSError:
437-
pass
438-
print('[Unrar] problem when getting rar sub name:', result)
439-
errorCB(_("unpack error: cannot get subname"))
440-
441-
def rarUnpackCB(result, retval, extra_args):
442-
if retval == 0:
443-
print('[Unrar] successfully unpacked rar archive')
444-
result = []
445-
rarSubNames = extra_args[0]
446-
for subName in rarSubNames:
447-
result.append(os.path.join(destDir, subName))
448-
successCB(result)
449-
else:
450-
print('[Unrar] problem when unpacking rar archive', result)
451-
try:
452-
os.unlink(extra_args[0])
453-
except OSError:
454-
pass
455-
errorCB(_("unpack error: cannot open archive"))
456-
457-
cmdRarSubName = 'unrar lb "%s"' % rarPath
458-
extraArgs = (rarPath, destDir)
459-
Console().ePopen(toString(cmdRarSubName), rarSubNameCB, extraArgs)
460-
461-
462414
class fps_float(float):
463415
def __eq__(self, other):
464416
return "%.3f" % self == "%.3f" % other

plugin/parsers/subrip.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from __future__ import absolute_import
2-
import re
2+
from re import finditer, search, sub, DOTALL, MULTILINE
33

44
from .baseparser import BaseParser, ParseError, HEX_COLORS
55

@@ -12,7 +12,7 @@ def _parse(self, text, fps):
1212
return self._srt_to_dict(text)
1313

1414
def _removeTags(self, text):
15-
return re.sub('<[^>]*>', '', text)
15+
return sub('<[^>]*>', '', text)
1616

1717
def _getColor(self, text, color):
1818
newColor = color
@@ -21,7 +21,7 @@ def _getColor(self, text, color):
2121
if text.find('</font>') != -1 or text.find('</Font>') != -1:
2222
newColor = 'default'
2323
else:
24-
colorMatch = re.search('<[Ff]ont [Cc]olor=(.+?)>', text, re.DOTALL)
24+
colorMatch = search('<[Ff]ont [Cc]olor=(.+?)>', text, DOTALL)
2525
colorText = colorMatch and colorMatch.group(1)
2626
colorText = colorText and colorText.replace("'", "").replace('"', '')
2727
if text.find('</font>') != -1 or text.find('</Font>') != -1:
@@ -30,12 +30,12 @@ def _getColor(self, text, color):
3030
newColor = color
3131
else:
3232
color = 'default'
33-
colorMatch = re.search('<[Ff]ont [Cc]olor=(.+?)>', text, re.DOTALL)
33+
colorMatch = search('<[Ff]ont [Cc]olor=(.+?)>', text, DOTALL)
3434
colorText = colorMatch and colorMatch.group(1) or color
3535
colorText = colorText.replace("'", "").replace('"', '')
3636

3737
if colorText:
38-
hexColor = re.search("(\#[0-9,a-f,A-F]{6})", colorText)
38+
hexColor = search("(\#[0-9,a-f,A-F]{6})", colorText)
3939
if hexColor:
4040
color = hexColor.group(1)[1:]
4141
else:
@@ -90,7 +90,7 @@ def _srt_to_dict(self, srtText):
9090
subs = []
9191
idx = 0
9292
srtText = srtText.replace('\r\n', '\n').strip() + "\n\n"
93-
for s in re.finditer(r'(^\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*-->\s*(\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*\n(.+?)(?:\n\n|\n\d+\s*\n)', srtText, re.DOTALL | re.MULTILINE):
93+
for s in finditer(r'(^\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*-->\s*(\d+)\s*\:\s*(\d+)\s*\:\s*(\d+)\s*\,\s*(\d+)\s*\n(.+?)(?:\n\n|\n\d+\s*\n)', srtText, DOTALL | MULTILINE):
9494
try:
9595
idx += 1
9696
shour, smin, ssec, smsec = int(s.group(1)), int(s.group(2)), int(s.group(3)), int(s.group(4))

plugin/seekers/Edna/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: UTF-8 -*-
22
from __future__ import absolute_import
3-
import os
3+
from os.path import join
44

55
from urllib.parse import urlencode
66
from urllib.request import urlopen
@@ -81,7 +81,7 @@ def download_subtitles(subtitles_list, pos, extract_subs, tmp_sub_dir, sub_folde
8181
log(__name__, "Subs in %s" % subtitles_format)
8282
if subtitles_format in ['srt', 'sub']:
8383
compressed = False
84-
store_path = os.path.join(sub_folder, subtitles_filename)
84+
store_path = join(sub_folder, subtitles_filename)
8585
subtitles_file = store_path
8686
else:
8787
compressed = True

plugin/seekers/Elsubtitle/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
from requests.packages.urllib3.exceptions import InsecureRequestWarning
1010
warnings.simplefilter('ignore', InsecureRequestWarning)
1111
import os
12-
import os.path
12+
from os.path import exists
1313
from urllib.request import Request, urlopen
1414
from urllib.parse import quote_plus, urlencode
1515
from html.parser import HTMLParser
1616

1717
from .ElsubtitleUtilities import get_language_info
18-
from ..utilities import languageTranslate, log, getFileSize
19-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
18+
from ..utilities import log
2019

2120
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:85.0) Gecko/20100101 Firefox/85.0',
2221
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
@@ -264,7 +263,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
264263
local_tmp_file = zip_subs
265264
try:
266265
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
267-
if not os.path.exists(tmp_sub_dir):
266+
if not exists(tmp_sub_dir):
268267
os.makedirs(tmp_sub_dir)
269268
local_file_handle = open(local_tmp_file, 'wb')
270269
local_file_handle.write(response.content)

plugin/seekers/Indexsubtitle/service.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
from requests.packages.urllib3.exceptions import InsecureRequestWarning
1010
warnings.simplefilter('ignore', InsecureRequestWarning)
1111
import os
12-
import os.path
12+
from os.path import exists
1313
from urllib.request import Request, urlopen
14-
#from urllib.request import FancyURLopener
1514
from urllib.parse import quote_plus, urlencode
1615

1716
from html.parser import HTMLParser
1817
from .IndexsubtitleUtilities import get_language_info
19-
from ..utilities import languageTranslate, log, getFileSize
20-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
18+
from ..utilities import log
2119

2220
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/117.0',
2321
'Accept': 'application/json, text/javascript, */*; q=0.01',
@@ -169,7 +167,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
169167
local_tmp_file = zip_subs
170168
try:
171169
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
172-
if not os.path.exists(tmp_sub_dir):
170+
if not exists(tmp_sub_dir):
173171
os.makedirs(tmp_sub_dir)
174172
local_file_handle = open(local_tmp_file, 'wb')
175173
local_file_handle.write(response.content)

plugin/seekers/Moviesubtitles/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
from requests.packages.urllib3.exceptions import InsecureRequestWarning
99
warnings.simplefilter('ignore', InsecureRequestWarning)
1010
import os
11-
import os.path
11+
from os.path import exists
1212
from urllib.request import Request, urlopen
1313
from .MoviesubtitlesUtilities import get_language_info
14-
from ..utilities import languageTranslate, log, getFileSize
14+
from ..utilities import log
1515

1616
import re
17-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
1817

1918

2019
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0',
@@ -170,7 +169,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
170169
local_tmp_file = zip_subs
171170
try:
172171
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
173-
if not os.path.exists(tmp_sub_dir):
172+
if not exists(tmp_sub_dir):
174173
os.makedirs(tmp_sub_dir)
175174
local_file_handle = open(local_tmp_file, 'wb')
176175
local_file_handle.write(response.content)

plugin/seekers/Moviesubtitles2/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
from requests.packages.urllib3.exceptions import InsecureRequestWarning
99
warnings.simplefilter('ignore', InsecureRequestWarning)
1010
import os
11-
import os.path
11+
from os.path import exists
1212
from urllib.request import Request, urlopen
1313
from .Moviesubtitles2Utilities import get_language_info
14-
from ..utilities import languageTranslate, log, getFileSize
14+
from ..utilities import log
1515

1616
import re
17-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
1817

1918

2019
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; rv:109.0) Gecko/20100101 Firefox/115.0',
@@ -148,7 +147,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
148147
local_tmp_file = zip_subs
149148
try:
150149
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
151-
if not os.path.exists(tmp_sub_dir):
150+
if not exists(tmp_sub_dir):
152151
os.makedirs(tmp_sub_dir)
153152
local_file_handle = open(local_tmp_file, 'wb')
154153
local_file_handle.write(response.content)

plugin/seekers/MySubs/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
from requests.packages.urllib3.exceptions import InsecureRequestWarning
1010
warnings.simplefilter('ignore', InsecureRequestWarning)
1111
import os
12-
import os.path
12+
from os.path import exists
1313
from urllib.request import Request, urlopen
1414
from .MySubsUtilities import get_language_info
15-
from ..utilities import languageTranslate, log, getFileSize
15+
from ..utilities import log
1616

1717
import re
1818
from html.parser import HTMLParser
19-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
2019
HDR = {'Host': 'my-subs.co',
2120
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/116.0',
2221
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8',
@@ -218,7 +217,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
218217
local_tmp_file = zip_subs
219218
try:
220219
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
221-
if not os.path.exists(tmp_sub_dir):
220+
if not exists(tmp_sub_dir):
222221
os.makedirs(tmp_sub_dir)
223222
local_file_handle = open(local_tmp_file, 'wb')
224223
local_file_handle.write(response.content)

plugin/seekers/Novalermora/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
from requests.packages.urllib3.exceptions import InsecureRequestWarning
1010
warnings.simplefilter('ignore', InsecureRequestWarning)
1111
import os
12-
import os.path
13-
from ..utilities import languageTranslate, log, getFileSize
14-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
12+
from os.path import exists
13+
from ..utilities import log
1514

1615
from urllib.request import urlopen, Request
1716

@@ -114,7 +113,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
114113
local_tmp_file = zip_subs
115114
try:
116115
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
117-
if not os.path.exists(tmp_sub_dir):
116+
if not exists(tmp_sub_dir):
118117
os.makedirs(tmp_sub_dir)
119118
local_file_handle = open(local_tmp_file, 'wb')
120119
local_file_handle.write(response.content)

plugin/seekers/OpenSubtitles2/service.py

+4-9
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
from __future__ import absolute_import
33

44
import os
5-
import re
65
import requests
76
from .OpenSubtitles2Utilities import get_language_info
8-
import os.path
9-
import http.client
10-
import json
11-
import sys
7+
from os.path import exists
128
from bs4 import BeautifulSoup
13-
from urllib.request import HTTPCookieProcessor, build_opener, install_opener, Request, urlopen
9+
from urllib.request import Request, urlopen
1410
from urllib.parse import urlencode
15-
from ..utilities import languageTranslate, getFileSize, log
16-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
11+
from ..utilities import log
1712

1813

1914
HDR = {
@@ -181,7 +176,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
181176
local_tmp_file = zip_subs
182177
try:
183178
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
184-
if not os.path.exists(tmp_sub_dir):
179+
if not exists(tmp_sub_dir):
185180
os.makedirs(tmp_sub_dir)
186181
local_file_handle = open(local_tmp_file, 'wb')
187182
local_file_handle.write(response.content)

plugin/seekers/OpenSubtitlesMora/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import re
88
import string
99
from bs4 import BeautifulSoup
10-
from .OpensubtitlesmoraUtilities import geturl, get_language_info
11-
from urllib.parse import quote_plus, urlencode
10+
from .OpensubtitlesmoraUtilities import get_language_info
11+
from urllib.parse import quote_plus
1212
from ..utilities import log
1313
from html import unescape
1414
import requests

plugin/seekers/Subdl/service.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
import os
7-
import os.path
7+
from os.path import exists
88
import re
99
import requests
1010
import warnings
@@ -13,8 +13,6 @@
1313
from .SubdlUtilities import get_language_info
1414
from ..utilities import log
1515

16-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
17-
1816
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0',
1917
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
2018
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
@@ -112,7 +110,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
112110
local_tmp_file = zip_subs
113111
try:
114112
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
115-
if not os.path.exists(tmp_sub_dir):
113+
if not exists(tmp_sub_dir):
116114
os.makedirs(tmp_sub_dir)
117115
local_file_handle = open(local_tmp_file, 'wb')
118116
local_file_handle.write(response.content)

plugin/seekers/Subscene/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from __future__ import print_function
55
import difflib
66
import os
7-
from .SubsceneUtilities import geturl, get_language_info
8-
from urllib.request import FancyURLopener, urlopen
7+
from .SubsceneUtilities import get_language_info
8+
from urllib.request import urlopen
99
from urllib.parse import quote_plus, urlencode
1010

1111
from ..utilities import log

plugin/seekers/Subscenebest/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import zipfile
88
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
99
from bs4 import BeautifulSoup
10-
from .SubscenebestUtilities import geturl, get_language_info
11-
from urllib.parse import quote_plus, urlencode
10+
from .SubscenebestUtilities import get_language_info
11+
from urllib.parse import quote_plus
1212
from ..utilities import log
1313
import html
1414
import re

plugin/seekers/Subsource/service.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import os
77
import re
88
import string
9-
from .SubsourceUtilities import geturl, get_language_info
10-
from urllib.parse import quote_plus, urlencode
9+
from .SubsourceUtilities import get_language_info
10+
from urllib.parse import quote_plus
1111
from ..utilities import log
1212
import html
1313
import requests

plugin/seekers/Subsyts/service.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
from requests.packages.urllib3.exceptions import InsecureRequestWarning
1010
warnings.simplefilter('ignore', InsecureRequestWarning)
1111
import os
12-
import os.path
12+
from os.path import exists
1313
from urllib.request import Request, urlopen
1414
from .SubsytsUtilities import get_language_info
15-
from ..utilities import languageTranslate, log, getFileSize
15+
from ..utilities import log
1616

1717
import re
1818
from html.parser import HTMLParser
19-
from ..seeker import SubtitlesDownloadError, SubtitlesErrors
2019
HDR = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0',
2120
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
2221
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
@@ -186,7 +185,7 @@ def download_subtitles(subtitles_list, pos, zip_subs, tmp_sub_dir, sub_folder, s
186185
local_tmp_file = zip_subs
187186
try:
188187
log(__name__, "%s Saving subtitles to '%s'" % (debug_pretext, local_tmp_file))
189-
if not os.path.exists(tmp_sub_dir):
188+
if not exists(tmp_sub_dir):
190189
os.makedirs(tmp_sub_dir)
191190

192191
local_file_handle = open(local_tmp_file, 'wb')

0 commit comments

Comments
 (0)