Modules in the miro package namespace located in portable/ in the source tarball that contain utility functions and classes.
miro.commandline – This modules handles the parsing of files/URLs passed to Miro on the command line.
Frontends should call set_ommand_line_args() passing it a list of arguments that the users gives. This should just be suspected torrents/videos, not things like --help, --version, etc.
Frontends should trap when a user opens a torrent/video with Miro while Miro is already running. They should arrange for add_video or add_torrent to be called in the existing Miro process.
This goes through a list of files which could be arguments passed in on the command line or a list of files from other source.
If the args list is None, then this pulls from the internal _command_line_args list which is populated by set_command_line_args.
miro.displaytext – Format strings to send to the user.
Convert the value return by strftime() to a unicode string.
By default, it’s in whatever the default codeset is.
miro.filetypes - functions for determining things from the filename, enclosure, content-type, and other things.
Sniffs the body to determine whether it’s a feed or not.
this is very loosely taken from Firefox nsFeedSniffer.cpp and ideas in http://blogs.msdn.com/rssteam/articles/PublishersGuide.aspx
miro.flashscraper – functions for converting a web-page url to a media url.
Returns whether or not the given url is possibly handled by one of the flash url converters we have.
Example:
>>> is_maybe_flashscrapable(u"http://www.youtube.com/watch?v=qRuNxHqwazs")
True
miro.gtcache – Caching gettext functions.
Takes the return from a gettext call, and “declarifies” it. If the item has | symbols in it, then this splits the string on | and returns the last string. If the item has no | symbols in it, then it returns the string.
>>> declarify("foo")
'foo'
>>> declarify("View|All")
'All'
Returns a unicode string.
Returns the translated form of the given text. If values are provided, expands the string with the given values.
In the case where the translated string is improperly formed and throws a ValueError when expanded, this caches and returns the original text. This reduces the likelihood that Miro will throw an error and stop functioning with bad translated strings.
For example, if the string is:
"%(countfiles) fichiers analyses"
^^^
the d is missing.
Note
This converts unicode strings to strings in utf-8 encoding before translating. This definitely slows things down, so if you don’t need unicode characters, use a string and not a unicode.
Returns a unicode string.
Given two strings and a count.
See Python gettext.ngettext documentation and the GNU gettext documentation for more details.
http://www.gnu.org/software/gettext/manual/gettext.html#Plural-forms
Returns a unicode string.
miro.subscription – Functions for handling subscriptions.
This file handles checking URLs that the user clicks on to see if they are subscribe links. Subscribe links are specially formatted URLs that signal that we should subscribe the user to a feed, add a new channel guide, start a new video download, or something similar.
Our basic strategy is to have have links with the host subscribe.getmiro.com. That way we can parse them in miro and have an actual page on subscribe.getmiro.com that the user will see if they click it in an actual web browser.
This class represents the common functionality of the subscription handlers (OPML import, one-click links in the Guide, and command-line additions).
We loop through the list of subscriptions, creating things as we go (if needed). We also keep track of what we’ve added.
Each type (folder, feed, site, download) gets dispatched to one of our methods. Each dispatcher returns True if it’s added the subscription, anything else if it’s been ignored for some reason (generally because it’s already present in the DB).
The only exception to this is the ‘folder’ type, which has the same return signature as this method.
Returns a tuple of dictionaries (added, ignored). Each dictionary maps a subscription type (feed, site, download) to the number of added/ignored items in this subscription.
Download subscriptions look like:
{
'type': 'download',
'url': URL of the file to download
'title': name of the download (optional),
'link': page representing this download (optional),
'feed': RSS feed containing this item (optional),
'mime_type': the MIME type of the item (optional),
'description': a description of the item (optional),
'thumbnail': a thumbnail image for the item (optional),
'length': the length in seconds of the item (optional)
}
Feed subscriptions look like:
{
'type': 'feed',
'url': URL of the RSS/Atom feed
'title': name of the feed (optional),
'section': one of ['audio', 'video'] (ignored if it's in a folder),
'search_term': terms for which this feed is a search (optional),
'auto_download': one of 'all', 'new', 'off' (optional),
'expiry_time': one of 'system', 'never', an integer of hours (optional),
}
Folder subscriptions look like:
{
'type': 'folder',
'title': name of the folder,
'section': one of ['audio', 'video'],
'children': a list of sub-feeds
}
Site subscriptions look like:
{
'type': 'site',
'url': URL of the site
'title': name of the site (optional),
}
Returns whether this is a subscribe url or not.
It’s pretty hearty and shouldn’t throw exceptions.
miro.util – Utility functions.
This module contains self-contained utility functions. It shouldn’t import any other Miro modules.
Strips html from text while maintaining links and newline-like HTML bits.
This class resets itself after every strip call, so you can re-use the class if you want. However, this class is not threadsafe.
2 Dimensional matrix.
Matrix objects are accessed like a list, except tuples are used as indices, for example:
>>> m = Matrix(5, 5)
>>> m[3, 4] = "foo"
>>> m
None, None, None, None, None
None, None, None, None, None
None, None, None, None, None
None, None, None, None, None
None, None, None, 'foo', None
Implements a counter that can be access by multiple threads.
Converts a string to lower case, using a simple translations of ASCII characters.
This method is not locale-dependant, which is useful in some cases. Normally str.lower() should be used though.
Gather media files on the disk in a directory tree. This is used by the first time startup dialog.
path – absolute file path to search
Create a pair of sockets connected to each other on the local interface. Used to implement SocketHandler.wakeup().
On Unixish systems, port 0 will pick the next available port. But that appears to have problems on Windows possibly with firewall software. So if we hit a socketerror with port 0, we try ports between 50000 and 65500.
Called at build-time to ask Subversion for the revision number of this checkout. Going to fail without Cygwin. Yeah, oh well. Pass the file or directory you want to use as a reference point.
Returns the (url, revision) on success and None on failure.
Parse a configuration file in a very simple format and return contents as a dict.
Each line is either whitespace or “Key = Value”. Whitespace is ignored at the beginning of Value, but the remainder of the line is taken literally, including any whitespace.
Note: There is no way to put a newline in a value.
Takes a possibly unicode string and converts it to a string string. This is required for some logging especially where the things being logged are filenames which can be Unicode in the Windows platform.
You can pass in a handleerror argument which defaults to "xmlcharrefreplace". This will increase the string size as it converts unicode characters that don’t have ascii equivalents into escape sequences. If you don’t want to increase the string length, use "replace" which will use ? for unicode characters that don’t have ascii equivalents.
Note
This is not the inverse of unicodify!
miro.xhtmltools – XML related utility functions.
Very simple parser to convert HTML to XHTML
Adds a <meta http-equiv=”Content-Type” content=”text/html; charset=blah”> tag to an HTML document
Since we’re only feeding this to our own HTML Parser anyway, we don’t care that it might bung up XHTML.