Skip to content

Commit 227ebe2

Browse files
committed
torbox cloud fixes
1 parent 4e33a58 commit 227ebe2

File tree

29 files changed

+304
-165
lines changed

29 files changed

+304
-165
lines changed

matrix/plugin.video.umbrella/addon.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.31">
1+
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.32">
22
<requires>
33
<import addon="xbmc.python" version="3.0.0"/>
44
<import addon="script.module.requests"/>
@@ -179,13 +179,9 @@
179179
<screenshot>resources/screenshots/screenshot003.jpg</screenshot>
180180
</assets>
181181
<news>
182-
[B]Update - v6.7.31 - December 26th, 2024[/B]
183-
--[Change] Made changes to the cache torrent function for TorBox.
184-
--[Change] Made context menu use highlight color for Umbrella Settings
185-
--[Fix] Changes in module loads for internal and cloud scrapers.
186-
--[Fix] Change in way Trakt regular expression for list was handled.
187-
--[Fix] Change to source_utils for title regedit.
188-
--[Fix] Fixed error in code comparing string literal.
182+
[B]Update - v6.7.32 - December 27th, 2024[/B]
183+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
184+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
189185
</news>
190186
</extension>
191187

matrix/plugin.video.umbrella/changelog.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[B]Update - v6.7.32 - December 27th, 2024[/B]
2+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
3+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
4+
15
[B]Update - v6.7.31 - December 26th, 2024[/B]
26
--[Change] Made changes to the cache torrent function for TorBox.
37
--[Change] Made context menu use highlight color for Umbrella Settings

matrix/plugin.video.umbrella/resources/lib/cloud_scrapers/tb_cloud.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55

66
import re
7+
from threading import Thread
78
from resources.lib.cloud_scrapers import cloud_utils
89
from resources.lib.database import cache
910
from resources.lib.debrid.torbox import TorBox
@@ -34,20 +35,25 @@ def sources(self, data, hostDict):
3435
self.episode = str(data['episode']) if 'tvshowtitle' in data else None
3536
query_list = self.episode_query_list() if 'tvshowtitle' in data else self.year_query_list()
3637
# log_utils.log('query_list = %s' % query_list)
37-
cloud_folders = TorBox().user_cloud()
38-
if not cloud_folders: return sources
39-
cloud_folders = [i for i in cloud_folders['data'] if i['download_finished']]
40-
if not cloud_folders: return sources
38+
folders = []
39+
threads = (
40+
Thread(target=self._scraper, args=(TorBox().user_cloud, folders, 'torent')),
41+
Thread(target=self._scraper, args=(TorBox().user_cloud_usenet, folders, 'usenet'))
42+
)
43+
[i.start() for i in threads]
44+
[i.join() for i in threads]
45+
if not folders: return sources
4146
extras_filter = cloud_utils.extras_filter()
4247
except:
4348
from resources.lib.modules import log_utils
4449
log_utils.error('TB_CLOUD: ')
4550
return sources
4651

47-
for folder in cloud_folders:
52+
for folder in folders:
4853
try:
4954
folder_name = folder.get('name', '')
50-
if not cloud_utils.cloud_check_title(title, aliases, folder_name): continue
55+
# if not cloud_utils.cloud_check_title(title, aliases, folder_name): continue
56+
mediatype = folder.get('mediatype', '')
5157
request_id = folder.get('id', '')
5258
folder_files = folder['files']
5359
except:
@@ -90,9 +96,14 @@ def sources(self, data, hostDict):
9096
# name = name[len(name)-1]
9197
# index_pos = folder_files.index(file)
9298
# link = torrent_info['links'][index_pos]
93-
link = '%d,%d' % (int(request_id), file['id'])
99+
link = '%d,%d,%s' % (int(request_id), file['id'], mediatype)
94100
size = file.get('size', '')
95101

