]>
gitweb.michael.orlitzky.com - dead/whatever-dl.git/blob - src/website.rb
2 # Copyright Michael Orlitzky
4 # http://michael.orlitzky.com/
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # http://www.fsf.org/licensing/licenses/gpl.html
19 # Necessary in a lot of subclasses; plus, we need it
20 # to parse the server name out of our URL.
23 # This class keeps track of all its subclasses
24 # We use this to loop through every "website" in an
25 # attempt to determine to which site a URL belongs.
33 def self.inherited(subclass
)
34 if superclass
.respond_to
? :inherited
35 superclass
.inherited(subclass
)
38 # Every time we're subclassed, add the new
39 # subclass to our list of subclasses.
41 @subclasses << subclass
46 # Get the HTTP server portion of our URI
60 # Factory method returning an instance of
61 # the appropriate subclass.
63 # Check the URL against each website's class.
64 # The class will know whether or not the URL
65 # "belongs" to its website.
66 @subclasses.each
do |w
|
72 # If nothing matched, we don't return an instance
78 # Abstract definition. Each subclass of Website
79 # should support it on its own.
80 def self.owns_url
?(url
)
81 raise NotImplementedError
85 # Same here. Abstract.
87 raise NotImplementedError
91 # The website class should be responsible for determining the
92 # video's filename. By default, we can take the last component
93 # of the video URL, but in some cases, subclasses will want
94 # to override this behavior.
95 def get_video_filename()
96 # Use whatever comes after the final front slash.
97 return get_video_url().split('/').pop()