Hello, Nick!

On Thu, 2007-11-01 at 15:51 -0400, nikosapi wrote:
> I've been looking through the suggestions and an idea that didn't come
> up was a simple enumeration at the beginning or ending of directory
> and file names. For example it could look something like this:
> 
> ~/{download dir}/{number}-{<title> (cut off if too long)}/
> {number}-{show title (also cut off if too long) or original
> filename}.ext
> 
> ~/gpodder-downloads/03-This_Week_in_Tech/19-Some_random_show.mp3
> 
> The numbers could be assigned randomly (in that case a bigger number
> would be needed) or the numbers could simply be counters that gpodder
> keeps track of.
> 
> I think this would be nicer than having to descend through many oddly
> named directories to find a show you're looking for.

Your proposal sounds reasonable, and it might be something we should
think about if we are going to change the internal structure of the
download folder. Of course, we have to make a number-URL mapping and
save that somewhere so we can always find the right number to determine
the file name.

Anyway, I've been working on a compatible hard-linking system that will
preserve the download folder structure, generate a new structure that
(given it resides on the same filesystem as the download folder and it
supports hard links) will not use any additional hard disk space and is
even compatible with renames.

Save the two attached scripts somewhere in your $PATH and don't forget
to set the PYTHONPATH variable to the "src/" subfolder of your SVN
checkout, so the scripts will find the gPodder libraries.

    Usage: gdfs-init.py [--yes] [Podcasts dir]

        Populates "Podcasts dir" with hard links from gPodder's
        downloads folder. "Podcasts dir" should be on the same
        filesystem as the downloads folder, and the filesystem
        has to support hard links.

        If "Podcasts dir" already exists, the script will ask 
        to overwrite its contents and re-build the mirror.

        The optional "--yes" parameter will skip the overwrite
        question and foribly re-build the folder if it exists.

    Usage: gdfs-check.py [from-gpodder|from-podcasts] [Podcasts dir]

        If you have deleted episodes from your Podcast mirror
        folder, use "from-podcasts" to get a list of files 
        that you have to delete from gPodder's download
        folder to "sync" with your podcast mirror.

        If you have deleted episodes in gPodder, you can use
        "from-gpodder" to get a list of files that are still 
        available in your podcasts dir, but not in gPodder's
        download directory.

So, basically, to get things going, download the two scripts to your
Desktop, run "python gdfs-init.py --yes Podcasts" and you should have
your podcasts in human-readable folder and file names on your Desktop.

You can always refresh this "mirror" of your download directory by
running the same command again, which will overwrite the old "Podcasts"
folder.

Please try out these scripts and tell me how they work for you. Maybe we
can do some more integration into gPodder when things are tested and
users are happy with this solution.


Thomas
#!/usr/bin/python
#
# gPodder download folder sync (gdfs-check.py)
# Copyright 2007 Thomas Perl <[EMAIL PROTECTED]>
#
# This file is distributed under the same terms
# as the gPodder program itself (GPLv3 or later).
#

import gettext
gettext.install('')

from gpodder import libgpodder

import sys
import os
import os.path
import stat

def get_files_from( top_path):
    result = {}

    for ( dirpath, dirnames, filenames ) in os.walk( os.path.abspath( top_path)):
        for filename in ( os.path.join( dirpath, filename) for filename in filenames ):
            s = os.stat( filename)
            if stat.S_ISREG(s[stat.ST_MODE]):
                device = s[stat.ST_DEV]
                inode = s[stat.ST_INO]
                result[(device,inode)] = filename

    return result

def filter_dict( d, keys_exclude):
    result = {}

    for key, value in d.items():
        if key not in keys_exclude:
            result[key] = value

    return result

def filter_gpodder_metadata( d):
    result = {}
    for key, value in d.items():
        if not value.endswith( '/cover') and not value.endswith('/index.xml'):
            result[key] = value

    return result

def usage():
    print >> sys.stderr, """
    Usage: %s [from-gpodder|from-podcasts] [Podcasts dir]

        If you have deleted episodes from your Podcast mirror
        folder, use "from-podcasts" to get a list of files 
        that you have to delete from gPodder's download
        folder to "sync" with your podcast mirror.

        If you have deleted episodes in gPodder, you can use
        "from-gpodder" to get a list of files that are still 
        available in your podcasts dir, but not in gPodder's
        download directory.
    """ % ( os.path.basename( sys.argv[0]), )