102+
if not (
103+
cloud_utils.cloud_check_title(title, aliases, name)
104+
or # because usenet obfuscation
105+
cloud_utils.cloud_check_title(title, aliases, folder_name)
106+
): continue
96107
name_info = sc_utils.info_from_name(name, title, self.year, hdlr, episode_title)
97108
hash = folder.get('hash', '')
98109
quality, info = sc_utils.get_release_quality(name_info, name)
@@ -145,9 +156,15 @@ def episode_list(self): # checks against formatted release_title with removed wh
145156

146157
def resolve(self, url):
147158
try:
148-
url = cache.get(TorBox().unrestrict_link, 48, url)
159+
url, mediatype = url.rsplit(',', 1)
160+
if mediatype == 'usenet': url = cache.get(TorBox().unrestrict_usenet, 1, url)
161+
else: url = cache.get(TorBox().unrestrict_link, 1, url)
149162
return url
150163
except:
151164
from resources.lib.modules import log_utils
152165
log_utils.error('TB_CLOUD: ')
153166
return None
167+
168+
def _scraper(self, function, results, mediatype):
169+
try: results += [{**i, 'mediatype': mediatype} for i in function()['data'] if i['download_finished']]
170+
except: pass

matrix/plugin.video.umbrella/resources/lib/debrid/torbox.py

+42-19
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818

1919
class TorBox:
2020
download = '/torrents/requestdl'
21+
download_usenet = '/usenet/requestdl'
2122
remove = '/torrents/controltorrent'
23+
remove_usenet = '/usenet/controlusenetdownload'
2224
stats = '/user/me'
2325
history = '/torrents/mylist'
26+
history_usenet = '/usenet/mylist'
2427
explore = '/torrents/mylist?id=%s'
28+
explore_usenet = '/usenet/mylist?id=%s'
2529
cache = '/torrents/checkcached'
2630
cloud = '/torrents/createtorrent'
2731
queued = '/torrents/getqueued'
@@ -72,12 +76,22 @@ def delete_torrent(self, request_id=''):
7276
def delete_torrent_queued(self, request_id=''):
7377
data = {'torrent_id': request_id, 'operation': 'delete'}
7478
return self._POST(self.removeQueued, json=data)
75-
79+
80+
def delete_usenet(self, request_id=''):
81+
data = {'usenet_id': request_id, 'operation': 'delete'}
82+
return self._POST(self.remove_usenet, json=data)
83+
7684
def unrestrict_link(self, file_id):
7785
torrent_id, file_id = file_id.split(',')
78-
params = {'token': self.api_key, 'torrent_id': torrent_id, 'file_id': file_id, 'user_ip': True}
86+
params = {'token': self.api_key, 'torrent_id': torrent_id, 'file_id': file_id}
7987
try: return self._GET(self.download, params=params)['data']
8088
except: return None
89+
90+
def unrestrict_usenet(self, file_id):
91+
usenet_id, file_id = file_id.split(',')
92+
params = {'token': self.api_key, 'usenet_id': usenet_id, 'file_id': file_id}
93+
try: return self._GET(self.download_usenet, params=params)['data']
94+
except: return None
8195

8296
def check_cache_single(self, hash):
8397
return self._GET(self.cache, params={'hash': hash, 'format': 'list'})
@@ -266,8 +280,12 @@ def account_info_to_dialog(self):
266280
return control.selectDialog(items, 'TorBox')
267281
except: log_utils.error()
268282

269-
def user_cloud(self):
270-
url = self.history
283+
def user_cloud(self, request_id=None):
284+
url = self.explore % request_id if request_id else self.history
285+
return self._GET(url)
286+
287+
def user_cloud_usenet(self, request_id=None):
288+
url = self.explore_usenet % request_id if request_id else self.history_usenet
271289
return self._GET(url)
272290

