def test_title_increment(self):
        fn = get_filename_handler("title_increment")
        # Ensure increment on same title
        self.assertEqual(fn(self._pset, self._photo, self._suffix), "Some Photo.jpg")
        self.assertEqual(fn(self._pset, self._photo, self._suffix), "Some Photo(1).jpg")

        # Ensure no increment on different title
        photo2 = AttrDict({"title": "Some Other Photo", "id": 124})
        self.assertEqual(fn(self._pset, photo2, self._suffix), "Some Other Photo.jpg")

        # Ensure no increment on same title, but different set
        pset2 = AttrDict({"title": "Some Other Set", "id": 1000})
        self.assertEqual(fn(pset2, self._photo, self._suffix), "Some Photo.jpg")
Пример #2
0
    def test_title_increment(self):
        fn = get_filename_handler('title_increment')
        # Ensure increment on same title
        self.assertEqual(fn(self._pset, self._photo, self._suffix),
                         'Some Photo')
        self.assertEqual(fn(self._pset, self._photo, self._suffix),
                         'Some Photo(1)')

        # Ensure no increment on different title
        photo2 = AttrDict({'title': 'Some Other Photo', 'id': 124})
        self.assertEqual(fn(self._pset, photo2, self._suffix),
                         'Some Other Photo')

        # Ensure no increment on same title, but different set
        pset2 = AttrDict({'title': 'Some Other Set', 'id': 1000})
        self.assertEqual(fn(pset2, self._photo, self._suffix), 'Some Photo')
Пример #3
0
    def test_title_increment(self):
        fn = get_filename_handler('title_increment')
        # Ensure increment on same title
        self.assertEqual(fn(self._pset, self._photo, self._suffix),
                         'Some Photo')
        self.assertEqual(fn(self._pset, self._photo, self._suffix),
                         'Some Photo(1)')

        # Ensure no increment on different title
        photo2 = AttrDict({'title': 'Some Other Photo', 'id': 124})
        self.assertEqual(fn(self._pset, photo2, self._suffix),
                         'Some Other Photo')

        # Ensure no increment on same title, but different set
        pset2 = AttrDict({'title': 'Some Other Set', 'id': 1000})
        self.assertEqual(fn(pset2, self._photo, self._suffix),
                         'Some Photo')
Пример #4
0
def main():
    parser = argparse.ArgumentParser('Download a Flickr Set')
    parser.add_argument('-k', '--api_key', type=str,
                        help='Flickr API key')
    parser.add_argument('-s', '--api_secret', type=str,
                        help='Flickr API secret')
    parser.add_argument('-t', '--user_auth', action='store_true',
                        help='Enable user authentication')
    parser.add_argument('-l', '--list', type=str, metavar='USER',
                        help='List photosets for a user')
    parser.add_argument('-d', '--download', type=str, metavar='SET_ID',
                        help='Download the given set')
    parser.add_argument('-u', '--download_user', type=str, metavar='USERNAME',
                        help='Download all sets for a given user')
    parser.add_argument('-q', '--quality', type=str, metavar='SIZE_LABEL',
                        default=None, help='Quality of the picture')
    parser.add_argument('-n', '--naming', type=str, metavar='NAMING_MODE',
                        default='title', help='Photo naming mode')
    parser.set_defaults(**_load_defaults())

    args = parser.parse_args()

    if not args.api_key or not args.api_secret:
        print ('You need to pass in both "api_key" and "api_secret" arguments', file=sys.stderr)
        return 1

    ret = _init(args.api_key, args.api_secret, args.user_auth)
    if not ret:
        return 1

    if args.list:
        print_sets(args.list)
    elif args.download or args.download_user:
        try:
            get_filename = get_filename_handler(args.naming)
            if args.download:
                download_set(args.download, get_filename, args.quality)
            else:
                download_user(args.download_user, get_filename, args.quality)
        except KeyboardInterrupt:
            print('Forcefully aborting. Last photo download might be partial :(', file=sys.stderr)
    else:
        print('ERROR: Must pass either --list or --download\n', file=sys.stderr)
        parser.print_help()
        return 1
 def test_title_increment_empty_title(self):
     photo = AttrDict({"title": "", "id": 175})
     fn = get_filename_handler("title_increment")
     self.assertEqual(fn(self._pset, photo, self._suffix), "175.jpg")
 def test_id(self):
     fn = get_filename_handler("id")
     self.assertEqual(fn(self._pset, self._photo, self._suffix), "123.jpg")
 def test_title_and_id_empty_title(self):
     photo = AttrDict({"title": "", "id": 1389})
     fn = get_filename_handler("title_and_id")
     self.assertEqual(fn(self._pset, photo, self._suffix), "1389.jpg")
 def test_title_and_id(self):
     fn = get_filename_handler("title_and_id")
     self.assertEqual(fn(self._pset, self._photo, self._suffix), "Some Photo-123.jpg")
