Skip to content

Commit

Permalink
rename_download: Add add_sortdate and add_podcast_title option
Browse files Browse the repository at this point in the history
Based on a patch by Rob <rob_is@jabawok.net>.
  • Loading branch information
thp committed Sep 29, 2015
1 parent 7575480 commit bf31b91
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions share/gpodder/extensions/rename_download.py
Expand Up @@ -20,27 +20,41 @@
__payment__ = 'https://flattr.com/submit/auto?user_id=BerndSch&url=http://wiki.gpodder.org/wiki/Extensions/RenameAfterDownload'
__category__ = 'post-download'

DefaultConfig = {
'add_sortdate': False, # Add the sortdate as prefix
'add_podcast_title': False, # Add the podcast title as prefix
}


class gPodderExtension:
def __init__(self, container):
self.container = container
self.config = self.container.config

def on_episode_downloaded(self, episode):
current_filename = episode.local_filename(create=False)

new_filename = self.make_filename(current_filename, episode.title)
new_filename = self.make_filename(current_filename, episode.title,
episode.sortdate, episode.channel.title)

if new_filename != current_filename:
logger.info('Renaming: %s -> %s', current_filename, new_filename)
os.rename(current_filename, new_filename)
util.rename_episode_file(episode, new_filename)

def make_filename(self, current_filename, title):
def make_filename(self, current_filename, title, sortdate, podcast_title):
dirname = os.path.dirname(current_filename)
filename = os.path.basename(current_filename)
basename, ext = os.path.splitext(filename)

new_basename = util.sanitize_encoding(title) + ext
new_basename = []
new_basename.append(util.sanitize_encoding(title) + ext)
if self.config.add_podcast_title:
new_basename.insert(0, podcast_title)
if self.config.add_sortdate:
new_basename.insert(0, sortdate)
new_basename = ' - '.join(new_basename)

# On Windows, force ASCII encoding for filenames (bug 1724)
new_basename = util.sanitize_filename(new_basename,
use_ascii=gpodder.ui.win32)
Expand Down

1 comment on commit bf31b91

@aburlot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works like a charm 👍 thanks a lot !
For those who might not get it working : you need to check two boxes in the gPodder configuration editor in order to get the modification.

Please sign in to comment.