273291
def user_cloud_clear(self):
@@ -282,17 +300,21 @@ def user_cloud_to_listItem(self, folder_id=None):
282300
highlight_color = getSetting('highlight.color')
283301
folder_str, deleteMenu = getLS(40046).upper(), getLS(40050)
284302
file_str, downloadMenu = getLS(40047).upper(), getLS(40048)
285-
cloud_dict = self.user_cloud()
286-
cloud_dict = [i for i in cloud_dict['data'] if i['download_finished']]
287-
for count, item in enumerate(cloud_dict, 1):
303+
folders = []
304+
try: folders += [{**i, 'mediatype': 'torent'} for i in self.user_cloud()['data'] if i['download_finished']]
305+
except: pass
306+
try: folders += [{**i, 'mediatype': 'usenet'} for i in self.user_cloud_usenet()['data'] if i['download_finished']]
307+
except: pass
308+
folders.sort(key=lambda k: k['updated_at'], reverse=True)
309+
for count, item in enumerate(folders, 1):
288310
try:
289311
cm = []
290312
folder_name = string_tools.strip_non_ascii_and_unprintable(item['name'])
291313
status_str = '[COLOR %s]%s[/COLOR]' % (highlight_color, item['download_state'].capitalize())
292-
cm.append((deleteMenu % 'Torrent', 'RunPlugin(%s?action=tb_DeleteUserTorrent&id=%s&name=%s)' %
293-
(sysaddon, item['id'], quote_plus(folder_name))))
314+
cm.append((deleteMenu % 'Torrent', 'RunPlugin(%s?action=tb_DeleteUserTorrent&id=%s&mediatype=%s&name=%s)' %
315+
(sysaddon, item['id'], item['mediatype'], quote_plus(folder_name))))
294316
label = '%02d | [B]%s[/B] | [B]%s[/B] | [I]%s [/I]' % (count, status_str, folder_str, folder_name)
295-
url = '%s?action=tb_BrowseUserTorrents&id=%s' % (sysaddon, item['id'])
317+
url = '%s?action=tb_BrowseUserTorrents&id=%s&mediatype=%s' % (sysaddon, item['id'], item['mediatype'])
296318
item = control.item(label=label, offscreen=True)
297319
item.addContextMenuItems(cm)
298320
item.setArt({'icon': tb_icon, 'poster': tb_icon, 'thumb': tb_icon, 'fanart': addonFanart, 'banner': tb_icon})
@@ -302,13 +324,13 @@ def user_cloud_to_listItem(self, folder_id=None):
302324
control.content(syshandle, 'files')
303325
control.directory(syshandle, cacheToDisc=True)
304326

305-
def browse_user_torrents(self, folder_id):
327+
def browse_user_torrents(self, folder_id, mediatype):
306328
sysaddon, syshandle = 'plugin://plugin.video.umbrella/', int(argv[1])
307329
quote_plus = requests.utils.quote
308330
extensions = supported_video_extensions()
309331
file_str, downloadMenu = getLS(40047).upper(), getLS(40048)
310-
torrent_files = self.torrent_info(folder_id)
311-
video_files = [i for i in torrent_files['data']['files'] if i['short_name'].lower().endswith(tuple(extensions))]
332+
files = self.user_cloud_usenet(folder_id) if mediatype == 'usenet' else self.user_cloud(folder_id)
333+
video_files = [i for i in files['data']['files'] if i['short_name'].lower().endswith(tuple(extensions))]
312334
for count, item in enumerate(video_files, 1):
313335
try:
314336
cm = []
@@ -317,9 +339,9 @@ def browse_user_torrents(self, folder_id):
317339
display_size = float(int(size)) / 1073741824
318340
label = '%02d | [B]%s[/B] | %.2f GB | [I]%s [/I]' % (count, file_str, display_size, name)
319341
item = '%d,%d' % (int(folder_id), item['id'])
320-
url = '%s?action=play_URL&url=%s&caller=torbox&type=unrestrict' % (sysaddon, item)
321-
cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=torbox&type=unrestrict)' %
322-
(sysaddon, quote_plus(name), quote_plus(tb_icon), item)))
342+
url = '%s?action=play_URL&url=%s&caller=torbox&mediatype=%s&type=unrestrict' % (sysaddon, item, mediatype)
343+
cm.append((downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&url=%s&caller=torbox&mediatype=%s&type=unrestrict)' %
344+
(sysaddon, quote_plus(name), quote_plus(tb_icon), item, mediatype)))
323345
item = control.item(label=label, offscreen=True)
324346
item.addContextMenuItems(cm)
325347
item.setArt({'icon': tb_icon, 'poster': tb_icon, 'thumb': tb_icon, 'fanart': addonFanart, 'banner': tb_icon})
@@ -329,10 +351,10 @@ def browse_user_torrents(self, folder_id):
329351
control.content(syshandle, 'files')
330352
control.directory(syshandle, cacheToDisc=True)
331353