Пример #9
0
 def test_title_increment_empty_title(self):
     photo = AttrDict({'title': '', 'id': 175})
     fn = get_filename_handler('title_increment')
     self.assertEqual(fn(self._pset, photo, self._suffix),
                      '175')
Пример #10
0
 def test_title_and_id_empty_title(self):
     photo = AttrDict({'title': '', 'id': 1389})
     fn = get_filename_handler('title_and_id')
     self.assertEqual(fn(self._pset, photo, self._suffix), '1389')
Пример #11
0
 def test_id(self):
     fn = get_filename_handler('id')
     self.assertEqual(fn(self._pset, self._photo, self._suffix),
                      '123')
Пример #12
0
 def test_title_and_id_empty_title(self):
     photo = AttrDict({'title': '', 'id': 1389})
     fn = get_filename_handler('title_and_id')
     self.assertEqual(fn(self._pset, photo, self._suffix),
                      '1389')
Пример #13
0
 def test_title_and_id(self):
     fn = get_filename_handler('title_and_id')
     self.assertEqual(fn(self._pset, self._photo, self._suffix),
                      'Some Photo-123')
Пример #14
0
 def test_title_increment_empty_title(self):
     photo = AttrDict({'title': '', 'id': 175})
     fn = get_filename_handler('title_increment')
     self.assertEqual(fn(self._pset, photo, self._suffix), '175')
Пример #15
0
 def test_id(self):
     fn = get_filename_handler('id')
     self.assertEqual(fn(self._pset, self._photo, self._suffix), '123')
Пример #16
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        description='Downloads one or more Flickr photo sets.\n'
        '\n'
        'To use it you need to get your own Flickr API key here:\n'
        'https://www.flickr.com/services/api/misc.api_keys.html\n'
        '\n'
        'For more information see:\n'
        'https://github.com/beaufour/flickr-download',
        epilog='examples:\n'
        '  list all sets for a user:\n'
        '  > {app} -k <api_key> -s <api_secret> -l beaufour\n'
        '\n'
        '  download a given set:\n'
        '  > {app} -k <api_key> -s <api_secret> -d 72157622764287329\n'
        '\n'
        '  download a given set, keeping duplicate names:\n'
        '  > {app} -k <api_key> -s <api_secret> -d 72157622764287329 -n title_increment\n'
        .format(app=sys.argv[0])
    )
    parser.add_argument('-k', '--api_key', type=str,
                        help='Flickr API key')
    parser.add_argument('-s', '--api_secret', type=str,
                        help='Flickr API secret')
    parser.add_argument('-t', '--user_auth', action='store_true',
                        help='Enable user authentication')
    parser.add_argument('-l', '--list', type=str, metavar='USER',
                        help='List photosets for a user')
    parser.add_argument('-d', '--download', type=str, metavar='SET_ID',
                        help='Download the given set')
    parser.add_argument('-u', '--download_user', type=str, metavar='USERNAME',
                        help='Download all sets for a given user')
    parser.add_argument('-q', '--quality', type=str, metavar='SIZE_LABEL',
                        default=None, help='Quality of the picture')
    parser.add_argument('-n', '--naming', type=str, metavar='NAMING_MODE',
                        help='Photo naming mode')
    parser.add_argument('-m', '--list_naming', action='store_true',
                        help='List naming modes')
    parser.set_defaults(**_load_defaults())

    args = parser.parse_args()

    if args.list_naming:
        print(get_filename_handler_help())
        return 1

    if not args.api_key or not args.api_secret:
        print ('You need to pass in both "api_key" and "api_secret" arguments', file=sys.stderr)
        return 1

    ret = _init(args.api_key, args.api_secret, args.user_auth)
    if not ret:
        return 1

    if args.list:
        print_sets(args.list)
        return 0

    if args.download or args.download_user:
        try:
            get_filename = get_filename_handler(args.naming)
            if args.download:
                download_set(args.download, get_filename, args.quality)
            else:
                download_user(args.download_user, get_filename, args.quality)
        except KeyboardInterrupt:
            print('Forcefully aborting. Last photo download might be partial :(', file=sys.stderr)
        return 0

    print('ERROR: Must pass either --list or --download\n', file=sys.stderr)
    parser.print_help()
    return 1
