This repository has been archived by the owner on Oct 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete_finished.py
54 lines (45 loc) · 1.82 KB
/
delete_finished.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
####
# 04/2018 Graham Benton <[email protected]>
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# gPodder is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
# This extension deletes downloaded file and marks played any episodes
# that are marked finished
import gpodder
import logging
logger = logging.getLogger(__name__)
_ = gpodder.gettext
__title__ = _('Delete finished episodes')
__description__ = _('Deletes downloaded files for finished episodes')
__authors__ = 'Graham Benton <[email protected]>'
__category__ = 'post-download'
class gPodderExtension:
def __init__(self, container):
self.container = container
self.config = container.config
def on_episode_save(self, episode):
""" Called when an episode is saved to the database
This extension will be called when a new episode is added to the
database or when the state of an existing episode is changed.
@param episode: A gpodder.model.PodcastEpisode instance
"""
if episode.is_finished():
if episode.state == gpodder.STATE_DOWNLOADED:
logger.info("deleting file {}".format(episode.trimmed_title))
episode.delete_from_disk()
if episode.check_is_new():
episode.mark(is_played=True)