332-
def delete_user_torrent(self, request_id, name, multi=False):
354+
def delete_user_torrent(self, request_id, mediatype, name, multi=False):
333355
if multi == False:
334356
if not control.yesnoDialog(getLS(40050) % '?\n' + name, '', ''): return
335-
result = self.delete_torrent(request_id)
357+
result = self.delete_usenet(request_id) if mediatype == 'usenet' else self.delete_torrent(request_id)
336358
if result['success']:
337359
control.notification(message='TorBox: %s was removed' % name, icon=tb_icon)
338360
if not multi: control.refresh()
@@ -386,7 +408,8 @@ def delete_active_torrents(self, data):
386408
for torrent in data:
387409
name = torrent.get('name','Unknown')
388410
request_id = torrent.get('id')
389-
self.delete_user_torrent(request_id, name, multi=True)
411+
mediatype = torrent.get('mediatype')
412+
self.delete_user_torrent(request_id, mediatype, name, multi=True)
390413

391414
def delete_queued_torrents(self, data):
392415
if not control.yesnoDialog(getLS(40544), '', ''): return

matrix/plugin.video.umbrella/resources/lib/modules/router.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,10 @@ def router(argv2):
613613
torbox.TorBox().user_cloud_to_listItem()
614614
elif action == 'tb_BrowseUserTorrents':
615615
from resources.lib.debrid import torbox
616-
torbox.TorBox().browse_user_torrents(params.get('id'))
616+
torbox.TorBox().browse_user_torrents(params.get('id'), mediatype)
617617
elif action == 'tb_DeleteUserTorrent':
618618
from resources.lib.debrid import torbox
619-
torbox.TorBox().delete_user_torrent(params.get('id'), name)
619+
torbox.TorBox().delete_user_torrent(params.get('id'), mediatype, name)
620620
if action == 'tb_ServiceNavigator':
621621
from resources.lib.menus import navigator
622622
navigator.Navigator().torbox_service()
@@ -796,7 +796,8 @@ def router(argv2):
796796
try:
797797
from resources.lib.modules import downloader
798798
from resources.lib.debrid import torbox
799-
url = torbox.TorBox().unrestrict_link(url.replace(' ', '%20'))
799+
if mediatype == 'usenet': url = torbox.TorBox().unrestrict_usenet(url.replace(' ', '%20'))
800+
else: url = torbox.TorBox().unrestrict_link(url.replace(' ', '%20'))
800801
downloader.download(name, image, torbox.TorBox().add_headers_to_url(url))
801802
except:
802803
import traceback
@@ -969,6 +970,12 @@ def router(argv2):
969970
from resources.lib.debrid import alldebrid
970971
if params.get('type') == 'unrestrict': control.player.play(alldebrid.AllDebrid().unrestrict_link(url.replace(' ', '%20')))
971972
else: control.player.play(url.replace(' ', '%20'))
973+
elif caller == 'torbox':
974+
from resources.lib.debrid import torbox
975+
if params.get('type') == 'unrestrict':
976+
if mediatype == 'usenet': control.player.play(torbox.TorBox().unrestrict_usenet(url.replace(' ', '%20')))
977+
else: control.player.play(torbox.TorBox().unrestrict_link(url.replace(' ', '%20')))
978+
else: control.player.play(url.replace(' ', '%20'))
972979
else:
973980
control.player.play(url.replace(' ', '%20'))
974981
elif action == 'play_EpisodesList': # global context option