if len(sys.argv) != 3:
    usage()
    sys.exit( -1)

files_in_dir1 = get_files_from( libgpodder.gPodderLib().downloaddir)
files_in_dir2 = get_files_from( sys.argv[-1])

files_missing_in_dir2 = filter_gpodder_metadata( filter_dict( files_in_dir1, files_in_dir2.keys())).values()
files_missing_in_dir1 = filter_gpodder_metadata( filter_dict( files_in_dir2, files_in_dir1.keys())).values()

if sys.argv[1].find( 'from-podcasts') >= 0:
    if len( files_missing_in_dir2):
        print >> sys.stderr, 'Files in gPodder that are not in %s:' % sys.argv[-1]
        for filename in files_missing_in_dir2:
            print filename
    else:
        print >> sys.stderr, 'All files in gPodder are in %s, too.' % sys.argv[-1]
elif sys.argv[1].find( 'from-gpodder') >= 0:
    if len( files_missing_in_dir1):
        print >> sys.stderr, 'Files in %s that are not in gPodder:' % sys.argv[-1]
        for filename in files_missing_in_dir1:
            print filename
    else:
        print >> sys.stderr, 'All files in %s are in gPodder, too.' % sys.argv[-1]
else:
    usage()
    print >> sys.stderr, 'Not a valid operation: "%s" (use from-podcasts or from-gpodder)' % ( sys.argv[1], )


#!/usr/bin/python
#
# gPodder download folder sync (gdfs-init.py)
# Copyright 2007 Thomas Perl <[EMAIL PROTECTED]>
#
# This file is distributed under the same terms
# as the gPodder program itself (GPLv3 or later).
#

import gettext
gettext.install('')

import gpodder.libpodcasts

import os.path
import shutil
import sys

def cb_url( url):
    print 'Loading %s...' % url

if len(sys.argv) < 2:
    print >> sys.stderr, """
    Usage: %s [--yes] [Podcasts dir]

        Populates "Podcasts dir" with hard links from gPodder's
        downloads folder. "Podcasts dir" should be on the same
        filesystem as the downloads folder, and the filesystem
        has to support hard links.

        If "Podcasts dir" already exists, the script will ask 
        to overwrite its contents and re-build the mirror.

        The optional "--yes" parameter will skip the overwrite
        question and foribly re-build the folder if it exists.
    """ % os.path.basename( sys.argv[0])
    sys.exit( -1)

dest_dir = sys.argv[-1]

if os.path.exists( dest_dir):
    if '--yes' not in sys.argv and (raw_input( '"%s" exists, remove and rebuild? [y|N] ' % ( os.path.abspath( dest_dir), )).strip().lower()+'n')[0] != 'y':
        sys.exit( -1)
    shutil.rmtree( dest_dir)

for channel in gpodder.libpodcasts.load_channels( callback_url = cb_url, offline = True):
    print channel.title
    channel_dir = os.path.join( dest_dir, os.path.basename( channel.title))

    for episode in channel.get_all_episodes():
        episode_file = os.path.join( channel_dir, os.path.basename( episode.title))
        filename = episode.local_filename()
        episode_file += os.path.splitext( os.path.basename( filename))[1]
        if os.path.exists( filename):
            if not os.path.exists( channel_dir):
                os.makedirs( channel_dir)
            os.link( filename, episode_file)
            print '     Linking: ' + episode.title

print """
    Yay, finished linking episodes :)

    You should now be able to browse and use your episodes in

       %s

    just as you would in a normal file system. When you have 
    downloaded new episodes, run this script again to rebuild
    this folder. If you delete episodes in that directory, 
    run gdfs-check.py on it to see which files you need to 
    delete inside the gPodder download directory to completely
    remove the episode from your hard disk.
""" % ( os.path.abspath( dest_dir), )

_______________________________________________
gpodder-devel mailing list
[email protected]
https://lists.berlios.de/mailman/listinfo/gpodder-devel

Reply via email to