|
@@ -263,12 +263,13 @@ if os.access(os.environ['HOME'] + "/.stov", os.F_OK & os.W_OK) is not True:
|
|
if sys.version_info >= (3, 0):
|
|
if sys.version_info >= (3, 0):
|
|
temp_input = input()
|
|
temp_input = input()
|
|
else:
|
|
else:
|
|
|
|
+ # noinspection PyCompatibility
|
|
temp_input = raw_input()
|
|
temp_input = raw_input()
|
|
if temp_input == "yes":
|
|
if temp_input == "yes":
|
|
conf.assist()
|
|
conf.assist()
|
|
try:
|
|
try:
|
|
conf.Initialize()
|
|
conf.Initialize()
|
|
- except stov_exceptions.ConfigFileWriteErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
logger.info(_("Writing initial configuration according to your "
|
|
logger.info(_("Writing initial configuration according to your "
|
|
@@ -280,18 +281,18 @@ if os.access(os.environ['HOME'] + "/.stov", os.F_OK & os.W_OK) is not True:
|
|
"and database."))
|
|
"and database."))
|
|
try:
|
|
try:
|
|
conf.Initialize()
|
|
conf.Initialize()
|
|
- except stov_exceptions.DirectoryCreationFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DirectoryCreationFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- except stov_exceptions.ConfigFileWriteErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
conf = configuration.conf()
|
|
conf = configuration.conf()
|
|
try:
|
|
try:
|
|
logger.debug(_("Comparing current and running configuration version."))
|
|
logger.debug(_("Comparing current and running configuration version."))
|
|
check_result = conf.CheckConfig()
|
|
check_result = conf.CheckConfig()
|
|
- except stov_exceptions.ConfigFileReadErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileReadErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- except stov_exceptions.InvalidConfigurationVersionException, e:
|
|
|
|
|
|
+ except stov_exceptions.InvalidConfigurationVersionException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
if check_result is not True:
|
|
if check_result is not True:
|
|
@@ -299,9 +300,9 @@ else:
|
|
" update now."))
|
|
" update now."))
|
|
try:
|
|
try:
|
|
conf.UpdateConfig()
|
|
conf.UpdateConfig()
|
|
- except stov_exceptions.ConfigFileReadErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileReadErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- except stov_exceptions.ConfigFileWriteErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
|
|
|
|
|
|
|
|
@@ -310,19 +311,19 @@ else:
|
|
if os.access(conf.dbpath, os.F_OK):
|
|
if os.access(conf.dbpath, os.F_OK):
|
|
try:
|
|
try:
|
|
db = database.db(path=conf.dbpath, version=conf.values["db_version"])
|
|
db = database.db(path=conf.dbpath, version=conf.values["db_version"])
|
|
- except stov_exceptions.DBConnectionFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBConnectionFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
db = database.db(path=conf.dbpath, version=conf.values["db_version"])
|
|
db = database.db(path=conf.dbpath, version=conf.values["db_version"])
|
|
- except stov_exceptions.DBConnectionFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBConnectionFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
db.Populate()
|
|
db.Populate()
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
sys.exit(1)
|
|
sys.exit(1)
|
|
|
|
|
|
@@ -336,7 +337,7 @@ try:
|
|
logger.debug("Opening configuration file.")
|
|
logger.debug("Opening configuration file.")
|
|
try:
|
|
try:
|
|
conf.WriteConfig()
|
|
conf.WriteConfig()
|
|
- except stov_exceptions.ConfigFileWriteErrorException, e:
|
|
|
|
|
|
+ except stov_exceptions.ConfigFileWriteErrorException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
except stov_exceptions.DBWriteAccessFailedException as e:
|
|
except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
@@ -382,7 +383,6 @@ run the corresponding code
|
|
|
|
|
|
"""
|
|
"""
|
|
if options.add is True:
|
|
if options.add is True:
|
|
- AddSub = True
|
|
|
|
if options.channel is not None and options.searchparameter is None:
|
|
if options.channel is not None and options.searchparameter is None:
|
|
NewSubscription = subscription.sub(type="channel",
|
|
NewSubscription = subscription.sub(type="channel",
|
|
name=options.channel, conf=conf)
|
|
name=options.channel, conf=conf)
|
|
@@ -406,37 +406,37 @@ if options.add is True:
|
|
else:
|
|
else:
|
|
logger.error(_("None or invalid subscription type given, please check "
|
|
logger.error(_("None or invalid subscription type given, please check "
|
|
"the type option and try again."))
|
|
"the type option and try again."))
|
|
- AddSub = False
|
|
|
|
- if AddSub is True:
|
|
|
|
- try:
|
|
|
|
- message, id = db.InsertSubscription(NewSubscription.AddSub())
|
|
|
|
- NewSubscription.SetID(id)
|
|
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
- logger.error(e)
|
|
|
|
- try:
|
|
|
|
- NewSubscription.ParseAPIData()
|
|
|
|
- except stov_exceptions.YoutubeAPITimeoutException, e:
|
|
|
|
- logger.error(e)
|
|
|
|
- except stov_exceptions.NoDataFromYoutubeAPIException, e:
|
|
|
|
- logger.error(e)
|
|
|
|
- for video in NewSubscription.parsed_response.videos:
|
|
|
|
- if not db.VideoInDatabase(video.ytid):
|
|
|
|
- if NewSubscription.CheckStringMatch(video):
|
|
|
|
- db.InsertVideo(video, NewSubscription.GetId())
|
|
|
|
- logger.info(_("New subscription ") + NewSubscription.GetTitle()
|
|
|
|
- + _(" successfully added"))
|
|
|
|
|
|
+ sys.exit(1)
|
|
|
|
+ try:
|
|
|
|
+ message, id = db.InsertSubscription(NewSubscription.AddSub())
|
|
|
|
+ NewSubscription.SetID(id)
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
|
|
+ logger.error(e)
|
|
|
|
+ try:
|
|
|
|
+ NewSubscription.ParseAPIData()
|
|
|
|
+ except stov_exceptions.YoutubeAPITimeoutException as e:
|
|
|
|
+ logger.error(e)
|
|
|
|
+ except stov_exceptions.NoDataFromYoutubeAPIException as e:
|
|
|
|
+ logger.error(e)
|
|
|
|
+ for video in NewSubscription.parsed_response.videos:
|
|
|
|
+ if not db.VideoInDatabase(video.ytid):
|
|
|
|
+ if NewSubscription.CheckStringMatch(video):
|
|
|
|
+ db.InsertVideo(video, NewSubscription.GetId())
|
|
|
|
+ logger.info(_("New subscription ") + NewSubscription.GetTitle()
|
|
|
|
+ + _(" successfully added"))
|
|
|
|
|
|
elif options.list is True:
|
|
elif options.list is True:
|
|
Listofsubscriptions = db.GetSubscriptions()
|
|
Listofsubscriptions = db.GetSubscriptions()
|
|
|
|
+ sub_state = None
|
|
if len(Listofsubscriptions) != 0:
|
|
if len(Listofsubscriptions) != 0:
|
|
logger.info(_("ID Title"))
|
|
logger.info(_("ID Title"))
|
|
- for subscription in Listofsubscriptions:
|
|
|
|
- if int(subscription[6]) == 0:
|
|
|
|
|
|
+ for sub in Listofsubscriptions:
|
|
|
|
+ if int(sub[6]) == 0:
|
|
sub_state = _("enabled")
|
|
sub_state = _("enabled")
|
|
- elif int(subscription[2]) == 1:
|
|
|
|
|
|
+ elif int(sub[6]) == 1:
|
|
sub_state = _("disabled")
|
|
sub_state = _("disabled")
|
|
- if subscription[0] is not None:
|
|
|
|
- logger.info(str(subscription[0]) + " " + subscription[1]
|
|
|
|
|
|
+ if sub[0] is not None:
|
|
|
|
+ logger.info(str(sub[0]) + " " + sub[1]
|
|
+ " (%s)" % sub_state)
|
|
+ " (%s)" % sub_state)
|
|
else:
|
|
else:
|
|
logger.info(_("No subscriptions added yet, add one!"))
|
|
logger.info(_("No subscriptions added yet, add one!"))
|
|
@@ -450,9 +450,9 @@ elif options.deleteid is not None:
|
|
else:
|
|
else:
|
|
try:
|
|
try:
|
|
deletemessage = db.DeleteSubscription(DeleteID)
|
|
deletemessage = db.DeleteSubscription(DeleteID)
|
|
- except stov_exceptions.SubscriptionNotFoundException, e:
|
|
|
|
|
|
+ except stov_exceptions.SubscriptionNotFoundException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
logger.info(deletemessage)
|
|
logger.info(deletemessage)
|
|
@@ -471,9 +471,9 @@ elif options.update is True:
|
|
for element in listofsubscriptions:
|
|
for element in listofsubscriptions:
|
|
try:
|
|
try:
|
|
element.ParseAPIData()
|
|
element.ParseAPIData()
|
|
- except stov_exceptions.YoutubeAPITimeoutException, e:
|
|
|
|
|
|
+ except stov_exceptions.YoutubeAPITimeoutException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- except stov_exceptions.NoDataFromYoutubeAPIException, e:
|
|
|
|
|
|
+ except stov_exceptions.NoDataFromYoutubeAPIException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
for video in element.parsed_response.videos:
|
|
for video in element.parsed_response.videos:
|
|
if not db.VideoInDatabase(video.ytid):
|
|
if not db.VideoInDatabase(video.ytid):
|
|
@@ -507,7 +507,7 @@ elif options.download is True:
|
|
element.GatherVideos(videos)
|
|
element.GatherVideos(videos)
|
|
try:
|
|
try:
|
|
element.DownloadVideos(itag_value)
|
|
element.DownloadVideos(itag_value)
|
|
- except stov_exceptions.SubscriptionDisabledException, e:
|
|
|
|
|
|
+ except stov_exceptions.SubscriptionDisabledException as e:
|
|
logger.debug(e)
|
|
logger.debug(e)
|
|
for entry in element.DownloadedVideos:
|
|
for entry in element.DownloadedVideos:
|
|
db.UpdateVideoDownloadStatus(entry.GetID(), 1)
|
|
db.UpdateVideoDownloadStatus(entry.GetID(), 1)
|
|
@@ -519,7 +519,7 @@ elif options.download is True:
|
|
db.UpdateVideoFailCount(video.failcnt, video.GetID())
|
|
db.UpdateVideoFailCount(video.failcnt, video.GetID())
|
|
if video.failcnt >= int(conf.values["maxfails"]):
|
|
if video.failcnt >= int(conf.values["maxfails"]):
|
|
db.DisableFailedVideo(video.GetID())
|
|
db.DisableFailedVideo(video.GetID())
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
if videosdownloaded > 0 and conf.values["notify"] == "yes":
|
|
if videosdownloaded > 0 and conf.values["notify"] == "yes":
|
|
MailText = ""
|
|
MailText = ""
|
|
@@ -594,35 +594,38 @@ elif options.download is True:
|
|
elif options.subscriptionid is not None:
|
|
elif options.subscriptionid is not None:
|
|
try:
|
|
try:
|
|
Data = db.GetSubscription(options.subscriptionid)
|
|
Data = db.GetSubscription(options.subscriptionid)
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- if Data:
|
|
|
|
- Subscription = subscription.sub(id=Data[0][0], title=Data[0][1],
|
|
|
|
- type=Data[0][2], name=Data[0][3],
|
|
|
|
- search=Data[0][4],
|
|
|
|
- directory=Data[0][5],
|
|
|
|
- disabled=Data[0][6], conf=conf)
|
|
|
|
- videos = db.GetVideos(Subscription.GetId())
|
|
|
|
- Subscription.GatherVideos(videos)
|
|
|
|
- video_list = Subscription.PrintVideos()
|
|
|
|
- for video in video_list:
|
|
|
|
- logger.info(video)
|
|
|
|
|
|
+ sys.exit(1)
|
|
else:
|
|
else:
|
|
- logger.error(_("Invalid subscription, please check the list and try "
|
|
|
|
- "again"))
|
|
|
|
|
|
+ if Data:
|
|
|
|
+ Subscription = subscription.sub(id=Data[0][0], title=Data[0][1],
|
|
|
|
+ type=Data[0][2], name=Data[0][3],
|
|
|
|
+ search=Data[0][4],
|
|
|
|
+ directory=Data[0][5],
|
|
|
|
+ disabled=Data[0][6], conf=conf)
|
|
|
|
+ videos = db.GetVideos(Subscription.GetId())
|
|
|
|
+ Subscription.GatherVideos(videos)
|
|
|
|
+ video_list = Subscription.PrintVideos()
|
|
|
|
+ for video in video_list:
|
|
|
|
+ logger.info(video)
|
|
|
|
+ else:
|
|
|
|
+ logger.error(_("Invalid subscription, please check the list and "
|
|
|
|
+ "try again"))
|
|
elif options.catchup is not None:
|
|
elif options.catchup is not None:
|
|
try:
|
|
try:
|
|
sub_data = db.GetSubscriptionTitle(options.catchup)
|
|
sub_data = db.GetSubscriptionTitle(options.catchup)
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
- if sub_data != []:
|
|
|
|
- try:
|
|
|
|
- db.MarkVideosDownloaded(options.catchup)
|
|
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
- logger.error(e)
|
|
|
|
else:
|
|
else:
|
|
- logger.error(_("The subscription could not be updated, "
|
|
|
|
- "please check if the ID given is correct."))
|
|
|
|
|
|
+ if sub_data != []:
|
|
|
|
+ try:
|
|
|
|
+ db.MarkVideosDownloaded(options.catchup)
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
|
|
+ logger.error(e)
|
|
|
|
+ else:
|
|
|
|
+ logger.error(_("The subscription could not be updated, "
|
|
|
|
+ "please check if the ID given is correct."))
|
|
|
|
|
|
|
|
|
|
elif options.cleanup is True:
|
|
elif options.cleanup is True:
|
|
@@ -642,11 +645,11 @@ elif options.cleanup is True:
|
|
"database") % delete_video.title)
|
|
"database") % delete_video.title)
|
|
try:
|
|
try:
|
|
db.DeleteVideo(delete_video.GetID())
|
|
db.DeleteVideo(delete_video.GetID())
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
try:
|
|
try:
|
|
db.Vacuum()
|
|
db.Vacuum()
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
elif options.enableid is not None:
|
|
elif options.enableid is not None:
|
|
subscription_state = db.GetSubscription(options.enableid)
|
|
subscription_state = db.GetSubscription(options.enableid)
|
|
@@ -657,7 +660,7 @@ elif options.enableid is not None:
|
|
elif int(subscription_state[0][6]) == 1:
|
|
elif int(subscription_state[0][6]) == 1:
|
|
try:
|
|
try:
|
|
db.ChangeSubscriptionState(options.enableid, 0)
|
|
db.ChangeSubscriptionState(options.enableid, 0)
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
logger.info(_("Enabled subscription ID %s")
|
|
logger.info(_("Enabled subscription ID %s")
|
|
@@ -674,7 +677,7 @@ elif options.disableid is not None:
|
|
elif int(subscription_state[0][6]) == 0:
|
|
elif int(subscription_state[0][6]) == 0:
|
|
try:
|
|
try:
|
|
db.ChangeSubscriptionState(options.disableid, 1)
|
|
db.ChangeSubscriptionState(options.disableid, 1)
|
|
- except stov_exceptions.DBWriteAccessFailedException, e:
|
|
|
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as e:
|
|
logger.error(e)
|
|
logger.error(e)
|
|
else:
|
|
else:
|
|
logger.info(_("Disabled subscription ID %s")
|
|
logger.info(_("Disabled subscription ID %s")
|