Skip to content

Commit

Permalink
fixes, smart add (season), use provider filter, etc.
Browse files Browse the repository at this point in the history
Fixes:
- Added more cases for Preview/Non-numbered episodes

New:
- Smart add extended for Seasons using Global Option
- External Source to use providers that carry same content movie/show

Changes:
- Refresh library will que refresh commands while Scheduler is running
to avoid multiple refreshes and meta download
- gvideo host to get accurate file-size instead of approx.
  • Loading branch information
coder-alpha committed Apr 1, 2019
1 parent 5af37d4 commit 407b199
Show file tree
Hide file tree
Showing 9 changed files with 260 additions and 111 deletions.
9 changes: 6 additions & 3 deletions Contents/Code/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
################################################################################
TITLE = "FMoviesPlus"
VERSION = '0.77' # Release notation (x.y - where x is major and y is minor)
VERSION = '0.78' # Release notation (x.y - where x is major and y is minor)
TAG = ''
GITHUB_REPOSITORY = 'coder-alpha/FMoviesPlus.bundle'
PREFIX = "/video/fmoviesplus"
Expand Down Expand Up @@ -79,6 +79,8 @@
EMOJI_ANIME = u'\u2318'
EMOJI_EXT = u'*'
EMOJI_GLASSES = u'\U0001F453'
EMOJI_DOWNARROW = u'\U00012B07'
EMOJI_DOWNARROW2 = u'\U0001F53B'

# Simple Emoji's
EMOJI_HEART = u'\u2665'
Expand Down Expand Up @@ -129,9 +131,10 @@
DEVICE_OPTIONS[12]:'Downloads-Listing - Reverse the order of Downloads i.e. oldest entry on top',
DEVICE_OPTIONS[13]:'Force-Transcoding (IMDb) - Force transcoding IMDb videos by PMS'}

GLOBAL_OPTIONS = ['Retry-Failed-Downloads','Dont-Refresh-Library-Downloads']
GLOBAL_OPTIONS = ['Retry-Failed-Downloads','Dont-Refresh-Library-Downloads','Extend-Smart-Add-For-Seasons']
GLOBAL_OPTION = {GLOBAL_OPTIONS[0]:'On Plugin Initialization Retry Failed Downloads',
GLOBAL_OPTIONS[1]:'Don\'t perform a Library Section Refresh after an Item is Downloaded'}
GLOBAL_OPTIONS[1]:'Don\'t perform a Library Section Refresh after an Item is Downloaded',
GLOBAL_OPTIONS[2]:'Extend Smart Add AutoPilot Option for Seasons as well'}

DEVICE_OPTION_CONSTRAINTS = {DEVICE_OPTIONS[2]:[{'Pref':'use_https_alt','Desc':'Use Alternate SSL/TLS','ReqValue':'disabled'}]}
DEVICE_OPTION_CONSTRAINTS2 = {DEVICE_OPTIONS[5]:[{'Option':6,'ReqValue':False}], DEVICE_OPTIONS[6]:[{'Option':5,'ReqValue':False}]}
Expand Down
33 changes: 31 additions & 2 deletions Contents/Code/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
Dict['DOWNLOAD_RATE_LIMIT_TIME'] = []
REMAP_EXTRAS = {'behind the scenes':'behindthescenes', 'deleted scenes':'deleted', 'featurette':'featurette', 'interviews':'interview', 'misc.':'scene', 'music video':'short', 'trailer':'trailer'}

AUTOPILOT_SCHEDULER = [False]
AUTOPILOT_SCHEDULER_POST_REFRESH = []

