module Network.RTorrent.Torrent
( TorrentInfo (..)
, TorrentId (..)
, TorrentAction
, start
, close
, erase
, checkHash
, getTorrent
, getTorrents
, allTorrents
, setTorrentPriority
, getTorrentPriority
, getTorrentId
, getTorrentOpen
, getTorrentUpRate
, getTorrentDownRate
, getTorrentSizeBytes
, getTorrentLeftBytes
, getTorrentName
, getTorrentPath
, getTorrentDir
, setTorrentDir
, getTorrentRatio
, getTorrentFileCount
)
where
import Control.Applicative
import Control.DeepSeq
import Network.XmlRpc.Internals
import Network.RTorrent.Action.Internals
import Network.RTorrent.Priority
newtype TorrentId = TorrentId String
deriving Show
type TorrentAction = Action TorrentId
instance NFData TorrentId where
rnf (TorrentId str) = rnf str
instance XmlRpcType TorrentId where
toValue (TorrentId s) = ValueString s
fromValue v = return . TorrentId =<< fromValue v
getType _ = TString
data TorrentInfo = TorrentInfo {
torrentId :: TorrentId
, torrentName :: String
, torrentOpen :: !Bool
, torrentDownRate :: !Int
, torrentUpRate :: !Int
, torrentSize :: !Int
, torrentBytesLeft :: !Int
, torrentPath :: String
, torrentDir :: String
, torrentTorrentPriority :: !TorrentPriority
} deriving Show
instance NFData TorrentInfo where
rnf (TorrentInfo i a0 a1 a2 a3 a4 a5 a6 a7 a8) =
rnf i `seq`
rnf a0 `seq`
rnf a1 `seq`
rnf a2 `seq`
rnf a3 `seq`
rnf a4 `seq`
rnf a5 `seq`
rnf a6 `seq`
rnf a7 `seq`
rnf a8
getTorrent :: TorrentId -> TorrentAction TorrentInfo
getTorrent = runActionB $ TorrentInfo
<$> b getTorrentId
<*> b getTorrentName
<*> b getTorrentOpen
<*> b getTorrentDownRate
<*> b getTorrentUpRate
<*> b getTorrentSizeBytes
<*> b getTorrentLeftBytes
<*> b getTorrentPath
<*> b getTorrentDir
<*> b getTorrentPriority
where
b = ActionB
start :: TorrentId -> TorrentAction Int
start = simpleAction "d.start" []
close :: TorrentId -> TorrentAction Int
close = simpleAction "d.close" []
erase :: TorrentId -> TorrentAction Int
erase = simpleAction "d.erase" []
checkHash :: TorrentId -> TorrentAction Int
checkHash = simpleAction "d.check_hash" []
setTorrentPriority :: TorrentPriority -> TorrentId -> TorrentAction Int
setTorrentPriority pr = simpleAction "d.priority.set" [PTorrentPriority pr]
getTorrentId :: TorrentId -> TorrentAction TorrentId
getTorrentId = simpleAction "d.hash" []
getTorrentName :: TorrentId -> TorrentAction String
getTorrentName = simpleAction "d.get_name" []
getTorrentPath :: TorrentId -> TorrentAction String
getTorrentPath = simpleAction "d.get_base_path" []
getTorrentDir :: TorrentId -> TorrentAction String
getTorrentDir = simpleAction "d.get_directory" []
setTorrentDir :: String -> TorrentId -> TorrentAction Int
setTorrentDir dir = simpleAction "d.set_directory" [PString dir]
getTorrentOpen :: TorrentId -> TorrentAction Bool
getTorrentOpen = fmap toEnum . simpleAction "d.is_open" []
getTorrentUpRate :: TorrentId -> TorrentAction Int
getTorrentUpRate = simpleAction "d.get_up_rate" []
getTorrentDownRate :: TorrentId -> TorrentAction Int
getTorrentDownRate = simpleAction "d.get_down_rate" []
getTorrentSizeBytes :: TorrentId -> TorrentAction Int
getTorrentSizeBytes = simpleAction "d.get_size_bytes" []
getTorrentLeftBytes :: TorrentId -> TorrentAction Int
getTorrentLeftBytes = simpleAction "d.get_left_bytes" []
getTorrentPriority :: TorrentId -> TorrentAction TorrentPriority
getTorrentPriority = simpleAction "d.priority" []
getTorrentRatio :: TorrentId -> TorrentAction Int
getTorrentRatio = simpleAction "d.get_ratio" []
getTorrentFileCount :: TorrentId -> TorrentAction Int
getTorrentFileCount = simpleAction "d.get_size_files" []
allTorrents :: (TorrentId -> TorrentAction a) -> AllAction TorrentId a
allTorrents = AllAction (TorrentId "") "d.multicall"
getTorrents :: AllAction TorrentId TorrentInfo
getTorrents = allTorrents getTorrent