Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for video data in media record #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Instagram.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Instagram
,Location(..)
,ImageData(..)
,Images(..)
,Videos(..)
,Comment(..)
,Count(..)
,NoResult
Expand Down
27 changes: 25 additions & 2 deletions src/Instagram/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module Instagram.Types (
,Location(..)
,ImageData(..)
,Images(..)
,Videos(..)
,CommentID
,Comment(..)
,Count(..)
Expand Down Expand Up @@ -126,7 +127,7 @@ instance ToJSON User where
, "profile_picture" .= uProfilePicture u
, "website" .= uWebsite u
, "bio" .= uBio u
, "counts" .= uCounts u
, "counts" .= uCounts u
]

-- | from json as per Instagram format
Expand Down Expand Up @@ -276,6 +277,7 @@ data Media = Media {
,mUser :: User
,mCreated :: POSIXTime
,mImages :: Images
,mVideos :: Maybe Videos
,mType :: Text
,mUsersInPhoto :: [UserPosition]
,mFilter :: Maybe Text
Expand All @@ -291,7 +293,7 @@ data Media = Media {
-- | to json as per Instagram format
instance ToJSON Media where
toJSON m=object ["id" .= mID m,"caption" .= mCaption m,"user".= mUser m,"link" .= mLink m, "created_time" .= toJSON (show ((round $ mCreated m) :: Integer))
,"images" .= mImages m,"type" .= mType m,"users_in_photo" .= mUsersInPhoto m, "filter" .= mFilter m,"tags" .= mTags m
,"images" .= mImages m, "videos" .= mVideos m, "type" .= mType m, "users_in_photo" .= mUsersInPhoto m, "filter" .= mFilter m,"tags" .= mTags m
,"location" .= mLocation m,"comments" .= mComments m,"likes" .= mLikes m,"user_has_liked" .= mUserHasLiked m,"attribution" .= mAttribution m]

-- | from json as per Instagram format
Expand All @@ -305,6 +307,7 @@ instance FromJSON Media where
v .: "user" <*>
pure (fromIntegral (read ct::Integer)) <*>
v .: "images" <*>
v .:? "videos" <*>
v .: "type" <*>
v .: "users_in_photo" <*>
v .:? "filter" <*>
Expand Down Expand Up @@ -428,6 +431,26 @@ instance FromJSON Images where
v .: "standard_resolution"
parseJSON _= fail "Images"


type VideoData = ImageData
-- | different images for the same media
data Videos = Videos {
vLowRes :: VideoData
,vStandardRes :: VideoData
}
deriving (Show,Eq,Ord,Typeable)

-- | to json as per Instagram format
instance ToJSON Videos where
toJSON i=object ["low_resolution" .= vLowRes i,"standard_resolution" .= vStandardRes i]

-- | from json as per Instagram format
instance FromJSON Videos where
parseJSON (Object v) = Videos <$>
v .: "low_resolution" <*>
v .: "standard_resolution"
parseJSON _= fail "Videos"

-- | comment id
type CommentID = Text

Expand Down