2

I'm using Arch Linux.

To download podcasts, I use gPodder 3.

To listen to my podcasts, I'm using Rockbox on my iPod Classic.

The thing is, the podcasts don't get sorted nicely on my iPod: everything will be sorted alphabetically. To overcome this , I'd like to change the podcast name right after downloading to something like:

YYYYMMDD_Podcast_Name.mp4

For example:

20130828_Easy_Linux_Remote_Desktop_LAS_s28e03.mp4

That way, even when sorting alphabetically, the podcasts would be in the right order.

How can I get this done? I know that there is a plugin called rename_downlad.py, which will convert the podcast name to <episode_title>.<ext>, but that's not exactly what I want. I tried to modify this extension in /usr/share/gpodder/extensions/rename_download.py:

line 45:

new_filename = str(datetime.datetime.now().strftime("%Y%b%d_")) + os.path.join(dirname, new_basename)

but for some reason, this didn't work.

How can I get this done? Note that in my example, the only thing that gets added to the title is the current date. It would be nice if this could be the episode's release date instead, but I'm already happy with just adding the current date.

1

If you simply want to rename the files so that they include the YYMMDD_Podcast_Name.mp4 you can do so using this Bash script:

$ for i in *.mp4; do
    dateString=$(date +"%Y%m%d" --date @$(stat -c %Z "$i"))
    mv "$i" "${dateString}_$i"
done

Example

Say I have the following files.

$ ls | paste - -
file1.mp4   file2.mp4
file3.mp4   file4.mp4
file5.mp4   file6.mp4
file7.mp4   file8.mp4
file9.mp4   

Run the above command as a one liner:

$ for i in *.mp4; do dateString=$(date +"%Y%m%d" \
    --date @$(stat -c %Z "$i")); mv "$i" "${dateString}_$i"; done

Now the files are named like so:

$ ls | paste - -
20130828_file1.mp4  20130828_file2.mp4
20130828_file3.mp4  20130828_file4.mp4
20130828_file5.mp4  20130828_file6.mp4
20130828_file7.mp4  20130828_file8.mp4
20130828_file9.mp4  

Details

The above technique is using the stat command to get the files' time of the last change in seconds since Epoch.

  %Z     Time of last change as seconds since Epoch

This number of seconds is then used by the date command to determine the YYNNDD time for those seconds.

date +"%Y%m%d" --date @...seconds...

NOTE: The @ sign is important, it tells the date command that we're giving it seconds.

Once we've calculated the YYMMDD we use a simple mv command to rename the file.

An alternative - Sorting in Rockbox

An alternative to renaming the files with a date prefixed is to configure Rockbox so that it sorts files based on their date. You can also sort directories based on their name.

These settings are under the menu hierarchy:

                               Rockbox -> Settings -> General Settings -> File View

                                  ss of rockbox settings

The 2 key settings are:

  • Sort Directories - set to *Alphabetical"
  • Sort Files - set to "By Date"

NOTE: the "Sort files" can also be set to "By Newest Date".

You can see more about the above settings on the Rockbox website on the page titled: 8 General Settings.

  • Hey slm, thank you for your response. The problem with this solution is, that gPodder will not recognize the downloaded files, and it will ask to redownload them afterwards. It would be nice if this would be covered. Maybe by touching an empty filename.mp4, and moving the 'real' videos to a new directory. I'm not sure whether this would work, though, as I don't know whether gPodder checks for metadata, too. – Exeleration-G Aug 28 '13 at 15:43
  • @Exeleration-G - doesn't Rockbox sort by filenames and/or the metadata in those files? I have it as well and I'm pretty sure it works that way, but I'll double check. – slm Aug 28 '13 at 15:50
  • Not sure, but thank you in advance :-) – Exeleration-G Aug 29 '13 at 8:29
  • @Exeleration-G - see my updates. – slm Aug 29 '13 at 19:15
  • Although this sorts the podcasts on 'converting date' rather than release date, it will lead to a good file order when converting regularly. I will use this. Thank you for your extensive research on the matter. – Exeleration-G Aug 29 '13 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.