├── 50_configure_filebot.sh ├── Dockerfile ├── LICENSE ├── README.md ├── TODO ├── build.sh ├── dpkg-excludes ├── filebot.conf ├── filebot.sh ├── monitor.sh ├── pre-run.sh └── startapp.sh /50_configure_filebot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function ts { 4 | echo [`date '+%b %d %X'`] 5 | } 6 | 7 | #----------------------------------------------------------------------------------------------------------------------- 8 | 9 | function initialize_configuration { 10 | echo "$(ts) Creating /config/filebot.conf.new" 11 | cp /files/filebot.conf /config/filebot.conf.new 12 | 13 | if [ ! -f /config/filebot.conf ] 14 | then 15 | echo "$(ts) Creating /config/filebot.conf" 16 | cp /files/filebot.conf /config/filebot.conf 17 | chmod a+w /config/filebot.conf 18 | fi 19 | 20 | # Clean up carriage returns 21 | tr -d '\r' < /config/filebot.conf > /tmp/filebot.conf 22 | mv -f /tmp/filebot.conf /config/filebot.conf 23 | 24 | # Create filebot.sh unless there is already one 25 | if [ ! -f /config/filebot.sh ] 26 | then 27 | echo "$(ts) Creating /config/filebot.sh and exiting" 28 | cp /files/filebot.sh /config/filebot.sh 29 | exit 1 30 | fi 31 | } 32 | 33 | #----------------------------------------------------------------------------------------------------------------------- 34 | 35 | function check_filebot_sh_version { 36 | USER_VERSION=$(grep '^VERSION=' /config/filebot.sh 2>/dev/null | sed 's/VERSION=//') 37 | CURRENT_VERSION=$(grep '^VERSION=' /files/filebot.sh | sed 's/VERSION=//') 38 | 39 | echo "$(ts) Comparing user's filebot.sh at version $USER_VERSION versus current version $CURRENT_VERSION" 40 | 41 | if [ -z "$USER_VERSION" ] || [ "$USER_VERSION" -lt "$CURRENT_VERSION" ] 42 | then 43 | echo "$(ts) ERROR: The container's filebot.sh is newer than the one in /config." 44 | echo "$(ts) Copying the new script to /config/filebot.sh.new." 45 | echo "$(ts) Compare your filebot.sh and filebot.sh.new. Save filebot.sh to reset its timestamp," 46 | echo "$(ts) then restart the container." 47 | cp /files/filebot.sh /config/filebot.sh.new 48 | exit 1 49 | fi 50 | } 51 | 52 | #----------------------------------------------------------------------------------------------------------------------- 53 | 54 | function create_conf_and_sh_files { 55 | # Create the config file for monitor.py 56 | cat <<"EOF" > /files/FileBot.conf 57 | if [[ -z "$INPUT_DIR" ]] 58 | then 59 | INPUT_DIR=/input 60 | fi 61 | 62 | if [[ -z "$OUTPUT_DIR" ]] 63 | then 64 | OUTPUT_DIR=/output 65 | fi 66 | 67 | EOF 68 | 69 | tr -d '\r' < /config/filebot.conf >> /files/FileBot.conf 70 | 71 | # Literal $INPUT_DIR 72 | cat <<"EOF" >> /files/FileBot.conf 73 | 74 | WATCH_DIR="$INPUT_DIR" 75 | EOF 76 | 77 | # Interpolate $USER_ID, $GROUP_ID, and $UMASK 78 | cat <> /files/FileBot.conf 79 | 80 | COMMAND="bash /files/filebot.sh" 81 | 82 | IGNORE_EVENTS_WHILE_COMMAND_IS_RUNNING=0 83 | 84 | USER_ID=$USER_ID 85 | GROUP_ID=$GROUP_ID 86 | UMASK=$UMASK 87 | EOF 88 | 89 | # Strip \r from the user-provided filebot.sh 90 | tr -d '\r' < /config/filebot.sh > /files/filebot.sh 91 | chmod a+wx /files/filebot.sh 92 | } 93 | 94 | #----------------------------------------------------------------------------------------------------------------------- 95 | 96 | function validate_configuration { 97 | . /files/FileBot.conf 98 | 99 | if [[ ! -d "$INPUT_DIR" ]]; then 100 | echo "$(ts) INPUT_DIR=$INPUT_DIR does not exist" 101 | exit 1 102 | fi 103 | 104 | if [[ ! -d "$OUTPUT_DIR" ]]; then 105 | echo "$(ts) OUTPUT_DIR=$OUTPUT_DIR does not exist" 106 | exit 1 107 | fi 108 | 109 | if find "$INPUT_DIR" -inum $(stat -c '%i' "$OUTPUT_DIR") 2>/dev/null | grep . 1>/dev/null 2>&1; then 110 | echo "$(ts) OUTPUT_DIR=$OUTPUT_DIR can not be a subdirectory of INPUT_DIR=$INPUT_DIR" 111 | exit 1 112 | fi 113 | } 114 | 115 | #----------------------------------------------------------------------------------------------------------------------- 116 | 117 | function setup_opensubtitles_account { 118 | . /files/FileBot.conf 119 | 120 | if [ "$OPENSUBTITLES_USER" != "" ]; then 121 | echo "$(ts) Configuring for OpenSubtitles user \"$OPENSUBTITLES_USER\"" 122 | echo -en "$OPENSUBTITLES_USER\n$OPENSUBTITLES_PASSWORD\n" | /files/runas.sh $USER_ID $GROUP_ID $UMASK filebot -script fn:configure 123 | else 124 | echo "$(ts) No OpenSubtitles user set. Skipping setup..." 125 | fi 126 | } 127 | 128 | #----------------------------------------------------------------------------------------------------------------------- 129 | 130 | function configure_java_prefs { 131 | . /files/FileBot.conf 132 | 133 | echo "$(ts) Creating user for ID $USER_ID and group for ID $GROUP_ID if necessary" 134 | # Running command as user "user_99_100"... 135 | runas_user=$(/files/runas.sh $USER_ID $GROUP_ID $UMASK true | grep Running | sed 's/.*"\(.*\)".*/\1/') 136 | 137 | mkdir -p /config/java_prefs /$runas_user/.java/.userPrefs/net 138 | chown -R $USER_ID:$GROUP_ID /config/java_prefs /$runas_user/.java 139 | rm -f /$runas_user/.java/.userPrefs/net/filebot 140 | echo Before creating symlink 141 | ls -al /config/java_prefs /$runas_user/.java/.userPrefs/net 142 | ln -s /config/java_prefs /$runas_user/.java/.userPrefs/net/filebot 143 | echo After creating symlink 144 | ls -al /config/java_prefs /$runas_user/.java/.userPrefs/net 145 | } 146 | 147 | #----------------------------------------------------------------------------------------------------------------------- 148 | 149 | echo "$(ts) Starting FileBot container" 150 | 151 | initialize_configuration 152 | 153 | check_filebot_sh_version 154 | 155 | create_conf_and_sh_files 156 | 157 | validate_configuration 158 | 159 | setup_opensubtitles_account 160 | 161 | configure_java_prefs 162 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM hurricane/dockergui:x11rdp 2 | #FROM hurricane/dockergui:xvnc 3 | 4 | MAINTAINER David Coppit 5 | 6 | ENV APP_NAME="Filebot" WIDTH=1280 HEIGHT=720 TERM=xterm 7 | 8 | # Use baseimage-docker's init system 9 | CMD ["/sbin/my_init"] 10 | 11 | ENV DEBIAN_FRONTEND noninteractive 12 | ADD dpkg-excludes /etc/dpkg/dpkg.cfg.d/excludes 13 | 14 | RUN true && \ 15 | 16 | # Create dir to keep things tidy. Make sure it's readable by $USER_ID 17 | mkdir /files && \ 18 | chmod a+rwX /files && \ 19 | 20 | # Speed up APT 21 | echo "force-unsafe-io" > /etc/dpkg/dpkg.cfg.d/02apt-speedup && \ 22 | echo "Acquire::http {No-Cache=True;};" > /etc/apt/apt.conf.d/no-cache && \ 23 | 24 | # Filebot requires Java 8. UI doesn't work with openjdk, so we use Oracle Java. (Gives an error when trying to rename a 25 | # file.) 26 | add-apt-repository ppa:webupd8team/java 27 | 28 | RUN true && \ 29 | 30 | # Auto-accept Oracle JDK license 31 | echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \ 32 | 33 | # Update apt and install dependencies. 34 | apt-get update && \ 35 | 36 | # Fix from https://stackoverflow.com/a/48343372/730300. Download first, let it fail, patch, then try again 37 | # See also: https://askubuntu.com/questions/998047/how-to-replace-a-faulty-java-installation-with-a-new-one 38 | ( apt-get install -qy 'oracle-java8-installer=8u161-1~webupd8~0' || true ) 39 | 40 | RUN true && \ 41 | 42 | sed -i 's|JAVA_VERSION=8u151|JAVA_VERSION=8u161|' /var/lib/dpkg/info/oracle-java8-installer.* && \ 43 | sed -i 's|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/|PARTNER_URL=http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/|' /var/lib/dpkg/info/oracle-java8-installer.* && \ 44 | sed -i 's|SHA256SUM_TGZ="c78200ce409367b296ec39be4427f020e2c585470c4eed01021feada576f027f"|SHA256SUM_TGZ="6dbc56a0e3310b69e91bb64db63a485bd7b6a8083f08e48047276380a0e2021e"|' /var/lib/dpkg/info/oracle-java8-installer.* && \ 45 | sed -i 's|J_DIR=jdk1.8.0_151|J_DIR=jdk1.8.0_161|' /var/lib/dpkg/info/oracle-java8-installer.* && \ 46 | 47 | # Install a specific version for reproducible builds. See this for supported versions: 48 | # https://launchpad.net/~webupd8team/+archive/ubuntu/java/+packages 49 | apt-get install -qy 'oracle-java8-installer=8u161-1~webupd8~0' 50 | 51 | RUN true && \ 52 | 53 | # libchromaprint-tools for fpcalc, used to compute AcoustID fingerprints for MP3s. 54 | apt-get install -qy mediainfo libchromaprint-tools && \ 55 | 56 | # I'm not sure if these are actually needed, but they suppress some Java exceptions 57 | apt-get install -qy libxslt1-dev libglapi-mesa-lts-xenial libgl1-mesa-glx-lts-xenial && \ 58 | 59 | # Install watchdog module for Python3, for monitor.py 60 | apt-get install -qy python3-setuptools && \ 61 | easy_install3 watchdog && \ 62 | 63 | # clean up 64 | apt-get clean && \ 65 | rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \ 66 | /usr/share/man /usr/share/groff /usr/share/info \ 67 | /usr/share/lintian /usr/share/linda /var/cache/man && \ 68 | (( find /usr/share/doc -depth -type f ! -name copyright|xargs rm || true )) && \ 69 | (( find /usr/share/doc -empty|xargs rmdir || true )) 70 | 71 | VOLUME ["/media", "/input", "/output", "/config"] 72 | 73 | ENV USER_ID 0 74 | ENV GROUP_ID 0 75 | ENV UMASK 0000 76 | 77 | EXPOSE 3389 8080 78 | 79 | # Set the locale, to support files that have non-ASCII characters 80 | RUN locale-gen en_US.UTF-8 81 | ENV LANG en_US.UTF-8 82 | ENV LANGUAGE en_US:en 83 | ENV LC_ALL en_US.UTF-8 84 | 85 | COPY startapp.sh / 86 | 87 | RUN true && \ 88 | 89 | # Fix guacamole errors and warnings: 90 | # SEVERE: The scratchDir you specified: /var/lib/tomcat7/work/Catalina/localhost/guacamole is unusable. 91 | # SEVERE: Cannot find specified temporary folder at /tmp/tomcat7-tomcat7-tmp 92 | # WARNING: Failed to create work directory [/var/lib/tomcat7/work/Catalina/localhost/_] for context [] 93 | mkdir -p /var/cache/tomcat7 /tmp/tomcat7-tomcat7-tmp /var/lib/tomcat7/work/Catalina/localhost && \ 94 | ln -s /var/lib/tomcat7/common /usr/share/tomcat7/common && \ 95 | ln -s /var/lib/tomcat7/server /usr/share/tomcat7/server && \ 96 | ln -s /var/lib/tomcat7/shared /usr/share/tomcat7/shared && \ 97 | 98 | # To find the latest version: https://www.filebot.net/download.php?mode=s&type=deb&arch=amd64 99 | # We'll use a specific version for reproducible builds 100 | wget --no-check-certificate -q -O /files/filebot.deb \ 101 | 'https://sourceforge.net/projects/filebot/files/filebot/FileBot_4.7.9/filebot_4.7.9_amd64.deb' && \ 102 | dpkg -i /files/filebot.deb && rm /files/filebot.deb && \ 103 | 104 | # Otherwise RDP rendering of the UI doesn't work right. 105 | sed -i 's/java /java -Dsun.java2d.xrender=false /' /usr/bin/filebot && \ 106 | 107 | # Revision-lock to a specific version to avoid any surprises. 108 | wget --no-check-certificate -q -O /files/runas.sh \ 109 | 'https://raw.githubusercontent.com/coppit/docker-inotify-command/1d4b941873b670525fd159dcb9c01bb2570b0565/runas.sh' && \ 110 | chmod +x /files/runas.sh && \ 111 | wget --no-check-certificate -q -O /files/monitor.py \ 112 | 'https://raw.githubusercontent.com/coppit/docker-inotify-command/c9e9c8b980d3a5ba4abfe7c1b069f684a56be6d2/monitor.py' && \ 113 | chmod +x /files/monitor.py 114 | 115 | # Add scripts. Make sure everything is executable by $USER_ID 116 | COPY pre-run.sh filebot.sh filebot.conf /files/ 117 | RUN chmod a+x /files/pre-run.sh 118 | RUN chmod a+w /files/filebot.conf 119 | 120 | ADD 50_configure_filebot.sh /etc/my_init.d/ 121 | 122 | RUN mkdir /etc/service/filebot 123 | ADD monitor.sh /etc/service/filebot/run 124 | RUN chmod +x /etc/service/filebot/run 125 | 126 | RUN mkdir /etc/service/filebot-ui 127 | ADD startapp.sh /etc/service/filebot-ui/run 128 | RUN chmod +x /etc/service/filebot-ui/run 129 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc., 5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Lesser General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | {description} 294 | Copyright (C) {year} {fullname} 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License along 307 | with this program; if not, write to the Free Software Foundation, Inc., 308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 309 | 310 | Also add information on how to contact you by electronic and paper mail. 311 | 312 | If the program is interactive, make it output a short notice like this 313 | when it starts in an interactive mode: 314 | 315 | Gnomovision version 69, Copyright (C) year name of author 316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 317 | This is free software, and you are welcome to redistribute it 318 | under certain conditions; type `show c' for details. 319 | 320 | The hypothetical commands `show w' and `show c' should show the appropriate 321 | parts of the General Public License. Of course, the commands you use may 322 | be called something other than `show w' and `show c'; they could even be 323 | mouse-clicks or menu items--whatever suits your program. 324 | 325 | You should also get your employer (if you work as a programmer) or your 326 | school, if any, to sign a "copyright disclaimer" for the program, if 327 | necessary. Here is a sample; alter the names: 328 | 329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 330 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 331 | 332 | {signature of Ty Coon}, 1 April 1989 333 | Ty Coon, President of Vice 334 | 335 | This General Public License does not permit incorporating your program into 336 | proprietary programs. If your program is a subroutine library, you may 337 | consider it more useful to permit linking proprietary applications with the 338 | library. If this is what you want to do, use the GNU Lesser General 339 | Public License instead of this License. 340 | 341 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-filebot 2 | 3 | This is a Docker container for running [FileBot](http://www.filebot.net/), a media file organizer. The container has both a user interface as well as a fully automated mode. The GUI is exposed via RDP and HTTP. For the automated version, you just drop files into the input directory, and they'll be cleaned up and moved to the output directory. 4 | 5 | This docker image is available [on Docker Hub](https://hub.docker.com/r/coppit/filebot/). 6 | 7 | ## Usage 8 | 9 | ### Interactive Method 10 | 11 | To use this container for a user interface to FileBot: 12 | 13 | `docker run --name=FileBotUI -e WIDTH=1280 -e HEIGHT=720 -p 3389:3389 -p 8080:8080 -v /media/dir/path:/media:rw -v /config/dir/path:/config:rw coppit/filebot` 14 | 15 | In this mode, point the UI at the /media folder, which is shared with the host. 16 | 17 | There are two ways to use the interactive user interface. One is to connect to the UI in your web browser with the URL http://host:8080/#/client/c/HandBrake. The second is to connect with a remote desktop client using port 3389. There are RDP clients for multiple platforms: 18 | 19 | * Microsoft Remote Desktop for Windows (built into the OS) 20 | * [Microsoft Remote Desktop for OS X](https://itunes.apple.com/us/app/microsoft-remote-desktop/id715768417?mt=12) 21 | * [rdesktop for Linux](http://www.rdesktop.org/) 22 | 23 | The second method is to point your web browser to http://:8080/. This will launch a web browser-based user interface. 24 | 25 | Of course, if you change the host ports, then when you connect you'll have to specify the server as `:`. Feel free to drop the 3389 mapping if you don't plan to use RDP, or the 8080 mapping if you don't plan to use the web browser. 26 | 27 | ### Non-Interactive Method 28 | 29 | If you want to run the container without a UI: 30 | 31 | `docker run --name=FileBot -d -v /input/dir/path:/input:rw -v /output/dir/path:/output:rw -v /config/dir/path:/config:rw coppit/filebot` 32 | 33 | With the default configuration, files written to the input directory will be renamed and copied to the output directory. It is recommended that you do **not** overlap your input and output directories. FileBot will end up re-processing files that it already processed, and generally make a mess of things. 34 | 35 | Note that the /input path is writable above. This is because subtitles are first downloaded into the input directory before being moved to the output directory. Some people also prefer to move instead of renaming files. If you are paranoid about FileBot messing with your input files, and don't care about downloading subtitles, you can make /input read-only by removing ":rw". 36 | 37 | When the container detects a change to the input directory, it will wait up to 60 seconds for changes to stop for 5 seconds. FileBot will be run if the directory stabilizes for 5 seconds, or if the 60 second maximum wait time elapses. 38 | 39 | To check the status of the container, run: 40 | 41 | `docker logs FileBot` 42 | 43 | ### Both Methods 44 | 45 | You can also combine all of the flags into one big command, to support both the UI as well as the automated conversion. 46 | 47 | `docker run --name=FileBot -e WIDTH=1280 -e HEIGHT=720 -p 3389:3389 -p 8080:8080 -v /media/dir/path:/media:rw -v /input/dir/path:/input:rw -v /output/dir/path:/output:rw -v /config/dir/path:/config:rw coppit/filebot` 48 | 49 | Just be careful not to use the /input directory with the UI. Otherwise you'll be triggering the automated update. 50 | 51 | ## Configuration 52 | 53 | When run for the first time, a config file named `filebot.conf` will be created in the config dir. (If you are upgrading from an old version, compare your existing `filebot.conf` against `filebot.conf.new` instead.) If you wish to download subtitles, edit the config file to set the username and password, as well as the language. 54 | 55 | When run for the first time, a script named `filebot.sh` will be created in the config dir, and the container will exit. Edit this file, customizing how you want FileBot to run. For example, you might want to change the file rename formatting. Then restart the container. 56 | 57 | While editing and testing your filebot.sh, keep in mind that FileBot (actually AMC) will not re-process files. Delete amc-exclude-list.txt in your config directory, then write a file into the input directory to get FileBot to re-process your files. 58 | 59 | After you gain confidence in how the container is running, you may want to change the action from "copy" to "move". FileBot will move the files from the input to the output directory, then clean up any "leftover junk" in the input directory. If you're going to do this, then it's also probably a good idea to store temporary files and incomplete downloads in a different directory than the input directory, just in case FileBot decides to move them. 60 | 61 | By default, FileBot will create files using user ID 0 (typically root) and group ID 0 (typically root), and with a umask of 0022. If you wish to change this, set the `USER_ID`, `GROUP_ID`, and `UMASK` environment variables to the right values from your host system. You can find the IDs using the "id" command. For example, for the user "nobody", it would be `id -u nobody` and `id -g nobody`. You can get the umask for a user like "nobody" by running `su -l nobody -c umask`. 62 | 63 | The `ALLOW_REPROCESSING` setting controls whether FileBot can reprocess a file if it is created again in the input directory. You should delete amc-exclude-list.txt in your config directory if you enable this for the first time. Note that filebot will refuse to reprocess an input file if the output file already exists. 64 | 65 | The `USE_UI` setting controls whether the user interface features are enabled. Set this to "yes" to enable the UI, which uses approximately 460MB of RAM, as opposed to 20MB of RAM. On my machine it uses .33% CPU instead of .03% CPU. 66 | 67 | ### Updates to filebot.sh 68 | 69 | Later, when you update the container, it may exit with this message in the log: 70 | 71 | > ERROR: The container's filebot.sh is newer than the one in /config. 72 | > Copying the new script to /config/filebot.sh.new. 73 | > Compare your filebot.sh and filebot.sh.new, being sure to copy over the VERSION line. 74 | > Then restart the container. 75 | 76 | This happens because some bugfix or something went into `filebot.sh`. Rather than deleting your `filebot.sh` (and losing any hard work you put into it), the container will write `filebot.sh.new`. It's your job to merge the two files. You can delete `filebot.sh`.new when you're done. NOTE: You must increase the VERSION even if you make no other changes. This will let the container know that you performed the merge. It will then start normally. 77 | 78 | ## Advanced Configuration when Moving Files in FileBot 79 | 80 | When using the non-interactive method, combined with FileBot's option to move instead of copy files, the moves can be slow if the container is configured with separate /input and /output directories. In this case, you can configure the container to operate on a single mounted volume. First, mount only the /media path: 81 | 82 | `docker run --name=FileBot -d -v /media/dir/path:/media:rw -v /config/dir/path:/config:rw coppit/filebot` 83 | 84 | Then, specify the `INPUT_DIR` and `OUTPUT_DIR` variables in your filebot.conf as subfolders of /media. Make sure that your output is not a subfolder of your input, or you'll confuse the change monitor. 85 | 86 | ## Known Limitations 87 | 88 | This container uses the inotify interface for watching for file system changes. This only works for kernel-supported file systems. It won't work for network shares. 89 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | - Swap out inotify for a more robust notification mechanism that supports polling, such as https://github.com/guard/listen 2 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | docker build --rm=true -t coppit/filebot . 4 | 5 | # Final test before pushing: 6 | #docker build --no-cache=true -t coppit/filebot:dev . 7 | 8 | -------------------------------------------------------------------------------- /dpkg-excludes: -------------------------------------------------------------------------------- 1 | path-exclude /usr/share/doc/* 2 | # we need to keep copyright files for legal reasons 3 | path-include /usr/share/doc/*/copyright 4 | path-exclude /usr/share/man/* 5 | path-exclude /usr/share/groff/* 6 | path-exclude /usr/share/info/* 7 | # lintian stuff is small, but really unnecessary 8 | path-exclude /usr/share/lintian/* 9 | path-exclude /usr/share/linda/* 10 | # Drop locales except English 11 | path-exclude=/usr/share/locale/* 12 | path-include=/usr/share/locale/en/* 13 | path-include=/usr/share/locale/locale.alias 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /filebot.conf: -------------------------------------------------------------------------------- 1 | # If we don't see any events for $SETTLE_DURATION time, assume that it's safe to run FileBot. Format is HH:MM:SS, 2 | # with HH and MM optional. 3 | SETTLE_DURATION=10 4 | 5 | # However, if we see a stream of changes for longer than $MAX_WAIT_TIME with no break of $SETTLE_DURATION or more, then 6 | # go ahead and run FileBot. Otherwise we might be waiting forever for the directory to stop changing. Format is 7 | # HH:MM:SS, with HH and MM optional. 8 | MAX_WAIT_TIME=01:00 9 | 10 | # After running FileBot, wait at least this long before running it again, even if $SETTLE_DURATION time has passed 11 | # after change. This controls the maximum frequency of FileBot. 12 | MIN_PERIOD=05:00 13 | 14 | # Set this to 1 to log all events, for debugging purposes. WARNING! This creates copious amounts of confusing logging! 15 | DEBUG=0 16 | 17 | # Create an account at http://www.opensubtitles.org/ if you want to download subtitles 18 | OPENSUBTITLES_USER="" 19 | OPENSUBTITLES_PASSWORD="" 20 | 21 | # Set this to a language code if you want to download subtitles. e.g. Use "en" for english 22 | SUBTITLE_LANG="" 23 | 24 | # By default, the container monitors /input and writes files to /output. Use this option if you are mounting /media 25 | # instead. See the documentation for more information. 26 | #INPUT_DIR=/media/input 27 | #OUTPUT_DIR=/media/output 28 | 29 | # Allow FileBot to process a file if the file is created or modified in the input directory, even if FileBot processed 30 | # the file before. Setting this to "no" causes FileBot to remember the file forever. 31 | ALLOW_REPROCESSING=yes 32 | 33 | # Run the UI in addition to the normal non-interactive behavior. The UI uses about 460MB of RAM, as opposed to about 34 | # 20MB of RAM. On my machine it uses .33% CPU instead of .03% CPU. 35 | RUN_UI=no 36 | -------------------------------------------------------------------------------- /filebot.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script by default uses "Automated Media Center" (AMC). See the final filebot call below. For more docs on AMC, 4 | # visit: http://www.filebot.net/forums/viewtopic.php?t=215 5 | 6 | #----------------------------------------------------------------------------------------------------------------------- 7 | 8 | # Specify the URLs of any scripts that you need. They will be downloaded into /config/scripts 9 | SCRIPTS_TO_DOWNLOAD=( 10 | # Example: 11 | # https://raw.githubusercontent.com/filebot/scripts/devel/cleaner.groovy 12 | ) 13 | 14 | #----------------------------------------------------------------------------------------------------------------------- 15 | 16 | QUOTE_FIXER='replaceAll(/[\`\u00b4\u2018\u2019\u02bb]/, "'"'"'").replaceAll(/[\u201c\u201d]/, '"'"'""'"'"')' 17 | 18 | # Customize the renaming format here. For info on formatting: https://www.filebot.net/naming.html 19 | 20 | # Music/Eric Clapton/From the Cradle/05 - It Hurts Me Too.mp3 21 | MUSIC_FORMAT="Music/{n.$QUOTE_FIXER}/{album.$QUOTE_FIXER}/{media.TrackPosition.pad(2)} - {t.$QUOTE_FIXER}" 22 | 23 | # Movies/Fight Club.mkv 24 | MOVIE_FORMAT="Movies/{n.$QUOTE_FIXER} {' CD'+pi}" 25 | 26 | # TV Shows/Game of Thrones/Season 05/Game of Thrones - S05E08 - Hardhome.mp4 27 | # TV Shows/Game of Thrones/Special/Game of Thrones - S00E11 - A Day in the Life.mp4 28 | SERIES_FORMAT="TV Shows/{n}/{episode.special ? 'Special' : 'Season '+s.pad(2)}/{n} - {episode.special ? 'S00E'+special.pad(2) : s00e00} - {t.${QUOTE_FIXER}.replaceAll(/[!?.]+$/).replacePart(', Part $1')}{'.'+lang}" 29 | 30 | . /files/FileBot.conf 31 | 32 | if [ "$SUBTITLE_LANG" == "" ];then 33 | SUBTITLE_OPTION="" 34 | else 35 | SUBTITLE_OPTION="subtitles=$SUBTITLE_LANG" 36 | fi 37 | 38 | #----------------------------------------------------------------------------------------------------------------------- 39 | 40 | # Used to detect old versions of this script 41 | VERSION=5 42 | 43 | # Download scripts and such. 44 | . /files/pre-run.sh 45 | 46 | # See http://www.filebot.net/forums/viewtopic.php?t=215 for details on amc 47 | filebot -script fn:amc -no-xattr --output "$OUTPUT_DIR" --log-file /files/amc.log --action copy --conflict auto \ 48 | -non-strict --def ut_dir="$INPUT_DIR" ut_kind=multi music=y deleteAfterExtract=y clean=y \ 49 | excludeList=/config/amc-exclude-list.txt $SUBTITLE_OPTION \ 50 | movieFormat="$MOVIE_FORMAT" musicFormat="$MUSIC_FORMAT" seriesFormat="$SERIES_FORMAT" 51 | 52 | if [ "$ALLOW_REPROCESSING" = "yes" ]; then 53 | tempfile=$(mktemp) 54 | # FileBot only puts files that it can process into the amc-exclude-list.txt file. e.g. jpg files are not in there. So 55 | # take the intersection of the existing files and the ones in the list. 56 | comm -12 <(sort /config/amc-exclude-list.txt) <(find /input | sort) > $tempfile 57 | mv -f $tempfile /config/amc-exclude-list.txt 58 | fi 59 | -------------------------------------------------------------------------------- /monitor.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . /files/FileBot.conf 4 | 5 | function ts { 6 | echo [`date '+%b %d %X'`] 7 | } 8 | 9 | #----------------------------------------------------------------------------------------------------------------------- 10 | 11 | # Run once at the start 12 | echo "$(ts) Running FileBot auto-renamer on startup" 13 | /files/runas.sh $USER_ID $GROUP_ID $UMASK /files/filebot.sh 14 | 15 | # Start monitoring 16 | /files/monitor.py /files/FileBot.conf 17 | -------------------------------------------------------------------------------- /pre-run.sh: -------------------------------------------------------------------------------- 1 | # Download any scripts 2 | for SCRIPT_TO_DOWNLOAD in ${SCRIPTS_TO_DOWNLOAD[@]} 3 | do 4 | FILENAME=/config/scripts/${SCRIPT_TO_DOWNLOAD##*/} 5 | 6 | # Sadly, github doesn't supply a Last-Modified header, so wget -N can't be used. So let's instead only pull down new 7 | # versions once a day 8 | if ! test "`find $FILENAME -mtime -1 2>/dev/null`" 9 | then 10 | echo Downloading $FILENAME 11 | wget -q -O $FILENAME $SCRIPT_TO_DOWNLOAD 12 | fi 13 | done 14 | 15 | # Avoid a Java encoding error 16 | export LC_ALL="en_US.UTF-8" 17 | 18 | -------------------------------------------------------------------------------- /startapp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | . /files/FileBot.conf 4 | 5 | function ts { 6 | echo [`date '+%b %d %X'`] 7 | } 8 | 9 | #----------------------------------------------------------------------------------------------------------------------- 10 | 11 | export DISPLAY=:1 12 | 13 | if [ "$RUN_UI" == "yes" ] 14 | then 15 | echo "$(ts) Running FileBot GUI" 16 | /files/runas.sh $USER_ID $GROUP_ID $UMASK filebot 17 | else 18 | echo "$(ts) Not running FileBot GUI" 19 | sv stop guacd tomcat7 filebot-ui X11rdp xrdp xrdp-sesman openbox 20 | fi 21 | --------------------------------------------------------------------------------