Copyright | (c) 2019-2021 Sam May |
---|---|
License | GPL-3.0-or-later |
Maintainer | ag@eitilt.life |
Stability | stable |
Portability | non-portable (requires libcdio) |
Safe Haskell | None |
Language | Haskell2010 |
Sound.Libcdio.Read.CdText
Contents
Description
Metadata is stored in a binary format both library-internally and on the disc.
Most audio archivists will recognize it as "those information fields in a CUE
file" (though there are other
formats
as well), and casual listeners will recognize it as the scrolling text that
you're always happy to see, on the rare times your music player shows it.
Little-used and even-less-known, however, is that a single disc can
theoretically contain metadata in up to eight different languages; because of
the complexity that introduces, it makes more sense to use a second monadic
interface than to try to provide a single monolithic datatype within Cdio
.
Synopsis
- data CdText a
- data CdTextError = CdTextError CdTextErrorType Text
- data CdTextErrorType
- data Info = Info {}
- emptyInfo :: Info
- data Genre
- data Language
- = UnknownLanguage
- | Albanian
- | Breton
- | Catalan
- | Croatian
- | Welsh
- | Czech
- | Danish
- | German
- | English
- | Spanish
- | Esperanto
- | Estonian
- | Basque
- | Faroese
- | French
- | Frisian
- | Irish
- | Gaelic
- | Galician
- | Icelandic
- | Italian
- | Lappish
- | Latin
- | Latvian
- | Luxembourgian
- | Lithuanian
- | Hungarian
- | Maltese
- | Dutch
- | Norwegian
- | Occitan
- | Polish
- | Portuguese
- | Romanian
- | Romansh
- | Serbian
- | Slovak
- | Slovenian
- | Finnish
- | Swedish
- | Turkish
- | Flemish
- | Wallon
- | Zulu
- | Vietnamese
- | Uzbek
- | Urdu
- | Ukrainian
- | Thai
- | Telugu
- | Tatar
- | Tamil
- | Tadzhik
- | Swahili
- | SrananTongo
- | Somali
- | Sinhalese
- | Shona
- | SerboCroatian
- | Ruthenian
- | Russian
- | Quechua
- | Pushtu
- | Punjabi
- | Persian
- | Papamiento
- | Oriya
- | Nepali
- | Ndebele
- | Marathi
- | Moldavian
- | Malaysian
- | Malagasay
- | Macedonian
- | Laotian
- | Korean
- | Khmer
- | Kazakh
- | Kannada
- | Japanese
- | Indonesian
- | Hindi
- | Hebrew
- | Hausa
- | Gurani
- | Gujurati
- | Greek
- | Georgian
- | Fulani
- | Dari
- | Churash
- | Chinese
- | Burmese
- | Bulgarian
- | Bengali
- | Bielorussian
- | Bambora
- | Azerbaijani
- | Assamese
- | Armenian
- | Arabic
- | Amharic
- cdText :: CdText a -> Cdio (Either CdTextError a)
- parseCdText :: ByteString -> CdText a -> IO (Either CdTextError a)
- withLanguage :: Language -> CdText a -> CdText a
- withIndex :: Word -> CdText a -> CdText a
- withAll :: CdText a -> CdText [Maybe a]
- runCdText :: Cdio -> CdText a -> IO (Either CdTextError a)
- language :: CdText Language
- languages :: Cdio [Maybe Language]
- firstTrack :: CdText Track
- lastTrack :: CdText Track
- info :: Maybe Track -> CdText Info
- discId :: CdText (Maybe Text)
- genre :: CdText (Maybe Genre, Maybe Text)
- cdTextRaw :: Cdio (Maybe ByteString)
Types
A computation within the environment of metadata (in a particular language) stored on a CD. The options for affecting that environment from within are limited by design, as this library is intended for reading discs rather than authoring them.
Instances
Monad CdText # | |
Functor CdText # | |
MonadFail CdText # | Wraps the text in a |
Defined in Sound.Libcdio.Read.CdText | |
Applicative CdText # | |
Alternative CdText # |
|
LibcdioLogger CdText # | |
MonadError CdTextError CdText # | |
Defined in Sound.Libcdio.Read.CdText Methods throwError :: CdTextError -> CdText a # catchError :: CdText a -> (CdTextError -> CdText a) -> CdText a # |
data CdTextError #
Associates a well-typed error with human-readable context information.
Constructors
CdTextError CdTextErrorType Text |
Instances
Eq CdTextError # | |
Defined in Sound.Libcdio.Read.CdText | |
Read CdTextError # | |
Defined in Sound.Libcdio.Read.CdText Methods readsPrec :: Int -> ReadS CdTextError # readList :: ReadS [CdTextError] # readPrec :: ReadPrec CdTextError # readListPrec :: ReadPrec [CdTextError] # | |
Show CdTextError # | |
Defined in Sound.Libcdio.Read.CdText Methods showsPrec :: Int -> CdTextError -> ShowS # show :: CdTextError -> String # showList :: [CdTextError] -> ShowS # | |
MonadError CdTextError CdText # | |
Defined in Sound.Libcdio.Read.CdText Methods throwError :: CdTextError -> CdText a # catchError :: CdText a -> (CdTextError -> CdText a) -> CdText a # |
data CdTextErrorType #
Potential situations which may cause a computation to fail.
Constructors
InvalidBlock Word | The requested language index is outside of the bounds accessible
by the library ( |
LanguageNotFound Language | The CdText data does not contain the requested language, or
|
BadBinaryRead | The binary data can not be parsed into a CdText object. |
NoCdText | The CD contains no CdText data. |
CdTextEmpty |
|
FreeformCdTextError Text | Escape hatch from structured typing to allow user-specified (and user-triggered) errors. |
Instances
Eq CdTextErrorType # | |
Defined in Sound.Libcdio.Read.CdText Methods (==) :: CdTextErrorType -> CdTextErrorType -> Bool # (/=) :: CdTextErrorType -> CdTextErrorType -> Bool # | |
Read CdTextErrorType # | |
Defined in Sound.Libcdio.Read.CdText Methods readsPrec :: Int -> ReadS CdTextErrorType # readList :: ReadS [CdTextErrorType] # | |
Show CdTextErrorType # | |
Defined in Sound.Libcdio.Read.CdText Methods showsPrec :: Int -> CdTextErrorType -> ShowS # show :: CdTextErrorType -> String # showList :: [CdTextErrorType] -> ShowS # |
Textual metadata describing a single track on a disc, or the disc itself.
Constructors
Info | |
Genres recognized in the CD Text standard.
Constructors
Written languages recognized in the CD Text standard.
Constructors
Instances
Bounded Language # | |
Enum Language # | |
Defined in Foreign.Libcdio.Types.Enums | |
Eq Language # | |
Ord Language # | |
Defined in Foreign.Libcdio.Types.Enums | |
Read Language # | |
Show Language # | |
Evaluation
parseCdText :: ByteString -> CdText a -> IO (Either CdTextError a) #
Given a binary stream, attempt to parse it as a CdText block and run the
given computation. Returns
if that parse fails.
At this top level, a Left
BadBinaryRead
specifically will almost always have
the same effect as running the computation directly.withIndex
0
Note that binary CdText dumps will frequently include four bytes at the
beginning indicating the size of the file; this implementation expects that
those bytes are not included. If your dump does indeed begin with them,
before passing the drop
4ByteString
to this function.
Before libcdio 0.94: Always returns Left
BadBinaryRead
withLanguage :: Language -> CdText a -> CdText a #
Try to use a specific language as the context for the given computation;
as this will frequently fail with LanguageNotFound
if given anything other
than English
, it is recommended that you provide a fallback with
<|>
or at least allow recovery with optional
. Note that
UnknownLanguage
will always fail.
withIndex :: Word -> CdText a -> CdText a #
Run the given computation over the data in a specific block. Fails with
InvalidBlock
if the index can't be accessed.
withAll :: CdText a -> CdText [Maybe a] #
Run the given computation over all of the accessible languages in the
CdText data. When successful, the resulting list can be associated exactly
with the list of languages
:
>>>
ls <- 'languages'
>>>
Right ls' <- 'cdText' $ 'withAll' 'language'
>>>
ls == ls'
True
runCdText :: Cdio -> CdText a -> IO (Either CdTextError a) #
Use a C-style Cdio
object as the base to run a Haskell-style
CdText
computation.
Note that some invariants of the monadic interface may not work as expected when used with the mutable objects, usually due to changing the active language block:
l <-language
cdio _ <-runCdText
cdio $withIndex
i g l' <-language
cdio (l == l') == undefined
Data
languages :: Cdio [Maybe Language] #
List every language with associated data in the CdText data associated
with the session. Drops any UnknownLanguage
values from the end
of the list. For a version which operates within the CdText
monad, the
construction
will have an identical effect.withAll
language
Before libcdio 2.1.0: Silently drops any Nothing
or
values, even in the middle of the list,
and only lists any single language a maximum of one time.Just
UnknownLanguage
firstTrack :: CdText Track #
The earliest track with any associated metadata in the current language.
Note that this may differ from minTrack
which gives
the first track on the disk, CDTEXT or not.
The final track with any associated metadata in the current language.
Note that this may differ from maxTrack
which gives
the last track on the disc, CDTEXT or not.
info :: Maybe Track -> CdText Info #
Retrieve the collection of data associated with a specific track, or if
Nothing
, the disc itself.
genre :: CdText (Maybe Genre, Maybe Text) #
The genre describing the music on this disc, and any associated human-readable name or subgenre.
cdTextRaw :: Cdio (Maybe ByteString) #
Get the raw binary data making up the CdText data, if any exists on the disc.