QUEUE_RUN_ITEMS = {}
WAIT_AND_RETRY_ON_429 = True
CONNECTION_TIMEOUT = 60
Expand Down Expand Up @@ -817,11 +820,37 @@ def download_completed(final_abs_path, section_title, section_key, purgeKey, fil
else:
Log('Download Completed - %s' % final_abs_path)

if fileExists == False and common.UsingOption(key=common.GLOBAL_OPTIONS[1], session='None') == False:
if fileExists == False and common.UsingOption(key=common.GLOBAL_OPTIONS[1], session='None') == False and AUTOPILOT_SCHEDULER[0] == False:
Thread.Create(refresh_section, {}, section_title, section_key)


if fileExists == False and common.UsingOption(key=common.GLOBAL_OPTIONS[1], session='None') == False and AUTOPILOT_SCHEDULER[0] == True:
AUTOPILOT_SCHEDULER_POST_REFRESH.append([section_title, section_key])

Thread.Create(trigger_que_run)

def post_autopilot_refresh():

tuid = common.id_generator(16)
common.control.AddThread('PostAutoPilotRefreshSections', 'Refresh Sections after AutoPilot Scheduler', time.time(), '3', False, tuid)
try:
if len(AUTOPILOT_SCHEDULER_POST_REFRESH) > 0 and AUTOPILOT_SCHEDULER[0] == True:
AUTOPILOT_SCHEDULER_POST_REFRESH = list(set(AUTOPILOT_SCHEDULER_POST_REFRESH))

for i in AUTOPILOT_SCHEDULER_POST_REFRESH:
refresh_section(i[0], i[1])

except Exception as e:
Log(e)

try:
del AUTOPILOT_SCHEDULER[:]
del AUTOPILOT_SCHEDULER_POST_REFRESH[:]
AUTOPILOT_SCHEDULER.append(False)
except:
pass

common.control.RemoveThread(tuid)

def download_failed(url, error, progress, startPos, purgeKey):

Log('Download Failed: Error - %s' % error)
Expand Down
83 changes: 62 additions & 21 deletions Contents/Code/downloadsmenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

ITEM_FOR_UPDATE = {}

SMART_ADD_EP_FALLOUT_DAYS = 30
SMART_ADD_SEASON_FALLOUT_DAYS = 365

#######################################################################################################
@route(PREFIX + '/AddToAutoPilotDownloads')
def AddToAutoPilotDownloads(title, year, type, purl=None, thumb=None, summary=None, quality=None, file_size=None, riptype='BRRIP', season=None, season_end=None, episode_start=None, episode_end=None, vidtype=None, section_path=None, section_title=None, section_key=None, session=None, admin=False, all_seasons=False, edit=False, mode=None, sub_mand=False, scheduled=False, smart_add=False, ssources=None, sproviders=None, **kwargs):
Expand Down Expand Up @@ -541,14 +544,27 @@ def AutoPilotDownloadThread1(item=None, runForWaiting=False, viaRunNow=False):
removeEntry = False
removeEntry_item = None
items_for_removal = {}
items_for_smart_add = {}

if item == None: # runs via Scheduler and after Initialization (plugin restart)
try:
del download.AUTOPILOT_SCHEDULER[:]
download.AUTOPILOT_SCHEDULER.append(True)
except:
pass

for type in common.DOWNLOAD_AUTOPILOT.keys():
items_for_removal[type] = []
for item in common.DOWNLOAD_AUTOPILOT[type]:
if (item['status'] == common.DOWNLOAD_AUTOPILOT_STATUS[2] or item['status'] == common.DOWNLOAD_AUTOPILOT_STATUS[6]):
items_for_removal[type].append(item)
elif 'smart_add_active' in item.keys() and 'first_time' in item.keys() and item['smart_add_active'] == True and float(time.time() - item['first_time']) > float(60*60*24*15):
elif type == 'show' and 'smart_add_active_season' not in item.keys() and 'smart_add_active' in item.keys() and 'first_time' in item.keys() and item['smart_add_active'] == True and float(time.time() - item['first_time']) > float(60*60*24*SMART_ADD_EP_FALLOUT_DAYS):
if common.UsingOption(key=common.GLOBAL_OPTIONS[2], session='None') == True:
item_i = item.copy()
item_i = itemForSmartAadd(item=item_i, smarttype='season')
items_for_smart_add[type].append(item_i)
items_for_removal[type].append(item)
elif type == 'show' and 'smart_add_active_season' in item.keys() and 'first_time' in item.keys() and item['smart_add_active_season'] == True and float(time.time() - item['first_time']) > float(60*60*24*SMART_ADD_SEASON_FALLOUT_DAYS):
items_for_removal[type].append(item)
if (item['status'] != common.DOWNLOAD_AUTOPILOT_STATUS[2] and runForWaiting == False) or (runForWaiting == True and (item['status'] == common.DOWNLOAD_AUTOPILOT_STATUS[0] or item['status'] == common.DOWNLOAD_AUTOPILOT_STATUS[3])) or (item['status'] == common.DOWNLOAD_AUTOPILOT_STATUS[0] and float(time.time() - item['timeAdded']) > float(60*60)):
sources = None
Expand Down Expand Up @@ -605,6 +621,7 @@ def AutoPilotDownloadThread1(item=None, runForWaiting=False, viaRunNow=False):
i['status'] = common.DOWNLOAD_AUTOPILOT_STATUS[6]
except:
pass
download.post_autopilot_refresh()
else: # runs when added or via Run Now
sources = None
start_time = time.time()
Expand Down Expand Up @@ -678,8 +695,6 @@ def AutoPilotDownloadThread1(item=None, runForWaiting=False, viaRunNow=False):
except:
pass

items_for_smart_add = {}

# remove completed entries
for type_r in items_for_removal.keys():
items_for_smart_add[type_r] = []
Expand All @@ -689,19 +704,10 @@ def AutoPilotDownloadThread1(item=None, runForWaiting=False, viaRunNow=False):
try:
if common.DEV_DEBUG == True and Prefs["use_debug"]:
Log('Item for removal: %s S%s E%s' % (item_i['short_title'],item_i['season'],item_i['episode']))
bool, lastep = verifyForSmart(item_i)
bool, lastep = verifyForSmart(item_i, smarttype='episode')
common.DOWNLOAD_AUTOPILOT[type_r].remove(item_i)
if bool == True:
item_i['episode'] = lastep + 1
item_i['first_time'] = time.time()
item_i['smart_add_active'] = True
item_i['status'] = common.DOWNLOAD_AUTOPILOT_STATUS[1]
item_i['title'] = '%s S%sE%s' % (item_i['short_title'], item_i['season'], item_i['episode'])
item_i['uid'] = common.makeUID(item_i['short_title'], item_i['year'], item_i['quality'], item_i['file_size'], item_i['purl'], item_i['season'], item_i['episode'])
if int(item_i['episode']) < 100:
item_i['watch_title'] = '%s S%sE%02d' % (item_i['short_title'],int(item_i['season']),int(item_i['episode']))
else:
item_i['watch_title'] = '%s S%sE%03d' % (item_i['short_title'],int(item_i['season']),int(item_i['episode']))
item_i = itemForSmartAadd(item=item_i, smarttype='episode', lastep=lastep)
items_for_smart_add[type_r].append(item_i)
except Exception as e:
Log.Error('ERROR: downloadsmenu.py > AutoPilotDownloadThread1 > items_for_removal: %s' % e)
Expand All @@ -723,18 +729,53 @@ def AutoPilotDownloadThread1(item=None, runForWaiting=False, viaRunNow=False):
common.control.RemoveThread(tuid)

del AutoPilotDownloadThread1_Singleton[:]

#######################################################################################################
def itemForSmartAadd(item=None, smarttype='episode', lastep=0):

if item['type'] == 'show':
if type == 'episode':
item['episode'] = int(lastep) + 1
item['first_time'] = time.time()
item['smart_add_active'] = True
if 'smart_add_active_season' in item.keys():
del item['smart_add_active_season']
item['status'] = common.DOWNLOAD_AUTOPILOT_STATUS[1]
item['title'] = '%s S%sE%s' % (item['short_title'], item['season'], item['episode'])
item['uid'] = common.makeUID(item['short_title'], item['year'], item['quality'], item['file_size'], item['purl'], item['season'], item['episode'])
if int(item['episode']) < 100:
item['watch_title'] = '%s S%sE%02d' % (item['short_title'],int(item['season']),int(item['episode']))
else:
item['watch_title'] = '%s S%sE%03d' % (item['short_title'],int(item['season']),int(item['episode']))
elif type == 'season':
item['episode'] = int(lastep) + 1
item['season'] = int(item['season']) + 1
item['first_time'] = time.time()
item['smart_add_active'] = True
item['smart_add_active_season'] = True
item['status'] = common.DOWNLOAD_AUTOPILOT_STATUS[1]
item['title'] = '%s S%sE%s' % (item['short_title'], item['season'], item['episode'])
item['uid'] = common.makeUID(item['short_title'], item['year'], item['quality'], item['file_size'], item['purl'], item['season'], item['episode'])
if int(item['episode']) < 100:
item['watch_title'] = '%s S%sE%02d' % (item['short_title'],int(item['season']),int(item['episode']))
else:
item['watch_title'] = '%s S%sE%03d' % (item['short_title'],int(item['season']),int(item['episode']))

return item

#######################################################################################################
def verifyForSmart(item):
def verifyForSmart(item, smarttype='episode'):

lastep = 0
no_items = 0
if 'smart_add' in item.keys() and item['smart_add'] == True:
for i in common.DOWNLOAD_AUTOPILOT['show']:
if item['short_title'] == i['short_title'] and item['season'] == i['season']:
no_items += 1
if i['episode'] > lastep:
lastep = int(i['episode'])

if smarttype == 'episode':
if 'smart_add' in item.keys() and item['smart_add'] == True:
for i in common.DOWNLOAD_AUTOPILOT['show']:
if item['short_title'] == i['short_title'] and item['season'] == i['season']:
no_items += 1
if i['episode'] > lastep:
lastep = int(i['episode'])

if no_items == 1:
return True, lastep
Expand Down
Loading

0 comments on commit 407b199

Please sign in to comment.