Class Mover

java.lang.Object
io.github.mastodonContentMover.Mover

public class Mover extends Object
Bootstraps application, parses command-line parameters, determines which function was requested by the user, and then performs that function.

Currently two functions are available: save, to download and save statuses for a given user account on a specified Mastodon instance to an XML-based archive on the local machine, and post, to repost them to a user account on a Mastodon instance.

At a high level, saving to an archive does the following:
  1. Parses and validates command-line parameters
  2. Connects to the specified user account and Mastodon instance (obtaining client and user authorization where necessary, and saving the relevant credentials to file for future use)
  3. Downloads the Mastodon statuses from that user's own timeline in a series of pages (backwards from the most recent), which obtains much status data but does not include the unformatted StatusSource text needed to repost the status elsewhere, nor does it include media files.
  4. Works back through the downloaded statuses (to download the StatusSource and media files for each status, and to identify any self-thread relationships that need to be preserved) and saves them as a Post to a PostArchive named according to the archiveName parameter (which holds this data in memory and also persists it to a set of XML files, using JAXB, on the local filesystem within a directory named to match the name of the archive).
Posting from an archive does the following:
  1. Parses and validates command-line parameters
  2. Connects to the specified user account and Mastodon instance (obtaining client and user authorization where necessary and saving the relevant credentials to file for future use)
  3. Populates a PostArchive by loading the data for its Post objects from the set of XML files on the local filesystem.
  4. Iterates through the archive, uploading any media attached to each Post to the specified Mastodon instance, removing meaningful symbols such as the at-mark for mentions or hashtag that would trigger spurious notifications from the text, and then submitting it as a new status (and as a reply to a previously reposted status where it is part of a self-thread).
  5. Re-bookmarks or re-pins reposted statuses that were bookmarked or pinned by the saving user when the archive was created, and where this is specified
To prevent a deluge of API requests to Mastodon instances, all current default API rate limits are honoured conservatively, with a small additional delay. It is also possible to increase this delay using a command-line parameter.

The main, required command-line options are as follows:
  • either save or post
  • -username
  • -instance
  • -archiveName
Additional, optional command-line options that are currently implemented are as follows:
  • -showdebug
  • -preserveHashtags
  • -bookmarkedOnly
  • -from (only when using post)
  • -until (only when using post)
  • -extraThrottle
  • -customPort


Since:
0.01.00
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected static boolean
    Confirms whether the application's data directory exists at the location specified by the DATA_DIRECTORY constant, and tries to create it if it does not.
    protected static String
    Provides the location of the application's data directory, currently as specified by the DATA_DIRECTORY constant.
    protected static String
    Provides the prefix used when debug messages are printed to the console, as specified by the DEBUG_PREFIX constant.
    protected static String
    Provides the prefix used when error messages are printed to the console, as specified by the ERROR_MESSAGE_PREFIX constant.
    static void
    main(String[] args)
    Initializes application, accepting command-line parameters, calling parseParameters to parse them into global variables and then calling the requested procedure accordingly.
    protected static boolean
    Indicates whether debug messages should be printed to the console, according to whether that option was specified as a parameter when the application was run.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Mover

      public Mover()
  • Method Details

    • main

      public static void main(String[] args)
      Initializes application, accepting command-line parameters, calling parseParameters to parse them into global variables and then calling the requested procedure accordingly.

      Parameters:
      args - space-delimited command line parameters as a primitive array of String objects

      Since:
      0.01.00
    • getDataDirectory

      protected static String getDataDirectory()
      Provides the location of the application's data directory, currently as specified by the DATA_DIRECTORY constant.

      Returns:
      the folder name within the working directory that is used to store all the application's data

      Since:
      0.01.00
    • checkDataDirectoryExists

      protected static boolean checkDataDirectoryExists()
      Confirms whether the application's data directory exists at the location specified by the DATA_DIRECTORY constant, and tries to create it if it does not.

      Returns:
      true if the directory exists or was successfully created, or false otherwise

      Since:
      0.01.00
    • showDebug

      protected static boolean showDebug()
      Indicates whether debug messages should be printed to the console, according to whether that option was specified as a parameter when the application was run.

      Returns:
      true if debug messages should be printed to the console, or false otherwise

      Since:
      0.01.00
    • getDebugPrefix

      protected static String getDebugPrefix()
      Provides the prefix used when debug messages are printed to the console, as specified by the DEBUG_PREFIX constant.

      Returns:
      the prefix used when debug messages are printed to the console

      Since:
      0.01.00
    • getErrorMessagePrefix

      protected static String getErrorMessagePrefix()
      Provides the prefix used when error messages are printed to the console, as specified by the ERROR_MESSAGE_PREFIX constant.

      Do not use this to prefix the messages attached to thrown exceptions, or the prefix will be displayed twice.

      Returns:
      the prefix used when error messages are printed to the console

      Since:
      0.01.00