├── MANIFEST ├── t └── pod.t ├── RELEASE.txt ├── Makefile.PL ├── README.md ├── LICENSE.txt └── gloc /MANIFEST: -------------------------------------------------------------------------------- 1 | gloc 2 | LICENSE.txt 3 | Makefile.PL 4 | MANIFEST This list of files 5 | README.md 6 | RELEASE.txt 7 | t/pod.t 8 | -------------------------------------------------------------------------------- /t/pod.t: -------------------------------------------------------------------------------- 1 | #!perl -T 2 | use 5.006; 3 | use strict; 4 | use warnings FATAL => 'all'; 5 | use Test::More; 6 | 7 | # Ensure a recent version of Test::Pod 8 | my $min_tp = 1.22; 9 | eval "use Test::Pod $min_tp"; 10 | plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; 11 | 12 | all_pod_files_ok(); 13 | -------------------------------------------------------------------------------- /RELEASE.txt: -------------------------------------------------------------------------------- 1 | GLOC 2 | 3 | Version 1.002 4 | 5 | * Fix handling of multiple ampersands in metadata 6 | * Improved handling of not-well-formed input XML 7 | 8 | Version 1.001 9 | 10 | * Fix handling of potentially missing metadata 11 | 12 | Version 1.000 13 | 14 | * Port to Gtk3 15 | 16 | Version 0.601 17 | 18 | * Made SSL requirement explicit 19 | * Improved error reporting under certain conditions 20 | 21 | Version 0.600 22 | 23 | * Added multithreaded download support 24 | * Switched backend to HTTP::Tiny 25 | * Switched version numbering scheme 26 | 27 | Version 0.5.4b 28 | 29 | * Added checks for correct domain names in URL (contentreserve.com, emusic.com) 30 | * Added hack to fix some thumbnail URLs in eMusic files 31 | * Changed default thumbnail name from 'thumb.jpg' to 'folder.jpg' for better 32 | compatibility 33 | 34 | Version 0.5.3b 35 | 36 | * Added additional input checks on parsed variables used in output filename 37 | (for security purposes) 38 | * Minor internal tweaks to allow Windows compatability 39 | * Minor internal tweaks to icon handling 40 | 41 | Version 0.5.2b 42 | 43 | * Fixed bug regarding case sensitivity in file extension recognition 44 | 45 | Version 0.5.1b 46 | 47 | * Modified thumbnail code to try alternative URL for eMusic cover art if 48 | primary URL fails (failure is also now non-fatal) 49 | 50 | Version 0.5b 51 | 52 | * Initial public release 53 | -------------------------------------------------------------------------------- /Makefile.PL: -------------------------------------------------------------------------------- 1 | use 5.012; 2 | 3 | use strict; 4 | use warnings FATAL => 'all'; 5 | 6 | use ExtUtils::MakeMaker; 7 | 8 | WriteMakefile( 9 | NAME => 'gloc', 10 | AUTHOR => q{Jeremy Volkening }, 11 | VERSION_FROM => 'gloc', 12 | ABSTRACT_FROM => 'gloc', 13 | LICENSE => 'GPL_3', 14 | PL_FILES => {}, 15 | MIN_PERL_VERSION => 5.012, 16 | CONFIGURE_REQUIRES => { 17 | 'ExtUtils::MakeMaker' => 0, 18 | }, 19 | BUILD_REQUIRES => { 20 | 'Test::More' => 0, 21 | 'Test::Pod' => 0, 22 | }, 23 | PREREQ_PM => { 24 | # core 25 | 'Config' => 0, 26 | 'Digest::SHA' => 0, 27 | 'Encode' => 0, 28 | 'File::Basename' => 0, 29 | 'File::Copy' => 0, 30 | 'Getopt::Long' => 0, 31 | 'List::Util' => 0, 32 | 'MIME::Base64' => 0, 33 | 'threads' => 0, 34 | 'threads::shared' => 0, 35 | 'Thread::Queue' => 0, 36 | 'Time::Piece' => 0, 37 | 'URI' => 0, 38 | 39 | # non-core 40 | 'File::HomeDir' => 0, 41 | 'Gtk3' => 0, 42 | 'HTML::Entities' => 0, 43 | 'HTTP::Tiny' => 0, 44 | 'IO::Socket::SSL' => 1.56, 45 | 'Net::SSLeay' => 1.49, 46 | 'XML::Simple' => 0, 47 | }, 48 | EXE_FILES => [qw| 49 | gloc 50 | |], 51 | META_MERGE => { 52 | 'meta-spec' => { version => 2 }, 53 | resources => { 54 | repository => { 55 | type => 'git', 56 | url => 'https://github.com/jvolkening/gloc.git', 57 | web => 'https://github.com/jvolkening/gloc', 58 | }, 59 | }, 60 | }, 61 | dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, 62 | clean => { FILES => 'gloc-*' }, 63 | ); 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NAME 2 | 3 | gloc - A GNU/Linux Overdrive/EMusic download client 4 | 5 | # SYNOPSIS 6 | 7 | gloc [options] 8 | 9 | # DESCRIPTION 10 | 11 | GLOC is a download manager for the OverDrive and eMusic MP3 audiobook 12 | collections written in Perl+GTK. Lack of a native Linux client for downloading 13 | OverDrive audiobooks from libraries and retailers has left Linux users in the 14 | cold, and this program was written to fill that need. eMusic compatibility 15 | was added later. It is developed and tested on Debian GNU/Linux but is 16 | expected to run on most flavors of Linux as well as any other platforms with 17 | the Perl bindings to the GTK+ libraries. 18 | 19 | # LICENSING AND LEGAL CONSIDERATIONS (Please read) 20 | 21 | GLOC is not authorized by OverDrive or eMusic. However, GLOC does not make any 22 | attempts to circumvent license restrictions and only works with the (already 23 | DRM-free) MP3 versions of audiobooks. It requires the user to have a license 24 | for any books downloaded in the same way that the official, 25 | non-Linux-compatible client does. 26 | 27 | It is important to note, however, that GLOC is not an audiobook manager, and 28 | does not manage license restrictions. It is a simple client which facilitates 29 | the download of legally borrowed or purchased MP3 files from the official 30 | OverDrive or eMusic servers to the user's computer. It can display license 31 | restrictions associated with a book (such as expiration date for borrowed 32 | books or burn-to-CD limits) but the user is responsible for abiding by any 33 | and all such restrictions and removing files when the license period has ended. 34 | 35 | # INSTALLATION 36 | 37 | GLOC is currently distributed as a single perl script along with associated 38 | documentation. If you are lucky, installation may be as simple as downloading 39 | the tarball, extracting, making the 'gloc' binary executable, and running it. 40 | It is also useful to add 'gloc' to your PATH, but the details of file 41 | permissions and environment variables will not be covered here. 42 | 43 | Some users, however, may need to install a few prerequisites before GLOC will 44 | run. The primary dependency, besides a reasonably modern version of perl, is 45 | the GTK+ (v.3) graphics library. Users of KDE or other non-GTK desktops may 46 | need to install this separately (a rather heavy dependency, but there you have 47 | it). Beyond that, most of the modules used are part of the perl core as of 48 | version 5.9 or later, with the exception of the following which may need to be 49 | installed separately: 50 | 51 | - File::HomeDir 52 | - Gtk3 53 | - IO::Socket::SSL 54 | - HTML::Entities 55 | - HTTP::Tiny 56 | - Net::SSLeay 57 | - XML::Simple 58 | 59 | These are available from the package manager of most distributions. For 60 | example, on Debian they can be installed with (on a single line): 61 | 62 | apt-get install libfile-homedir-perl libgtk3-perl libhtml-parser-perl 63 | libhttp-tiny-perl libxml-simple-perl libio-socket-ssl-perl 64 | libnet-ssleay-perl 65 | 66 | There is also now a Makefile.PL included with the distribution for those who 67 | prefer. All it does is to check the dependencies and copy the executable and 68 | manpage to an appropriate directory (wherever your copy of Perl is configured 69 | to install binaries from MakeMaker scripts). Install by: 70 | 71 | perl Makefile.PL 72 | make 73 | make install 74 | 75 | Test your installation simply by running the program on the command line (if 76 | you don't know how to do this, either read elsewhere or have someone else 77 | install and set up GLOC for you). It should open the main GLOC window. If you 78 | get errors about missing dependencies, check the above, seek help elsewhere, 79 | or (as a last resort) submit a question to the developers. 80 | 81 | # ALTERNATIVE INSTALLATION 82 | 83 | If you have Docker and `docker-compose` installed then you can get GLOC up and 84 | running quickly with [gloc_box](https://github.com/justin2004/gloc_box). 85 | Please make note of the potential issues with Docker and root mentioned in the 86 | associated README. 87 | 88 | # BASIC USAGE 89 | 90 | GLOC usage should be relatively self-explanatory, but a brief description of a 91 | typical use case and some relevant implementation details are provided below. 92 | 93 | ## Loading a Book 94 | 95 | GLOC is meant to be used as a download manager. It works by reading 96 | information from the XML metadata files that are served by both OverDrive and 97 | eMusic (albeit in different formats) when a download is initiated. Basically, 98 | when you click "Download" for a book title in your browser, the browser 99 | will download an "\*.odm" file (for OverDrive) or "\*.emx" file (for eMusic). On 100 | Windows or Mac, this file is transparently opened by the OverDrive Media 101 | Console or eMusic Download Manager. For GLOC, the browser should be set up to 102 | recognize "\*.odm" and "\*.emx" file extensions and open them with the 'gloc' 103 | binary. The details of how to do this are browser-specific and the user should 104 | refer to their browser documentation for how to associate downloaded file 105 | types with specific applications. 106 | 107 | Alternatively, the "\*.odm" or "\*.emx" XML files can be saved to disk and then 108 | opened separately in GLOC. To do this, either pass the path to the XML file on 109 | the command line as the only argument to GLOC (e.g. 'gloc example\_book.odm') 110 | or open up gloc and select the XML file via "File->Open". 111 | 112 | When an ODM or EMX file is opened for the first time, GLOC will prompt for a 113 | directory in which to save the audiobook files. Within this directory, it will 114 | create a new subdirectory with a name based on the book title. For example, if you are 115 | downloading "A Clockwork Orange" and select "Media/Audiobooks" as the parent 116 | directory, GLOC will create a folder called 117 | "Media/Audiobooks/A\_Clockwork\_Orange" to which to save all of the MP3 files 118 | and associated metadata. 119 | 120 | If the XML file loads successfully, the main GLOC window will be populated 121 | with information about the book (title, author, etc) as well as a list of MP3 122 | files comprising the audiobook. By default, all files are selected, but the 123 | list of selected files can be changed if desired. Clicking the 'Start 124 | Download' button at the bottom of the window will initialize download of the 125 | selected files, and progress for each file is shown on the right side of each 126 | line. The download can be aborted at any time by clicking 'Stop Download'. If 127 | all goes well, the status of all files will eventually change to 'Completed' 128 | and GLOC can be closed. 129 | 130 | ## Restarting Interrupted Downloads 131 | 132 | Occasionally a file download will timeout or fail for some reason, and its 133 | status will remain as 'Missing' after the other downloads complete. Download 134 | of individual files can be re-tried as many times as necessary by selecting 135 | them and clicking 'Start Download' again. Successful downloads are tested 136 | by comparing the expected and actual file sizes, which must match before a 137 | file is marked as 'Completed'. 138 | 139 | When a book download is attempted for the first time, GLOC saves a 140 | configuration file in the book's directory named '.gloc\_meta' (normally hidden 141 | in Linux). It also renames and saves a copy of the downloaded XML file as 142 | 'download.odm' or 'download.emx'. If GLOC needs to be closed for some reason 143 | during download, these files store information needed to resume the download 144 | at a later time. Simply run GLOC and open the 'download.odm' or 'download.emx' 145 | file. All relevant information should load and the download can be resumed as 146 | per the previous paragraph. 147 | 148 | # COMMAND LINE OPTIONS 149 | 150 | The following options are supported when using GLOC from the command line: 151 | 152 | - --retry <int> 153 | 154 | Specify the number of times times to retry connections before giving up. 155 | Default: 3. 156 | 157 | - --threads <int> 158 | 159 | Specify the number of download threads to use. 160 | 161 | \*WARNING\*: use of more than one thread is experimental and currently 162 | unstable. Stick to the default singled-threaded mode unless you want to 163 | assist with testing and debugging this feature. Default: 1. 164 | 165 | - --debug 166 | 167 | Print various debugging messages to STDERR. Useful for developers only. 168 | 169 | # LIMITATIONS AND BUGS 170 | 171 | GLOC is only capable of downloading MP3 audiobooks. It does not handle WMA 172 | audiobooks which require proprietary licensing libraries not available on 173 | Linux. However, many libraries as well as commercial retailers using OverDrive 174 | have a wide selection of MP3 audiobooks for download. 175 | 176 | GLOC should be working with eMusic now as well, but the developer no longer 177 | has an active account and so testing has been limited. 178 | 179 | GLOC is considered to be in beta testing stage. The developer has used it 180 | extensively for his own needs and it behaves stably on his system, but no 181 | outside testing on other system configurations has been done. Users are 182 | encouraged to try it out and report any suspected bugs, unexpected behavior, 183 | or other problems or comments on the bug tracker and discussion forums of the 184 | project homepage ([https://github.com/jvolkening/gloc](https://github.com/jvolkening/gloc)). 185 | 186 | # AUTHOR 187 | 188 | Jeremy Volkening 189 | 190 | # CONTRIBUTORS 191 | 192 | Hubert Chathi <@uhoreg> (port to Gtk3) 193 | 194 | # COPYRIGHT AND LICENSE 195 | 196 | Copyright 2014-2021 Jeremy Volkening 197 | 198 | This program is free software: you can redistribute it and/or modify it under 199 | the terms of the GNU General Public License as published by the Free Software 200 | Foundation, either version 3 of the License, or (at your option) any later 201 | version. 202 | 203 | This program is distributed in the hope that it will be useful, but WITHOUT 204 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 205 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 206 | details. 207 | 208 | You should have received a copy of the GNU General Public License along with 209 | this program. If not, see <http://www.gnu.org/licenses/>. 210 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /gloc: -------------------------------------------------------------------------------- 1 | #!/usr/bin/perl 2 | 3 | ############################################################################# 4 | # embedded files 5 | ############################################################################# 6 | 7 | package GLOC::Embed; 8 | 9 | $ui = < 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | XML 24 | 25 | $gloc_tux_16 = < \$retries, 433 | 'debug' => \$debug, 434 | 'threads=i' => \$n_threads, 435 | ); 436 | 437 | 438 | ## Build queue system (MUST be done before using Gtk3!!) 439 | my @status_queue :shared; 440 | $Config{useithreads} 441 | or die "This program requires threaded perl"; 442 | my $download_queue = Thread::Queue->new; 443 | my @workers; 444 | for (1..$n_threads) { 445 | push @workers, threads->create( \&download_file ); 446 | } 447 | 448 | use Gtk3 qw/-init/; 449 | use Glib qw(TRUE FALSE); 450 | 451 | ## Build main GUI 452 | my $mw = Gtk3::Window->new( 'toplevel' ); 453 | $mw->signal_connect( 'delete_event' => \&clean_quit ); 454 | $mw->set_default_size( 400, 500 ); 455 | $mw->set_title( "$PROG_NAME v$VERSION" ); 456 | 457 | ## Set up icon theme 458 | for (16,24,32,48,64) { 459 | Gtk3::IconTheme::add_builtin_icon( 'gloc-tux', $_, $embedded->{"icon_$_"} ); 460 | } 461 | 462 | Gtk3::Window::set_default_icon_name( 'gloc-tux' ); 463 | 464 | # Main layout box 465 | my $vbox_main = Gtk3::VBox->new( FALSE, 0 ); 466 | 467 | # Define menu structure 468 | my @menu_actions = ( 469 | # name stock id label 470 | [ "FileMenu", undef, "_File" ], 471 | [ "HelpMenu", undef, "_Help" ], 472 | # name stock id label accelerator tooltip callback 473 | [ "Open", 'gtk-open', "_Open", "O", "Open", \&open_odm ], 474 | [ "License", undef, "_License Info", undef, "License", \&show_license ], 475 | [ "Quit", 'gtk-quit', "_Quit", "Q", "Quit", \&clean_quit ], 476 | [ "About", 'gtk-about', "_About", undef, "About", \&show_about ], 477 | ); 478 | my $actions = Gtk3::ActionGroup->new( "Actions" ); 479 | $actions->add_actions( \@menu_actions, undef ); 480 | my $ui = Gtk3::UIManager->new; 481 | $ui->insert_action_group( $actions, 0 ); 482 | $mw->add_accel_group( $ui->get_accel_group ); 483 | $ui->add_ui_from_string( $embedded->{ui} ); 484 | $vbox_main->pack_start( $ui->get_widget( "/MenuBar" ), FALSE, FALSE, 0 ); 485 | 486 | # Create book info pane 487 | my $table_book_info = Gtk3::Table->new( 6, 2, FALSE ); 488 | my $hbox_book_info = Gtk3::HBox->new( FALSE, 0 ); 489 | my $thumbnail = Gtk3::Image->new; 490 | my $frame_thumbnail = Gtk3::Frame->new; 491 | $frame_thumbnail->set_shadow_type( 'in' ); 492 | $frame_thumbnail->add( $thumbnail ); 493 | $thumbnail->set_size_request( -1, 120 ); 494 | $thumbnail->set_alignment( 0, 0.5 ); 495 | $table_book_info->attach( 496 | $frame_thumbnail, 497 | 0, 1, 0, 6, 498 | [], 499 | ['expand','fill'], 500 | 8, 501 | 0, 502 | ); 503 | foreach ( 504 | ['Title' => 1,2,0,1], 505 | ['Author' => 1,2,1,2], 506 | ['Narrator' => 1,2,2,3], 507 | ['Publisher' => 1,2,3,4], 508 | ['Duration' => 1,2,4,5], 509 | ['Expires' => 1,2,5,6], 510 | ) { 511 | my ($text,@coords) = @$_; 512 | my $lb = Gtk3::Label->new( undef ); 513 | $lb->set_markup( "$text:" ); 514 | $lb->set_alignment( 1, 0.5 ); 515 | $table_book_info->attach( 516 | $lb, 517 | @coords, 518 | ['fill'], 519 | ['expand','fill'], 520 | 4, 521 | 0 522 | ); 523 | my $l = Gtk3::Label->new( undef ); 524 | $l->set_alignment( 0, 0.5 ); 525 | $coords[0] += 1; 526 | $coords[1] += 1; 527 | $table_book_info->attach( 528 | $l, 529 | @coords, 530 | ['fill'], 531 | ['expand','fill'], 532 | 4, 533 | 0 534 | ); 535 | $info_labels{$text} = $l; 536 | } 537 | $hbox_book_info->pack_start( $table_book_info, FALSE, FALSE, 0 ); 538 | 539 | # Create file list pane 540 | my $COLUMN_ID = 0; 541 | my $COLUMN_FETCH = 1; 542 | my $COLUMN_TITLE = 2; 543 | my $COLUMN_DURATION = 3; 544 | my $COLUMN_SIZE = 4; 545 | my $COLUMN_STATUS = 5; 546 | my $COLUMN_CLICKABLE = 6; 547 | my $COLUMN_PROGRESS = 7; 548 | my $sw_file_list = Gtk3::ScrolledWindow->new( undef, undef ); 549 | $sw_file_list->set_shadow_type( 'in' ); 550 | $sw_file_list->set_policy( 'never', 'always' ); 551 | 552 | my $file_list = Gtk3::ListStore->new( 553 | 'Glib::Int', 554 | 'Glib::Boolean', 555 | 'Glib::String', 556 | 'Glib::String', 557 | 'Glib::String', 558 | 'Glib::String', 559 | 'Glib::Boolean', 560 | 'Glib::Float', 561 | ); 562 | 563 | 564 | my $tview = Gtk3::TreeView->new($file_list); 565 | 566 | #---------------------------------------------------------------------------# 567 | 568 | my $renderer = Gtk3::CellRendererToggle->new; 569 | $renderer->signal_connect( toggled => \&toggle_bool, $file_list ); 570 | my $column = Gtk3::TreeViewColumn->new_with_attributes( 571 | "Fetch?", 572 | $renderer, 573 | active => $COLUMN_FETCH, 574 | activatable => $COLUMN_CLICKABLE, 575 | ); 576 | $column->set_sizing( 'fixed' ); 577 | $column->set_fixed_width( 50 ); 578 | $column->set_alignment( 0.5 ); 579 | $tview->append_column( $column ); 580 | 581 | #---------------------------------------------------------------------------# 582 | 583 | $renderer = Gtk3::CellRendererText->new; 584 | $column = Gtk3::TreeViewColumn->new_with_attributes( 585 | "File name", 586 | $renderer, 587 | text => $COLUMN_TITLE 588 | ); 589 | $tview->append_column( $column ); 590 | 591 | #---------------------------------------------------------------------------# 592 | 593 | $renderer = Gtk3::CellRendererText->new; 594 | $renderer->set( 'xalign' => 0.5 ); 595 | $renderer->set( 'xpad' => 10 ); 596 | $column = Gtk3::TreeViewColumn->new_with_attributes( 597 | "Duration", 598 | $renderer, 599 | text => $COLUMN_DURATION, 600 | ); 601 | $column->set_alignment( 0.5 ); 602 | $tview->append_column( $column ); 603 | 604 | #---------------------------------------------------------------------------# 605 | 606 | $renderer = Gtk3::CellRendererText->new; 607 | $renderer->set( 'xalign'=> 0.5 ); 608 | $renderer->set( 'xpad' => 10 ); 609 | $column = Gtk3::TreeViewColumn->new_with_attributes( 610 | "File size", 611 | $renderer, 612 | text => $COLUMN_SIZE, 613 | ); 614 | $column->set_alignment( 0.5 ); 615 | $tview->append_column( $column ); 616 | 617 | #---------------------------------------------------------------------------# 618 | 619 | $renderer = Gtk3::CellRendererProgress->new; 620 | $column = Gtk3::TreeViewColumn->new_with_attributes( 621 | "Status", 622 | $renderer, 623 | text => $COLUMN_STATUS, 624 | value => $COLUMN_PROGRESS, 625 | ); 626 | $column->set_sizing( 'fixed' ); 627 | $column->set_fixed_width( 100 ); 628 | $tview->append_column( $column ); 629 | 630 | #---------------------------------------------------------------------------# 631 | 632 | $sw_file_list->add( $tview ); 633 | 634 | my $hbox_controls = Gtk3::HBox->new( FALSE, 0 ); 635 | my $btn_select_all = Gtk3::Button->new_with_label( 'Select All' ); 636 | my $btn_select_none = Gtk3::Button->new_with_label( 'Select None' ); 637 | my $btn_download = Gtk3::Button->new_with_label( 'Start Download' ); 638 | $btn_download->signal_connect( 'released' => \&toggle_download ); 639 | $btn_select_all->signal_connect( 640 | 'released' => sub {$file_list->foreach( \&set_bool, [$COLUMN_FETCH => 1] )} ); 641 | $btn_select_none->signal_connect( 642 | 'released' => sub {$file_list->foreach( \&set_bool, [$COLUMN_FETCH => 0] )} ); 643 | $hbox_controls->pack_start( $btn_select_all, FALSE, FALSE, 0 ); 644 | $hbox_controls->pack_start( $btn_select_none, FALSE, FALSE, 0 ); 645 | $hbox_controls->pack_end( $btn_download, FALSE, FALSE, 0 ); 646 | 647 | $vbox_main->pack_start( $hbox_book_info,FALSE, FALSE, 0 ); 648 | $vbox_main->pack_start( $sw_file_list, TRUE, TRUE, 0 ); 649 | $vbox_main->pack_start( $hbox_controls, FALSE, FALSE, 0 ); 650 | my $statusbar = Gtk3::Statusbar->new; 651 | $vbox_main->pack_end( $statusbar, FALSE, FALSE, 0 ); 652 | $mw->add( $vbox_main ); 653 | $mw->show_all; 654 | 655 | # Check for filenames passed in to the program and open if found 656 | if ($ARGV[0]) { 657 | if (-e $ARGV[0] && -f $ARGV[0] && -R $ARGV[0]) { 658 | load_file($ARGV[0]); 659 | } 660 | } 661 | 662 | # Check for SSL support (do this after GUI init so we can use a dialog box) 663 | # Currently this is disabled as stable Debian HTTP::Tiny isn't new enough, but 664 | # it will be enabled ( and the explicit 'use' statements above removed) 665 | # eventually 666 | 667 | # my ($can_ssl, $why) = HTTP::Tiny->can_ssl; 668 | # if (! $can_ssl) { 669 | # visual_warn("GLOC requires SSL, but the following error was received when" 670 | # . " checking for support:\n\n$why\n\nPlease correct this issue and try" 671 | # . " again, or ask for assistance on the project support page."); 672 | # exit(1); 673 | # } 674 | 675 | Gtk3->main; 676 | 677 | 678 | ############################################################################# 679 | # Subroutines 680 | ############################################################################# 681 | 682 | sub download_file { 683 | 684 | my $term_flag = 0; 685 | $SIG{'TERM'} = sub {$term_flag = 1}; 686 | 687 | FILE: 688 | while (my $file_ref = $download_queue->dequeue()) { 689 | my ($id, $filename, $url, $filesize, $license) = @{ $file_ref }; 690 | 691 | { 692 | lock $cwd; 693 | $filename = $cwd . $filename; 694 | } 695 | 696 | # initialize user agent 697 | my $type; 698 | { 699 | lock $current_type; 700 | $type = $current_type; 701 | } 702 | my $ua_string = $current_type eq 'odm' ? $ODM_UA_STRING 703 | : $EMX_UA_STRING; 704 | my $ua = HTTP::Tiny->new( 705 | keep_alive => 1, 706 | agent => $ua_string, 707 | timeout => 60, 708 | ); 709 | 710 | # fetch file size if necessary (currently only eMusic files) 711 | if ($filesize eq '??') { 712 | for (1..$retries) { 713 | my $response = $ua->head($url); 714 | next if (! $response->{success}); 715 | $filesize = $response->{headers}->{'Content-Length'}; 716 | next if (! defined $filesize); 717 | { 718 | lock @status_queue; 719 | push @status_queue, "$id:SZ:$filesize"; 720 | } 721 | last; 722 | } 723 | } 724 | 725 | # hard limit of 200MB on file size to download 726 | if ($filesize > 200*1024**2) { 727 | { 728 | lock @status_queue; 729 | push @status_queue, "$id:VW:Download of files > 200 MiB disabled"; 730 | } 731 | next FILE; 732 | } 733 | 734 | # double-check that the file isn't already downloaded 735 | if (! $filesize) { 736 | { 737 | lock @status_queue; 738 | push @status_queue, "$id:SC:Error"; 739 | } 740 | } 741 | elsif (-e $filename && -s $filename == $filesize) { 742 | { 743 | lock @status_queue; 744 | push @status_queue, "$id:SC:Completed"; 745 | } 746 | } 747 | 748 | else { 749 | warn "Downloading $url to $filename\n" if ($debug); 750 | 751 | { 752 | lock @status_queue; 753 | push @status_queue, "$id:SC:Downloading"; 754 | } 755 | 756 | my $tmpfile = $filename . '.part'; 757 | open my $tmpfh, ">", $tmpfile; 758 | binmode $tmpfh; 759 | 760 | my %headers; 761 | { 762 | lock $current_type; 763 | if ($current_type eq 'odm') { 764 | $headers{'ClientID'} = $CLIENT_ID; 765 | $headers{'License'} = $license; 766 | } 767 | } 768 | 769 | my $size = 0; 770 | my $last_frac = 0; 771 | 772 | TRY: 773 | for (1..$retries) { # try each request up to $retries times 774 | 775 | warn "Try $_...\n" if ($debug); 776 | 777 | my %headers = %headers; 778 | $headers{'Range'} = 'bytes=' . $size . '-'; 779 | 780 | # Make the request and handle the incoming data 781 | my $res = $ua->get( $url, { 782 | headers => {%headers}, 783 | data_callback => sub { 784 | 785 | # Run with every data chunk received 786 | if ($term_flag) { #if TERM rcvd 787 | $term_flag = 0; 788 | last FILE; 789 | #die("Aborted by user"); 790 | } 791 | print {$tmpfh} $_[0] or die "Can't write to $filename: $!\n"; 792 | $size += length $_[0]; 793 | die("Returned more data than expected") if ($size > $filesize); 794 | my $fraction = $size/$filesize*100; 795 | if ($fraction - $last_frac > 5) { 796 | { 797 | lock @status_queue; 798 | push @status_queue, "$id:PU:$fraction"; 799 | } 800 | $last_frac = $fraction; 801 | } 802 | }, 803 | } ); 804 | 805 | # check the outcome 806 | next TRY if ($_ < $retries && $res->{status} == 599 807 | && $res->{content} =~ /^read timeout/); 808 | close $tmpfh; 809 | if ($res->{success} && -s $tmpfile == $filesize) { 810 | { 811 | lock @status_queue; 812 | push @status_queue, "$id:SC:Completed"; 813 | } 814 | copy ($tmpfile => $filename); 815 | } 816 | else { 817 | warn "File size did not match expected value\n" 818 | if ($debug && -s $tmpfile != $filesize); 819 | { 820 | lock @status_queue; 821 | push @status_queue, "$id:SC:Failed"; 822 | } 823 | } 824 | last TRY; 825 | } 826 | 827 | unlink $tmpfile; 828 | } 829 | 830 | # If the queue is empty, send signal that download is done 831 | if (! $download_queue->peek) { 832 | lock @status_queue; 833 | push @status_queue, "$id:DC:Done"; 834 | } 835 | 836 | } 837 | 838 | } 839 | 840 | sub end_download { 841 | 842 | update_file_list(); 843 | $btn_download->set_label( 'Start Download' ); 844 | $file_list->foreach( \&set_bool, [$COLUMN_CLICKABLE => 1] ); 845 | $btn_select_all->set_sensitive( TRUE ); 846 | $btn_select_none->set_sensitive( TRUE ); 847 | { 848 | lock @status_queue; 849 | @status_queue = (); 850 | } 851 | 852 | } 853 | 854 | sub toggle_download { 855 | 856 | if (defined $current_timeout) { # a download is running 857 | 858 | #empty queue and tell current download to stop 859 | if ($download_queue->pending > 0) { 860 | $download_queue->dequeue( $download_queue->pending ); 861 | } 862 | for (@workers) { 863 | $_->kill( 'TERM' ); 864 | } 865 | 866 | #end_download(); 867 | return; 868 | 869 | } 870 | start_download(); 871 | 872 | } 873 | 874 | sub set_bool { 875 | 876 | my ($model,$path,$iter,$arg_ref) = @_; 877 | my ($col, $bool) = @{ $arg_ref }; 878 | my $status = $file_list->get( $iter, $COLUMN_STATUS ); 879 | $bool = 0 if ( $status eq 'Completed' ); 880 | $file_list->set( $iter, $col => $bool ); 881 | return 0; 882 | 883 | } 884 | 885 | sub toggle_bool { 886 | 887 | my ($cell, $path_str, $model) = @_; 888 | my $path = Gtk3::TreePath->new( $path_str ); 889 | my $iter = $model->get_iter( $path ); 890 | my ($fixed) = $model->get( $iter, $COLUMN_FETCH ); 891 | $fixed ^= 1; 892 | $model->set( $iter, $COLUMN_FETCH => $fixed ); 893 | 894 | } 895 | 896 | sub parse_emx { 897 | 898 | my $filename = shift; 899 | my $book = {'source' => 'emx'}; 900 | 901 | # read the .emx XML file into a hash 902 | my $xml = new XML::Simple; 903 | my $data = $xml->XMLin( $filename, 904 | ForceArray => ['TRACK','ARTIST','Part','Creator'], 905 | GroupTags => {TRACKLIST => 'TRACK', 906 | }, 907 | ); 908 | 909 | #EMX files have only track info, so we get book info from first track 910 | my $first_track = $data->{TRACKLIST}->[0]; 911 | $book->{type} = $first_track->{MIMETYPE}; 912 | if ($book->{type} ne 'audio/mpeg') { 913 | visual_warn( "This does not appear to be an Emusic MP3 book" ); 914 | return 0; 915 | } 916 | 917 | $book->{media_ID} = $first_track->{ALBUMID}; 918 | $book->{play_on_PC} = 'NA'; 919 | $book->{play_count} = 'NA'; 920 | $book->{burn_to_CD} = 'NA'; 921 | $book->{burn_count} = 'NA'; 922 | $book->{play_on_PM} = 'NA'; 923 | $book->{SDMI_tfr} = 'NA'; 924 | $book->{nonSDMI_tfr} = 'NA'; 925 | $book->{tfr_count} = 'NA'; 926 | $book->{exp_date} = 'NA'; 927 | 928 | my $title = decode_entities( $first_track->{ALBUM} ); 929 | $book->{title} = $title; 930 | $title =~ s/\W/_/g; 931 | $book->{file_base} = $title; 932 | $book->{publisher} = 'Unknown'; # not listed in EMX 933 | 934 | # for added security, check that URL resides on proper domain 935 | ($book->{thumbnail_url}) = ( $first_track->{ALBUMARTLARGE} 936 | =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$EMUSIC_DOMAIN\/.*)\Z/i ); 937 | ($book->{thumbnail_url2}) = ( $first_track->{ALBUMART} 938 | =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$EMUSIC_DOMAIN\/.*)\Z/i ); 939 | 940 | # Handle multiple authors, etc by appending 'et al' to first 941 | my %multiples; 942 | CREATOR: 943 | $book->{author} = decode_entities( $first_track->{ARTIST}->[0] ); 944 | $book->{author} .= ' et al' if (defined $first_track->{ARTIST}->[1]); 945 | $book->{narrator} = 'Unknown'; # not listed in EMX 946 | 947 | $book->{num_parts} = $first_track->{TRACKCOUNT}; 948 | 949 | #number of parts used in 'open()', so check here for security purposes 950 | die "bad track count" if ($book->{num_parts} !~ /\A\d+\z/); 951 | 952 | my $s = 0; # total length 953 | my @parts; 954 | for (@{ $data->{TRACKLIST} }) { 955 | my $part = {}; 956 | 957 | # for added security, check that URL resides on proper domain 958 | my ($url) = ( $_->{TRACKURL} 959 | =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$EMUSIC_DOMAIN\/.*)\Z/i ); 960 | $part->{url} = $url; 961 | 962 | $part->{filesize} = '??'; 963 | $part->{number} = $_->{TRACKNUM}; 964 | 965 | #track number used in 'open()', so check here for security purposes 966 | die "bad track number" if ($part->{number} !~ /\A\d+\z/); 967 | 968 | $part->{filename} = sprintf "%s_Part_%02d_of_%02d.mp3", 969 | $book->{file_base}, $part->{number}, $book->{num_parts}; 970 | $part->{duration} = int($_->{DURATION}/60) . ':' . sprintf('%02s',$_->{DURATION}%60); 971 | $s += $_->{DURATION}; 972 | push @parts, $part; 973 | } 974 | $book->{parts} = [sort {$a->{number} <=> $b->{number}} @parts]; 975 | $book->{duration} = int($s/3600) . ' hrs ' . int(($s+30)%3600/60) . ' min'; 976 | 977 | if (@{ $book->{parts} } != $first_track->{TRACKCOUNT}) { #internal check 978 | my $counted = @{ $book->{parts} }; 979 | my $reported = $first_track->{TRACKCOUNT}; 980 | visual_warn( "EMX format error: part count mismatch ($counted v $reported)" ); 981 | return 0; 982 | } 983 | 984 | $book->{license} = 'NA'; 985 | 986 | return $book; 987 | 988 | } 989 | sub parse_odm { 990 | 991 | my $filename = shift; 992 | my $book = {'source' => 'odm'}; 993 | 994 | # read file, stripping out the entity because XML::Simple 995 | # seems to have a hard time with it in some files. 996 | my $file_contents; 997 | { 998 | local $/; 999 | open my $in, '<', $filename; 1000 | $file_contents = <$in>; 1001 | close $in; 1002 | $file_contents =~ s/(.*)<\/Description>//s; 1003 | } 1004 | 1005 | # read the .odm XML file into a hash and the CDATA metadata from 1006 | # the file into another hash 1007 | my $xml = new XML::Simple; 1008 | my $data = eval { 1009 | $xml->XMLin( $file_contents, 1010 | ForceArray => ['Format','Protocol','Part','Creator'], 1011 | GroupTags => {Formats => 'Format', 1012 | Protocols => 'Protocol', 1013 | Parts => 'Part', 1014 | Creators => 'Creator', 1015 | }, 1016 | KeyAttr => {Format => 'name', 1017 | Protocol => 'method', 1018 | }, 1019 | ); 1020 | }; 1021 | if ($@) { 1022 | visual_warn( 1023 | "There was an error parsing the download file. Please" 1024 | . " report the following error along with the ODM contents," 1025 | . " if possible, to the GLOC developers:\n\n$@\n" 1026 | ); 1027 | return 0; 1028 | } 1029 | 1030 | # Metadata is sometimes CDATA and sometimes not !!! 1031 | my $meta; 1032 | if (defined $data->{Metadata}) { 1033 | $meta = $data->{Metadata}; 1034 | } 1035 | else { 1036 | 1037 | my $content = $data->{'content'}; 1038 | # OverDrive sometimes uses unescaped ampersands in the metadata block 1039 | $content =~ s/&/&/g; 1040 | $meta = eval { 1041 | $xml->XMLin( $content, 1042 | ForceArray => ['Creator'], 1043 | GroupTags => {'Creators' => 'Creator'}, 1044 | ); 1045 | }; 1046 | if ($@) { 1047 | visual_warn( 1048 | "There was an error parsing the download file. Please" 1049 | . " report the following error along with the ODM contents," 1050 | . " if possible, to the GLOC developers:\n\n$@\n" 1051 | ); 1052 | return 0; 1053 | } 1054 | } 1055 | 1056 | $book->{type} = $meta->{'ContentType'}; 1057 | if ($book->{type} !~ /^MP3/i) { 1058 | visual_warn( "This does not appear to be an MP3 book" ); 1059 | return 0; 1060 | } 1061 | 1062 | $book->{media_ID} = $data->{id}; 1063 | if (ref $data->{License}) { 1064 | $book->{license_url} = $data->{License}->{AcquisitionUrl}; 1065 | } 1066 | else { 1067 | $book->{license} = $data->{License}; 1068 | } 1069 | $book->{play_on_PC} = $data->{DrmInfo}->{PlayOnPC}; 1070 | $book->{play_count} = $data->{DrmInfo}->{PlayOnPCCount}; 1071 | $book->{burn_to_CD} = $data->{DrmInfo}->{BurnToCD}; 1072 | $book->{burn_count} = $data->{DrmInfo}->{BurnToCDCount}; 1073 | $book->{play_on_PM} = $data->{DrmInfo}->{PlayOnPM}; 1074 | $book->{SDMI_tfr} = $data->{DrmInfo}->{TransferToSDMI}; 1075 | $book->{nonSDMI_tfr} = $data->{DrmInfo}->{TransferToNonSDMI}; 1076 | $book->{tfr_count} = $data->{DrmInfo}->{TransferCount}; 1077 | $book->{exp_date} = $data->{DrmInfo}->{ExpirationDate}; 1078 | 1079 | # a bit of a hack - Time::Piece doesnt' seem to handle %z well 1080 | # if not UTC as expected, just use given string 1081 | if ($book->{exp_date} && $book->{exp_date} =~ s/Z$//) { 1082 | my $t = Time::Piece->strptime( $book->{exp_date}, "%Y-%m-%dT%T" ); 1083 | $t += $t->localtime->tzoffset; 1084 | $book->{exp_date} = join ' ', ( 1085 | $t->fullmonth, 1086 | $t->day_of_month . ',', 1087 | $t->year, 1088 | $t->hms, 1089 | ); 1090 | } 1091 | 1092 | my $title = $meta->{Title}; 1093 | $book->{title} = $title; 1094 | $title =~ s/\W/_/g; 1095 | $book->{file_base} = $title; 1096 | $book->{publisher} = $meta->{Publisher}; 1097 | 1098 | # for added security, check that URL resides on proper domain 1099 | ($book->{thumbnail_url}) = ( $meta->{CoverUrl} 1100 | =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$OVERDRIVE_DOMAIN\/.*)\Z/i ); 1101 | ($book->{thumbnail_url2}) = ( $meta->{ThumbnailUrl} 1102 | =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$OVERDRIVE_DOMAIN\/.*)\Z/i ); 1103 | 1104 | # Handle multiple authors, etc by appending 'et al' to first 1105 | my %multiples; 1106 | CREATOR: 1107 | for (@{ $meta->{Creators} }) { 1108 | my $role = lc $_->{role}; 1109 | if (defined $book->{$role}) { 1110 | $multiples{$role} = 1; 1111 | next CREATOR; 1112 | } 1113 | $book->{$role} = $_->{content}; 1114 | } 1115 | $book->{author} .= ' et al' if ($multiples{author}); 1116 | $book->{narrator} .= ' et al' if ($multiples{narrator}); 1117 | 1118 | my $format_ref = get_format( $data->{Formats} ); 1119 | $book->{base_url} = $format_ref->{Protocols}->{download}->{baseurl}; 1120 | $book->{num_parts} = $format_ref->{Parts}->{count}; 1121 | 1122 | #number of parts used in 'open()', so check here for security purposes 1123 | die "bad track count" if ($book->{num_parts} !~ /\A\d+\z/); 1124 | 1125 | my @parts = @{ $format_ref->{Parts}->{Part} }; 1126 | my $s; 1127 | for (@parts) { 1128 | 1129 | #track number used in 'open()', so check here for security purposes 1130 | die "bad track number" if ($_->{number} !~ /\A\d+\z/); 1131 | 1132 | my $full_url = $book->{base_url} . '/' . $_->{filename}; 1133 | $full_url =~ s/\\/\//g; # substitute forward slashes for backslashes 1134 | 1135 | # for added security, check that URL resides on proper domain 1136 | ($_->{url}) = ( $full_url =~ /\A(https?\:\/\/(?:[\w\-\.]*\.)?$OVERDRIVE_DOMAIN\/.*)\Z/i ); 1137 | $_->{filename} = sprintf "%s_Part_%02d_of_%02d.mp3", 1138 | $book->{file_base}, $_->{number}, $book->{num_parts}; 1139 | my ($min,$sec) = split ':', $_->{duration}; 1140 | $s += $sec + $min*60; 1141 | } 1142 | $book->{parts} = [sort {$a->{number} <=> $b->{number}} @parts]; 1143 | $book->{duration} = int($s/3600) . ' hrs ' . int(($s+30)%3600/60) . ' min'; 1144 | 1145 | if (@{ $book->{parts} } != $format_ref->{Parts}->{count}) { #internal check 1146 | visual_warn( "ODM format error: part count mismatch" ); 1147 | return; 1148 | } 1149 | 1150 | # gracefully handle any expected but potentially missing metadata fields 1151 | for my $tag (qw/ 1152 | title 1153 | author 1154 | narrator 1155 | publisher 1156 | /) { 1157 | $book->{$tag} //= 'Unknown/missing'; 1158 | } 1159 | 1160 | return $book; 1161 | 1162 | } 1163 | 1164 | sub load_file { 1165 | 1166 | my $filename = shift; 1167 | if (! -r $filename) { 1168 | visual_warn( "Couldn't open file for reading" ); 1169 | return; 1170 | } 1171 | if ($filename !~ /\.(?:emx|odm)$/ig) { 1172 | visual_warn( "Unrecognized file extension" ); 1173 | return; 1174 | } 1175 | my $book; 1176 | if ($filename =~ /\.odm$/i) { 1177 | 1178 | # for OverDrive books, we need to calculate Client ID and License Hash 1179 | $CLIENT_ID = gen_client_id(); 1180 | warn "set CL to $CLIENT_ID\n" if ($debug); 1181 | if ($CLIENT_ID) { 1182 | $LIC_HASH = get_license_hash( 1183 | $CLIENT_ID, 1184 | $OMC_VERSION, 1185 | $OS_VERSION, 1186 | ); 1187 | $book = parse_odm( $filename ); 1188 | } 1189 | } 1190 | $book = parse_emx( $filename) if ($filename =~ /\.emx$/i); 1191 | return if (! $book); 1192 | $current_book = $book; 1193 | $current_type = $book->{source}; 1194 | my ($file,$path) = fileparse($filename); 1195 | my $sum = sha1_hex( do { 1196 | local $/ = undef; 1197 | open my $infile, '<', $filename; 1198 | binmode $infile; 1199 | <$infile>; 1200 | } ); 1201 | warn "sha1: $sum\n" if ($debug); 1202 | { 1203 | lock $cwd; 1204 | chdir($path) && ($cwd = $path); 1205 | } 1206 | my $download_dir; 1207 | if (my $meta = read_meta()) { # is possible already a download directory 1208 | if ($meta->[0] eq $sum) { 1209 | $download_dir = $path; 1210 | { 1211 | lock $cwd; 1212 | chdir $download_dir && ($cwd = $download_dir); 1213 | } 1214 | warn "already in valid download dir\n" if ($debug); 1215 | } 1216 | my $license = $meta->[1]; 1217 | 1218 | #only set license from current meta if sums matched 1219 | $book->{license} = $license if ($download_dir); 1220 | } 1221 | if (! $download_dir) { 1222 | my $dialog = Gtk3::FileChooserDialog->new( 1223 | 'Please select parent directory', 1224 | $mw, 1225 | 'select-folder', 1226 | 'gtk-cancel'=>'cancel', 1227 | 'gtk-ok' => 'ok', 1228 | ); 1229 | $dialog->set_current_folder($path); 1230 | if ($dialog->run eq 'cancel') { 1231 | $dialog->destroy; 1232 | return 0; 1233 | } 1234 | else { 1235 | my $tmp_path = $dialog->get_filename; 1236 | $dialog->destroy; 1237 | if (-d $tmp_path) { 1238 | my $t = $book->{title}; 1239 | $t =~ s/\s/_/g; 1240 | $download_dir = "$tmp_path/$t/"; 1241 | if (-e $download_dir) { 1242 | visual_warn( "Directory exists and we won't overwrite" ); 1243 | return 0; 1244 | } 1245 | mkdir $download_dir; 1246 | copy( $filename => $download_dir . 'download.' . $book->{source} ); 1247 | warn "changing to $download_dir\n" if ($debug); 1248 | { 1249 | lock $cwd; 1250 | chdir $download_dir && ($cwd = $download_dir); 1251 | } 1252 | my $license = $book->{license} || 'missing'; 1253 | write_meta( [$sum, $license] ); 1254 | $book->{license} = $license; 1255 | } 1256 | else { 1257 | return 0; 1258 | } 1259 | } 1260 | } 1261 | warn "download dir: $download_dir\n" if ($debug); 1262 | 1263 | # update display 1264 | $info_labels{Duration}->set_text( $book->{duration} ); 1265 | $info_labels{Title}->set_text( $book->{title} ); 1266 | $info_labels{Author}->set_text( $book->{author} ); 1267 | $info_labels{Narrator}->set_text( $book->{narrator} ); 1268 | $info_labels{Publisher}->set_text($book->{publisher}); 1269 | $info_labels{Expires}->set_text( $book->{exp_date} ); 1270 | 1271 | # attempt to fetch cover thumbnail if necessary 1272 | # GLOC used to name it 'thumb.jpg', but to increase compatability with 1273 | # other software we now use the more standard (but perhaps more cryptic) 1274 | # 'folder.jpg'. For backward compatability, try to recognize either one. 1275 | my $thumbnail_file = -e 'thumb.jpg' ? 'thumb.jpg' : 'folder.jpg'; 1276 | warn "thumb: $thumbnail_file\n" if ($debug); 1277 | if (! -e $thumbnail_file) { 1278 | my @urls; 1279 | push @urls, $book->{thumbnail_url} if (defined $book->{thumbnail_url}); 1280 | 1281 | # this is a hack because some (older?) eMusic .emx files have bad 1282 | # thumbnail URLs. Will probably change in the future. 1283 | if ($current_type eq 'emx' && defined $book->{thumbnail_url}) { 1284 | my $url = $book->{thumbnail_url}; 1285 | $url =~ s/images(?=\.emusic\.com)/cf-images/; 1286 | $url =~ s/images\/book\/0\//images\//; 1287 | push @urls, $url; 1288 | } 1289 | 1290 | push @urls, $book->{thumbnail_url2} if (defined $book->{thumbnail_url2}); 1291 | URL: 1292 | for (@urls) { 1293 | my $u = $_; 1294 | warn "fetching thumbnail from server: $u\n" if ($debug); 1295 | my $ua = HTTP::Tiny->new( 1296 | keep_alive => 1, 1297 | timeout => 60, 1298 | ); 1299 | my $res = $ua->get( $u ); 1300 | if ($res->{success}) { 1301 | open my $image_file, ">", $thumbnail_file; 1302 | binmode $image_file; 1303 | print {$image_file} $res->{content}; 1304 | close $image_file; 1305 | last URL; 1306 | } 1307 | else { 1308 | warn $res->{reason}, "\n" if ($debug); 1309 | next URL; 1310 | } 1311 | } 1312 | 1313 | } 1314 | if (-e $thumbnail_file) { 1315 | $thumbnail->set_from_pixbuf( 1316 | Gtk3::Gdk::Pixbuf->new_from_file_at_scale( 1317 | $thumbnail_file, 1318 | -1, 1319 | 120, 1320 | TRUE, 1321 | ) 1322 | ); 1323 | $thumbnail->set_size_request( 1324 | min($thumbnail->get_pixbuf->get_width,200), 1325 | min($thumbnail->get_pixbuf->get_height,200), 1326 | ); 1327 | } 1328 | load_file_list(); 1329 | 1330 | } 1331 | 1332 | sub update_file_list { 1333 | 1334 | # runs in current working directory 1335 | my @existing = glob '*'; 1336 | my @parts = @{ $current_book->{parts} }; 1337 | my $id = 0; 1338 | for my $part (@parts) { 1339 | my $status = 'Missing'; 1340 | my $filename = $part->{filename}; 1341 | if (-e $filename) { 1342 | $status = -s $filename == $part->{filesize} 1343 | ? 'Completed' : 'Corrupted'; 1344 | } 1345 | my $iter = $file_list->get_iter( 1346 | Gtk3::TreePath->new_from_indices($id++)); 1347 | my $fetch = $file_list->get($iter, $COLUMN_FETCH); 1348 | my $clickable = TRUE; 1349 | if ($status eq 'Completed'|| $status eq 'Downloading' || $status eq 'Queued') { 1350 | $clickable = FALSE; 1351 | $fetch = FALSE; 1352 | } 1353 | $file_list->set ($iter, 1354 | #this arithmetic hack is necessary because Gtk3::ListStore->set doesn't 1355 | # seem to like plain constants or Readonly constants until they have been 1356 | # used at least once 1357 | $COLUMN_FETCH => $fetch, 1358 | $COLUMN_STATUS => $status, 1359 | $COLUMN_CLICKABLE => $clickable, 1360 | $COLUMN_PROGRESS => 0, 1361 | ); 1362 | 1363 | 1364 | } 1365 | 1366 | } 1367 | 1368 | sub load_file_list { 1369 | 1370 | # runs in current working directory 1371 | my @existing = glob '*'; 1372 | my @parts = @{ $current_book->{parts} }; 1373 | visual_warn( "Too many book parts" ) && return if (@parts > 99); 1374 | $file_list->clear; 1375 | my $id = 0; 1376 | for my $part (@parts) { 1377 | my $status = 'Missing'; 1378 | my $filename = $part->{filename}; 1379 | if (-e $filename) { 1380 | $status = $part->{filesize} eq '??' ? 'Unknown' 1381 | : -s $filename == $part->{filesize} ? 'Completed' 1382 | : 'Corrupted'; 1383 | } 1384 | my $iter = $file_list->append; 1385 | my $clickable = TRUE; 1386 | my $fetch = TRUE; 1387 | if ($status eq 'Completed'|| $status eq 'Downloading' || $status eq 'Queued') { 1388 | $clickable = FALSE; 1389 | $fetch = FALSE; 1390 | } 1391 | $file_list->set ($iter, 1392 | #this arithmetic hack is necessary because Gtk3::ListStore->set doesn't 1393 | # seem to like plain constants or Readonly constants until they have been 1394 | # used at least once 1395 | $COLUMN_ID+0 => $id++, 1396 | $COLUMN_FETCH => $fetch, 1397 | $COLUMN_TITLE => $filename, 1398 | $COLUMN_DURATION => $part->{duration}, 1399 | $COLUMN_SIZE => format_size( $part->{filesize} ), 1400 | $COLUMN_STATUS => $status, 1401 | $COLUMN_CLICKABLE => $clickable, 1402 | $COLUMN_PROGRESS => 0, 1403 | ); 1404 | 1405 | 1406 | } 1407 | 1408 | } 1409 | 1410 | sub format_size { 1411 | 1412 | my $bytes = shift; 1413 | return $bytes if ($bytes !~ /^\d+$/); 1414 | my @labels = qw/B KiB MiB GiB TiB/; 1415 | my $exp = $bytes > 1024**4 ? 4 1416 | : $bytes > 1024**3 ? 3 1417 | : $bytes > 1024**2 ? 2 1418 | : $bytes > 1024**1 ? 1 1419 | : 0; 1420 | my $string = sprintf "%.1f %s", $bytes/1024**$exp, $labels[$exp]; 1421 | return $string; 1422 | 1423 | } 1424 | 1425 | 1426 | sub open_odm { 1427 | my $opendialog = Gtk3::FileChooserDialog->new( 1428 | 'Open audiobook descriptor file', 1429 | $mw, 1430 | 'open', 1431 | 'gtk-cancel' => 'cancel', 1432 | 'gtk-ok' => 'ok', 1433 | ); 1434 | my $filename; 1435 | if ( $opendialog->run eq 'ok') { 1436 | $filename = ($opendialog->get_filename); 1437 | load_file($filename); 1438 | } 1439 | $opendialog->destroy; 1440 | } 1441 | 1442 | sub visual_warn { 1443 | my $error_string = shift; 1444 | $error_string =~ s/\s/ /g; 1445 | my $blocked_string = ''; 1446 | my $curr_line = ''; 1447 | while ($error_string =~ /(\S+) ?/g) { 1448 | my $word = $1; 1449 | $curr_line = $curr_line ? "$curr_line $word" : $word; 1450 | if (length $curr_line >= 40) { 1451 | $blocked_string .= "$curr_line\n"; 1452 | $curr_line = ''; 1453 | } 1454 | } 1455 | $blocked_string .= $curr_line; 1456 | my $dialog = Gtk3::MessageDialog->new( 1457 | $mw, 1458 | 'modal', 1459 | 'error', 1460 | 'ok', 1461 | $blocked_string 1462 | #undef, 1463 | ); 1464 | $dialog->run; 1465 | $dialog->destroy; 1466 | return 0; 1467 | } 1468 | 1469 | sub clean_quit { 1470 | Gtk3->main_quit; 1471 | 1472 | if (defined $current_timeout) { 1473 | if ($download_queue->pending > 0) { 1474 | $download_queue->dequeue( $download_queue->pending ); 1475 | } 1476 | for (@workers) { 1477 | $_->kill('TERM'); 1478 | } 1479 | } 1480 | $download_queue->enqueue(undef) for (@workers); 1481 | for (@workers) { 1482 | $_->join(); 1483 | } 1484 | 1485 | return 0; 1486 | 1487 | } 1488 | 1489 | sub show_about { 1490 | 1491 | my $dialog = Gtk3::AboutDialog->new; 1492 | $dialog->set_program_name($PROG_NAME); 1493 | $dialog->set_version($VERSION); 1494 | $dialog->set_copyright(chr(169) . ' 2014-2021 Jeremy Volkening'); 1495 | $dialog->set_comments('GLOC is a native Linux substitute for the Overdrive Media Console and eMusic download clients'); 1496 | $dialog->set_authors(['Jeremy Volkening']); 1497 | $dialog->set_wrap_license(TRUE); 1498 | $dialog->set_license( 1499 | "$PROG_NAME is free software: you can redistribute it and/or modify " . 1500 | 'it under the terms of the GNU General Public License as published by ' . 1501 | 'the Free Software Foundation, either version 3 of the License, or ' . 1502 | "(at your option) any later version.\n\n" . 1503 | 1504 | "$PROG_NAME is distributed in the hope that it will be useful, " . 1505 | 'but WITHOUT ANY WARRANTY; without even the implied warranty of ' . 1506 | 'MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ' . 1507 | "GNU General Public License for more details.\n\n" . 1508 | 1509 | 'You should have received a copy of the GNU General Public License ' . 1510 | 'along with this program. If not, see http://www.gnu.org/licenses/.' 1511 | ); 1512 | $dialog->set_logo_icon_name('gloc-tux'); 1513 | $dialog->run; 1514 | $dialog->destroy; 1515 | return 0; 1516 | 1517 | } 1518 | 1519 | sub gen_client_id { 1520 | 1521 | # The client ID consists of a string of hexidecimal digits in the form of 1522 | # XXXXXXXX-XXXX-XXXX-XXXXXXXXXXXXXXXXX 1523 | # We generate a random string in this format the first time it is 1524 | # requested and then read it from a config file thereafter. 1525 | 1526 | my $home_dir = File::HomeDir->my_home . '/.gloc'; 1527 | if (-e $home_dir && ! -d $home_dir) { 1528 | visual_warn("Won\'t overwrite ~/.gloc"); 1529 | clean_quit(); 1530 | } 1531 | mkdir $home_dir if (! -e $home_dir); 1532 | 1533 | # generate a file containing the random client ID if it doesn't exist 1534 | if (! -e "$home_dir/client_ID") { 1535 | my $id = join('', map {("A".."F",0..9)[int(rand(16))]} (1..36)); 1536 | substr($id,$_,1) = '-' for (8,13,18); 1537 | open my $out, '>', "$home_dir/client_ID"; 1538 | print {$out} $id; 1539 | close $out; 1540 | } 1541 | 1542 | # read the client ID 1543 | open my $in, '<', "$home_dir/client_ID"; 1544 | my $id = <$in>; 1545 | close $in; 1546 | die "FATAL ERROR: Invalid client ID\n" 1547 | if ($id !~ /^[0-9A-F]{8}\-[0-9A-F]{4}\-[0-9A-F]{4}\-[0-9A-F]{17}$/); 1548 | warn "CLID: $id\n" if ($debug); 1549 | return $id; 1550 | 1551 | } 1552 | 1553 | sub get_license_hash { 1554 | 1555 | # This routine returns a SHA-1 hash for inclusion with the license request 1556 | # String is built and then properly encoded and hashed 1557 | my ($ClientID , $OMCv , $OSv) = @_; 1558 | my $id = join '|', ($ClientID, $OMCv, $OSv, 'ELOSNOC*AIDEM*EVIRDREVO'); 1559 | return sha1_base64( encode('utf16le',$id) ) . '='; 1560 | 1561 | } 1562 | 1563 | sub get_format { 1564 | 1565 | my $hash_ref = shift; 1566 | my @keys = keys %{ $hash_ref }; 1567 | my $format_ref = $hash_ref->{$keys[0]}; 1568 | if (@keys > 1) { 1569 | my $dialog = Gtk3::Dialog->new_with_buttons( 1570 | "Choose Format", 1571 | $mw, 1572 | 'modal', 1573 | 'OK' => 1, 1574 | 'Cancel' => 0, 1575 | ); 1576 | my $vbox = $dialog->get_content_area; 1577 | $vbox->pack_start(Gtk3::Label->new("This audiobook has multiple formats\n" 1578 | . "Please choose the format you would like to use:"),TRUE,TRUE,5); 1579 | my $combo_box = Gtk3::ComboBox->new_text(); 1580 | for (@keys) { $combo_box->append_text($_) } 1581 | $vbox->pack_start($combo_box,FALSE,FALSE,5); 1582 | $combo_box->set_active(0); 1583 | $vbox->show_all; 1584 | my $response = $dialog->run; 1585 | if (! $response) { 1586 | $dialog->destroy; 1587 | return undef; 1588 | } 1589 | my $choice = $combo_box->get_active_text; 1590 | $dialog->destroy; 1591 | $format_ref = $hash_ref->{$choice}; 1592 | } 1593 | return $format_ref; 1594 | 1595 | } 1596 | 1597 | sub get_embedded { 1598 | 1599 | my $embedded = {}; 1600 | 1601 | my %encoded = ( 1602 | icon_16 => $GLOC::Embed::gloc_tux_16, 1603 | icon_24 => $GLOC::Embed::gloc_tux_24, 1604 | icon_32 => $GLOC::Embed::gloc_tux_32, 1605 | icon_48 => $GLOC::Embed::gloc_tux_48, 1606 | icon_64 => $GLOC::Embed::gloc_tux_64, 1607 | ); 1608 | my %unencoded = ( 1609 | ui => $GLOC::Embed::ui, 1610 | ); 1611 | 1612 | for (keys %encoded) { 1613 | $embedded->{$_} = do { 1614 | my $loader = Gtk3::Gdk::PixbufLoader->new(); 1615 | my $img_data = decode_base64($encoded{$_}); 1616 | $loader->write( [unpack 'C*', $img_data] ); 1617 | $loader->close; 1618 | $loader->get_pixbuf(); 1619 | }; 1620 | } 1621 | for (keys %unencoded) { 1622 | $embedded->{$_} = $unencoded{$_}; 1623 | } 1624 | return $embedded; 1625 | 1626 | } 1627 | 1628 | sub start_download { 1629 | 1630 | my $license = $current_book->{license}; 1631 | if (! $license || $license eq 'missing') { 1632 | fetch_license() || return FALSE; 1633 | } 1634 | 1635 | $btn_download->set_label('Stop Download'); 1636 | $file_list->foreach( \&set_bool, [$COLUMN_CLICKABLE => 0] ); 1637 | $btn_select_all->set_sensitive(FALSE); 1638 | $btn_select_none->set_sensitive(FALSE); 1639 | my $queued = 0; 1640 | $file_list->foreach( sub { 1641 | 1642 | my ($model,$path,$iter) = @_; 1643 | my $is_checked = $model->get($iter, $COLUMN_FETCH); 1644 | return 0 if (! $is_checked); 1645 | my $id = $model->get($iter, $COLUMN_ID); 1646 | $download_queue->enqueue( [ 1647 | $id, 1648 | $current_book->{parts}->[$id]->{filename}, 1649 | $current_book->{parts}->[$id]->{url}, 1650 | $current_book->{parts}->[$id]->{filesize}, 1651 | $current_book->{license}, 1652 | ] ); 1653 | $model->set($iter, $COLUMN_STATUS, 'Queued'); 1654 | ++$queued; 1655 | return FALSE; 1656 | 1657 | } ); 1658 | if (! $queued) { 1659 | end_download(); 1660 | return FALSE; 1661 | } 1662 | $current_timeout = Glib::Timeout->add( 1663 | 500, 1664 | \&check_status, 1665 | ); 1666 | 1667 | } 1668 | 1669 | sub check_status { 1670 | 1671 | my @messages = (); 1672 | { 1673 | lock @status_queue; 1674 | while (my $msg = shift @status_queue) { 1675 | push @messages, $msg; 1676 | } 1677 | } 1678 | for (@messages) { 1679 | my ($id, $type, $value) = split ':', $_; 1680 | my $iter = $file_list->get_iter( 1681 | Gtk3::TreePath->new_from_indices($id)); 1682 | if ($type eq 'SC' ) { #status change 1683 | $file_list->set($iter, $COLUMN_PROGRESS => 0); 1684 | $file_list->set($iter, $COLUMN_STATUS => $value); 1685 | } 1686 | elsif ($type eq 'PU' ) { #status change 1687 | $file_list->set($iter, $COLUMN_PROGRESS => $value); 1688 | } 1689 | elsif ($type eq 'DC' ) { #status change 1690 | $current_timeout = undef; 1691 | end_download(); 1692 | return FALSE; 1693 | } 1694 | elsif ($type eq 'VW' ) { #status change 1695 | visual_warn($value); 1696 | } 1697 | elsif ($type eq 'SZ' ) { #size update 1698 | $file_list->set($iter, $COLUMN_SIZE => format_size($value)); 1699 | $current_book->{parts}->[$id]->{filesize} = $value; 1700 | } 1701 | } 1702 | return TRUE; 1703 | 1704 | } 1705 | 1706 | sub fetch_license { 1707 | 1708 | my $license_url = $current_book->{license_url}; 1709 | my $media_ID = $current_book->{media_ID}; 1710 | return 0 if (! defined $license_url || ! defined $media_ID); 1711 | $license_url = URI->new($license_url); 1712 | my $tail = "MediaID=$media_ID&ClientID=$CLIENT_ID&OMC=$OMC_VERSION&OS=$OS_VERSION&Hash=$LIC_HASH"; 1713 | $license_url->query( 1714 | $license_url->query ? $license_url->query . "&$tail" : $tail 1715 | ); 1716 | warn "LICENSE: $license_url\n" if ($debug); 1717 | my $ua = HTTP::Tiny->new( 1718 | keep_alive => 1, 1719 | agent => $ODM_UA_STRING, 1720 | timeout => 60, 1721 | ); 1722 | my $res = $ua->get($license_url); 1723 | if ($res->{success}) { 1724 | warn "successfully retrieved license\n" if ($debug); 1725 | my $lic_string = $res->{content}; 1726 | $lic_string =~ s/\s/ /g; 1727 | write_meta( [undef,$lic_string] ); 1728 | $current_book->{license} = $lic_string; 1729 | return TRUE; 1730 | 1731 | } 1732 | 1733 | # this point is reached if there was an error of some sort 1734 | my $err; 1735 | eval { $err = XMLin( $res->{content} ) }; 1736 | if (defined $err) { 1737 | my $code = $err->{ErrorCode}; 1738 | my $msg = $err->{ErrorMessage}; 1739 | if ($code == 1003) { 1740 | visual_warn( "The following error was received from the server" 1741 | . " when requesting the license for this book: \"$msg\"." 1742 | . " The most common cause for this is trying to download the same" 1743 | . " book more than once using the same ODM file. Try to fetch a" 1744 | . " fresh ODM file by re-downloading the book from Overdrive, or" 1745 | . " seek help on the project support page." ); 1746 | } 1747 | else { 1748 | visual_warn( "The following error was received from the server" 1749 | . " when requesting the license for this book:\"$msg\"." 1750 | . " For support, please report this message to the support page" 1751 | . " of the software package." ); 1752 | } 1753 | } 1754 | else { 1755 | visual_warn( "There was an unknown error fetching the license for" 1756 | . " this book. The full contents of the error (if any) will be" 1757 | . " included below. For support, please report this message to the" 1758 | . " support page of the software package." ); 1759 | } 1760 | 1761 | warn "error fetching license: $res->{reason}\n$res->{content}\n" if ($debug); 1762 | return FALSE; 1763 | 1764 | } 1765 | 1766 | sub read_meta { 1767 | 1768 | return 0 if (! -r '.gloc_meta'); 1769 | my $string; 1770 | { 1771 | local $/ = undef; 1772 | open my $in, '<', '.gloc_meta'; 1773 | $string = <$in>; 1774 | } 1775 | if ($string =~ /\Aodm_hash:(\w*)\nodm_license:([^\n]*)\Z/m) { 1776 | return [$1, $2]; 1777 | } 1778 | else { 1779 | visual_warn( "incorrectly formatted meta file" ) & return 0; 1780 | } 1781 | 1782 | } 1783 | sub write_meta { 1784 | 1785 | my $ref = shift; 1786 | my $existing = read_meta(); 1787 | my $new = $ref; 1788 | if ($existing) { 1789 | $new->[0] = $ref->[0] ? $ref->[0] : $existing->[0]; 1790 | $new->[1] = $ref->[1] ? $ref->[1] : $existing->[1]; 1791 | } 1792 | open my $out, '>', '.gloc_meta'; 1793 | print {$out} "odm_hash:$new->[0]\nodm_license:$new->[1]\n"; 1794 | close $out; 1795 | return 1; 1796 | 1797 | } 1798 | 1799 | sub show_license { 1800 | 1801 | my %text_values = ( 1802 | -1 => 'Unlimited', 1803 | 0 => 'No', 1804 | 1 => 'Yes', 1805 | ); 1806 | 1807 | my $table_license_info = Gtk3::Table->new( 6, 2, FALSE ); 1808 | foreach ( 1809 | #slot label 1810 | [ 'play_on_PC', 'Play On PC', 1,2,0,1 ], 1811 | [ 'play_count', 'Play On PCCount', 1,2,1,2 ], 1812 | [ 'burn_to_CD', 'Burn To CD', 1,2,2,3 ], 1813 | [ 'burn_count', 'Burn To CD Count', 1,2,3,4 ], 1814 | [ 'play_on_PM', 'Play On PM', 1,2,4,5 ], 1815 | [ 'SDMI_tfr', 'Transfer To SDMI', 1,2,5,6 ], 1816 | [ 'nonSDMI_tfr', 'Transfer To NonSDMI', 1,2,6,7 ], 1817 | [ 'tfr_count', 'Transfer Count', 1,2,7,8 ], 1818 | [ 'exp_date', 'Expiration Date', 1,2,8,9 ], 1819 | ) { 1820 | my ($slot, $text, @coords) = @$_; 1821 | my $lb = Gtk3::Label->new( undef ); 1822 | $lb->set_markup( "$text:" ); 1823 | $lb->set_alignment( 1, 0.5 ); 1824 | $table_license_info->attach( 1825 | $lb, 1826 | @coords, 1827 | ['fill'], 1828 | ['expand','fill'], 1829 | 4, 1830 | 0 1831 | ); 1832 | my $value = $text_values{ $current_book->{$slot} } 1833 | || $current_book->{$slot}; 1834 | my $l2 = Gtk3::Label->new( $value ); 1835 | $l2->set_alignment( 0, 0.5 ); 1836 | $coords[0] += 1; 1837 | $coords[1] += 1; 1838 | $table_license_info->attach( 1839 | $l2, 1840 | @coords, 1841 | ['fill'], 1842 | ['expand','fill'], 1843 | 4, 1844 | 0 1845 | ); 1846 | } 1847 | 1848 | my $dialog = Gtk3::Dialog->new_with_buttons( 1849 | "Audiobook License Details", 1850 | $mw, 1851 | 'modal', 1852 | 'OK' => 1, 1853 | ); 1854 | my $vbox = $dialog->get_content_area; 1855 | $vbox->pack_start( $table_license_info, TRUE, TRUE, 0 ); 1856 | $vbox->show_all; 1857 | my $response = $dialog->run; 1858 | $dialog->destroy; 1859 | 1860 | } 1861 | 1862 | __END__ 1863 | 1864 | 1865 | =head1 NAME 1866 | 1867 | gloc - A GNU/Linux Overdrive/EMusic download client 1868 | 1869 | 1870 | =head1 SYNOPSIS 1871 | 1872 | gloc [options] 1873 | 1874 | 1875 | =head1 DESCRIPTION 1876 | 1877 | GLOC is a download manager for the OverDrive and eMusic MP3 audiobook 1878 | collections written in Perl+GTK. Lack of a native Linux client for downloading 1879 | OverDrive audiobooks from libraries and retailers has left Linux users in the 1880 | cold, and this program was written to fill that need. eMusic compatibility 1881 | was added later. It is developed and tested on Debian GNU/Linux but is 1882 | expected to run on most flavors of Linux as well as any other platforms with 1883 | the Perl bindings to the GTK+ libraries. 1884 | 1885 | 1886 | =head1 LICENSING AND LEGAL CONSIDERATIONS (Please read) 1887 | 1888 | GLOC is not authorized by OverDrive or eMusic. However, GLOC does not make any 1889 | attempts to circumvent license restrictions and only works with the (already 1890 | DRM-free) MP3 versions of audiobooks. It requires the user to have a license 1891 | for any books downloaded in the same way that the official, 1892 | non-Linux-compatible client does. 1893 | 1894 | It is important to note, however, that GLOC is not an audiobook manager, and 1895 | does not manage license restrictions. It is a simple client which facilitates 1896 | the download of legally borrowed or purchased MP3 files from the official 1897 | OverDrive or eMusic servers to the user's computer. It can display license 1898 | restrictions associated with a book (such as expiration date for borrowed 1899 | books or burn-to-CD limits) but the user is responsible for abiding by any 1900 | and all such restrictions and removing files when the license period has ended. 1901 | 1902 | 1903 | =head1 INSTALLATION 1904 | 1905 | GLOC is currently distributed as a single perl script along with associated 1906 | documentation. If you are lucky, installation may be as simple as downloading 1907 | the tarball, extracting, making the 'gloc' binary executable, and running it. 1908 | It is also useful to add 'gloc' to your PATH, but the details of file 1909 | permissions and environment variables will not be covered here. 1910 | 1911 | Some users, however, may need to install a few prerequisites before GLOC will 1912 | run. The primary dependency, besides a reasonably modern version of perl, is 1913 | the GTK+ (v.3) graphics library. Users of KDE or other non-GTK desktops may 1914 | need to install this separately (a rather heavy dependency, but there you have 1915 | it). Beyond that, most of the modules used are part of the perl core as of 1916 | version 5.9 or later, with the exception of the following which may need to be 1917 | installed separately: 1918 | 1919 | =over 1 1920 | 1921 | =item * File::HomeDir 1922 | 1923 | =item * Gtk3 1924 | 1925 | =item * IO::Socket::SSL 1926 | 1927 | =item * HTML::Entities 1928 | 1929 | =item * HTTP::Tiny 1930 | 1931 | =item * Net::SSLeay 1932 | 1933 | =item * XML::Simple 1934 | 1935 | =back 1936 | 1937 | These are available from the package manager of most distributions. For 1938 | example, on Debian they can be installed with (on a single line): 1939 | 1940 | apt-get install libfile-homedir-perl libgtk3-perl libhtml-parser-perl 1941 | libhttp-tiny-perl libxml-simple-perl libio-socket-ssl-perl 1942 | libnet-ssleay-perl 1943 | 1944 | There is also now a Makefile.PL included with the distribution for those who 1945 | prefer. All it does is to check the dependencies and copy the executable and 1946 | manpage to an appropriate directory (wherever your copy of Perl is configured 1947 | to install binaries from MakeMaker scripts). Install by: 1948 | 1949 | perl Makefile.PL 1950 | make 1951 | make install 1952 | 1953 | Test your installation simply by running the program on the command line (if 1954 | you don't know how to do this, either read elsewhere or have someone else 1955 | install and set up GLOC for you). It should open the main GLOC window. If you 1956 | get errors about missing dependencies, check the above, seek help elsewhere, 1957 | or (as a last resort) submit a question to the developers. 1958 | 1959 | =head1 ALTERNATIVE INSTALLATION 1960 | 1961 | If you have Docker and C installed then you can get GLOC up and 1962 | running quickly with L. 1963 | Please make note of the potential issues with Docker and root mentioned in the 1964 | associated README. 1965 | 1966 | =head1 BASIC USAGE 1967 | 1968 | GLOC usage should be relatively self-explanatory, but a brief description of a 1969 | typical use case and some relevant implementation details are provided below. 1970 | 1971 | =head2 Loading a Book 1972 | 1973 | GLOC is meant to be used as a download manager. It works by reading 1974 | information from the XML metadata files that are served by both OverDrive and 1975 | eMusic (albeit in different formats) when a download is initiated. Basically, 1976 | when you click "Download" for a book title in your browser, the browser 1977 | will download an "*.odm" file (for OverDrive) or "*.emx" file (for eMusic). On 1978 | Windows or Mac, this file is transparently opened by the OverDrive Media 1979 | Console or eMusic Download Manager. For GLOC, the browser should be set up to 1980 | recognize "*.odm" and "*.emx" file extensions and open them with the 'gloc' 1981 | binary. The details of how to do this are browser-specific and the user should 1982 | refer to their browser documentation for how to associate downloaded file 1983 | types with specific applications. 1984 | 1985 | Alternatively, the "*.odm" or "*.emx" XML files can be saved to disk and then 1986 | opened separately in GLOC. To do this, either pass the path to the XML file on 1987 | the command line as the only argument to GLOC (e.g. 'gloc example_book.odm') 1988 | or open up gloc and select the XML file via "File->Open". 1989 | 1990 | When an ODM or EMX file is opened for the first time, GLOC will prompt for a 1991 | directory in which to save the audiobook files. Within this directory, it will 1992 | create a new subdirectory with a name based on the book title. For example, if you are 1993 | downloading "A Clockwork Orange" and select "Media/Audiobooks" as the parent 1994 | directory, GLOC will create a folder called 1995 | "Media/Audiobooks/A_Clockwork_Orange" to which to save all of the MP3 files 1996 | and associated metadata. 1997 | 1998 | If the XML file loads successfully, the main GLOC window will be populated 1999 | with information about the book (title, author, etc) as well as a list of MP3 2000 | files comprising the audiobook. By default, all files are selected, but the 2001 | list of selected files can be changed if desired. Clicking the 'Start 2002 | Download' button at the bottom of the window will initialize download of the 2003 | selected files, and progress for each file is shown on the right side of each 2004 | line. The download can be aborted at any time by clicking 'Stop Download'. If 2005 | all goes well, the status of all files will eventually change to 'Completed' 2006 | and GLOC can be closed. 2007 | 2008 | =head2 Restarting Interrupted Downloads 2009 | 2010 | Occasionally a file download will timeout or fail for some reason, and its 2011 | status will remain as 'Missing' after the other downloads complete. Download 2012 | of individual files can be re-tried as many times as necessary by selecting 2013 | them and clicking 'Start Download' again. Successful downloads are tested 2014 | by comparing the expected and actual file sizes, which must match before a 2015 | file is marked as 'Completed'. 2016 | 2017 | When a book download is attempted for the first time, GLOC saves a 2018 | configuration file in the book's directory named '.gloc_meta' (normally hidden 2019 | in Linux). It also renames and saves a copy of the downloaded XML file as 2020 | 'download.odm' or 'download.emx'. If GLOC needs to be closed for some reason 2021 | during download, these files store information needed to resume the download 2022 | at a later time. Simply run GLOC and open the 'download.odm' or 'download.emx' 2023 | file. All relevant information should load and the download can be resumed as 2024 | per the previous paragraph. 2025 | 2026 | 2027 | =head1 COMMAND LINE OPTIONS 2028 | 2029 | The following options are supported when using GLOC from the command line: 2030 | 2031 | =over 1 2032 | 2033 | =item --retry 2034 | 2035 | Specify the number of times times to retry connections before giving up. 2036 | Default: 3. 2037 | 2038 | =item --threads 2039 | 2040 | Specify the number of download threads to use. 2041 | 2042 | *WARNING*: use of more than one thread is experimental and currently 2043 | unstable. Stick to the default singled-threaded mode unless you want to 2044 | assist with testing and debugging this feature. Default: 1. 2045 | 2046 | =item --debug 2047 | 2048 | Print various debugging messages to STDERR. Useful for developers only. 2049 | 2050 | =back 2051 | 2052 | 2053 | =head1 LIMITATIONS AND BUGS 2054 | 2055 | GLOC is only capable of downloading MP3 audiobooks. It does not handle WMA 2056 | audiobooks which require proprietary licensing libraries not available on 2057 | Linux. However, many libraries as well as commercial retailers using OverDrive 2058 | have a wide selection of MP3 audiobooks for download. 2059 | 2060 | GLOC should be working with eMusic now as well, but the developer no longer 2061 | has an active account and so testing has been limited. 2062 | 2063 | GLOC is considered to be in beta testing stage. The developer has used it 2064 | extensively for his own needs and it behaves stably on his system, but no 2065 | outside testing on other system configurations has been done. Users are 2066 | encouraged to try it out and report any suspected bugs, unexpected behavior, 2067 | or other problems or comments on the bug tracker and discussion forums of the 2068 | project homepage (L). 2069 | 2070 | 2071 | =head1 AUTHOR 2072 | 2073 | Jeremy Volkening 2074 | 2075 | =head1 CONTRIBUTORS 2076 | 2077 | Hubert Chathi <@uhoreg> (port to Gtk3) 2078 | 2079 | =head1 COPYRIGHT AND LICENSE 2080 | 2081 | Copyright 2014-2021 Jeremy Volkening 2082 | 2083 | This program is free software: you can redistribute it and/or modify it under 2084 | the terms of the GNU General Public License as published by the Free Software 2085 | Foundation, either version 3 of the License, or (at your option) any later 2086 | version. 2087 | 2088 | This program is distributed in the hope that it will be useful, but WITHOUT 2089 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 2090 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 2091 | details. 2092 | 2093 | You should have received a copy of the GNU General Public License along with 2094 | this program. If not, see . 2095 | 2096 | =cut 2097 | 2098 | --------------------------------------------------------------------------------