Пример #17
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawTextHelpFormatter,
        description='Downloads one or more Flickr photo sets.\n'
        '\n'
        'To use it you need to get your own Flickr API key here:\n'
        'https://www.flickr.com/services/api/misc.api_keys.html\n'
        '\n'
        'For more information see:\n'
        'https://github.com/beaufour/flickr-download\n'
        '\n'
        'You can store argument defaults in ' + CONFIG_FILE + '. API keys for example:\n'
        '  api_key: .....\n'
        '  api_secret: ...\n',
        epilog='examples:\n'
        '  list all sets for a user:\n'
        '  > {app} -k <api_key> -s <api_secret> -l beaufour\n'
        '\n'
        '  download a given set:\n'
        '  > {app} -k <api_key> -s <api_secret> -d 72157622764287329\n'
        '\n'
        '  download a given set, keeping duplicate names:\n'
        '  > {app} -k <api_key> -s <api_secret> -d 72157622764287329 -n title_increment\n'
        .format(app=sys.argv[0])
    )
    parser.add_argument('-k', '--api_key', type=str,
                        help='Flickr API key')
    parser.add_argument('-s', '--api_secret', type=str,
                        help='Flickr API secret')
    parser.add_argument('-t', '--user_auth', action='store_true',
                        help='Enable user authentication')
    parser.add_argument('-l', '--list', type=str, metavar='USER',
                        help='List photosets for a user')
    parser.add_argument('-d', '--download', type=str, metavar='SET_ID',
                        help='Download the given set')
    parser.add_argument('-p', '--download_user_photos', type=str, metavar='USERNAME',
                        help='Download all photos for a given user')
    parser.add_argument('-u', '--download_user', type=str, metavar='USERNAME',
                        help='Download all sets for a given user')
    parser.add_argument('-i', '--download_photo', type=str, metavar='PHOTO_ID',
                        help='Download one specific photo')
    parser.add_argument('-q', '--quality', type=str, metavar='SIZE_LABEL',
                        default=None, help='Quality of the picture')
    parser.add_argument('-n', '--naming', type=str, metavar='NAMING_MODE',
                        help='Photo naming mode')
    parser.add_argument('-m', '--list_naming', action='store_true',
                        help='List naming modes')
    parser.add_argument('-o', '--skip_download', action='store_true',
                        help='Skip the actual download of the photo')
    parser.add_argument('-j', '--save_json', action='store_true',
                        help='Save photo info like description and tags, one .json file per photo')
    parser.set_defaults(**_load_defaults())

    args = parser.parse_args()

    if args.list_naming:
        print(get_filename_handler_help())
        return 1

    if not args.api_key or not args.api_secret:
        print ('You need to pass in both "api_key" and "api_secret" arguments', file=sys.stderr)
        return 1

    ret = _init(args.api_key, args.api_secret, args.user_auth)
    if not ret:
        return 1

    # Replace stdout with a non-strict writer that replaces unknown characters instead of throwing
    # an exception. This "fixes" print issues on the standard Windows terminal, and when there is no
    # terminal at all.
    if sys.stdout.isatty():
        default_encoding = sys.stdout.encoding
    else:
        default_encoding = locale.getpreferredencoding()
    if default_encoding != 'utf-8':
        sys.stdout = codecs.getwriter(default_encoding)(sys.stdout, 'replace')

    if args.list:
        print_sets(args.list)
        return 0

    if args.skip_download:
        print('Will skip actual downloading of files')

    if args.save_json:
        print('Will save photo info in .json file with same basename as photo')

    if args.download or args.download_user or args.download_user_photos or args.download_photo:
        try:
            with Timer('total run'):
                get_filename = get_filename_handler(args.naming)
                if args.download:
                    download_set(args.download, get_filename, args.quality, args.skip_download,
                                 args.save_json)
                elif args.download_user:
                    download_user(args.download_user, get_filename, args.quality,
                                  args.skip_download, args.save_json)
                elif args.download_photo:
                    download_photo(args.download_photo, get_filename, args.quality,
                                   args.skip_download, args.save_json)
                else:
                    download_user_photos(args.download_user_photos, get_filename, args.quality,
                                         args.skip_download, args.save_json)
        except KeyboardInterrupt:
            print('Forcefully aborting. Last photo download might be partial :(', file=sys.stderr)
        return 0

    print('ERROR: Must pass either --list or --download\n', file=sys.stderr)
    parser.print_help()
    return 1
Пример #18
0
 def test_title_and_id(self):
     fn = get_filename_handler('title_and_id')
     self.assertEqual(fn(self._pset, self._photo, self._suffix),
                      'Some Photo-123')