matrix/zips/addons.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8'?>
2-
<addons><addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.31">
2+
<addons><addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.32">
33
<requires>
44
<import addon="xbmc.python" version="3.0.0" />
55
<import addon="script.module.requests" />
@@ -180,13 +180,9 @@
180180
<screenshot>resources/screenshots/screenshot003.jpg</screenshot>
181181
</assets>
182182
<news>
183-
[B]Update - v6.7.31 - December 26th, 2024[/B]
184-
--[Change] Made changes to the cache torrent function for TorBox.
185-
--[Change] Made context menu use highlight color for Umbrella Settings
186-
--[Fix] Changes in module loads for internal and cloud scrapers.
187-
--[Fix] Change in way Trakt regular expression for list was handled.
188-
--[Fix] Change to source_utils for title regedit.
189-
--[Fix] Fixed error in code comparing string literal.
183+
[B]Update - v6.7.32 - December 27th, 2024[/B]
184+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
185+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
190186
</news>
191187
</extension>
192188

matrix/zips/addons.xml.md5

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
f7629b12573fa3ff2b8d86a27f001975
1+
4f2c9385be36610a1a3bbae7fdf6d447

matrix/zips/plugin.video.umbrella/addon.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.31">
1+
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.32">
22
<requires>
33
<import addon="xbmc.python" version="3.0.0"/>
44
<import addon="script.module.requests"/>
@@ -179,13 +179,9 @@
179179
<screenshot>resources/screenshots/screenshot003.jpg</screenshot>
180180
</assets>
181181
<news>
182-
[B]Update - v6.7.31 - December 26th, 2024[/B]
183-
--[Change] Made changes to the cache torrent function for TorBox.
184-
--[Change] Made context menu use highlight color for Umbrella Settings
185-
--[Fix] Changes in module loads for internal and cloud scrapers.
186-
--[Fix] Change in way Trakt regular expression for list was handled.
187-
--[Fix] Change to source_utils for title regedit.
188-
--[Fix] Fixed error in code comparing string literal.
182+
[B]Update - v6.7.32 - December 27th, 2024[/B]
183+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
184+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
189185
</news>
190186
</extension>
191187

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"python.testing.unittestArgs": [
3+
"-v",
4+
"-s",
5+
".",
6+
"-p",
7+
"*test.py"
8+
],
9+
"python.testing.pytestEnabled": false,
10+
"python.testing.unittestEnabled": true
11+
}

nexus/plugin.video.umbrella/addon.xml

+4-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.31">
1+
<addon id="plugin.video.umbrella" name="Umbrella" provider-name="Umbrella" version="6.7.32">
22
<requires>
33
<import addon="xbmc.python" version="3.0.0"/>
44
<import addon="script.module.requests"/>
@@ -179,13 +179,9 @@
179179
<screenshot>resources/screenshots/screenshot003.jpg</screenshot>
180180
</assets>
181181
<news>
182-
[B]Update - v6.7.31 - December 26th, 2024[/B]
183-
--[Change] Made changes to the cache torrent function for TorBox.
184-
--[Change] Made context menu use highlight color for Umbrella Settings
185-
--[Fix] Changes in module loads for internal and cloud scrapers.
186-
--[Fix] Change in way Trakt regular expression for list was handled.
187-
--[Fix] Change to source_utils for title regedit.
188-
--[Fix] Fixed error in code comparing string literal.
182+
[B]Update - v6.7.32 - December 27th, 2024[/B]
183+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
184+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
189185
</news>
190186
</extension>
191187

nexus/plugin.video.umbrella/changelog.txt

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
[B]Update - v6.7.32 - December 27th, 2024[/B]
2+
--[Fix] Used changes from kodifitzwell for TorBox cloud scraping and playing from cloud.
3+
--[Change] Used updates from kodifitzwell for TorBox for usenet.
4+
15
[B]Update - v6.7.31 - December 26th, 2024[/B]
26
--[Change] Made changes to the cache torrent function for TorBox.
37
--[Change] Made context menu use highlight color for Umbrella Settings

0 commit comments

Comments
 (0)