types.nim 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import times, sequtils, options
  2. import norm/sqlite
  3. import prefs_impl
  4. export sqlite, options
  5. type
  6. VideoType* = enum
  7. vmap, m3u8, mp4
  8. db("cache.db", "", "", ""):
  9. type
  10. Profile* = object
  11. username*: string
  12. fullname*: string
  13. location*: string
  14. website*: string
  15. bio*: string
  16. userpic*: string
  17. banner*: string
  18. following*: string
  19. followers*: string
  20. tweets*: string
  21. likes*: string
  22. media*: string
  23. verified*: bool
  24. protected*: bool
  25. joinDate* {.
  26. dbType: "INTEGER"
  27. parseIt: it.i.fromUnix()
  28. formatIt: dbValue(it.toUnix())
  29. .}: Time
  30. updated* {.
  31. dbType: "INTEGER"
  32. parseIt: it.i.fromUnix()
  33. formatIt: dbValue(getTime().toUnix())
  34. .}: Time
  35. Video* = object
  36. videoId*: string
  37. contentId*: string
  38. durationMs*: int
  39. url*: string
  40. thumb*: string
  41. views*: string
  42. available*: bool
  43. playbackType* {.
  44. dbType: "STRING"
  45. parseIt: parseEnum[VideoType](it.s)
  46. formatIt: dbValue($it)
  47. .}: VideoType
  48. Prefs* = object
  49. hlsPlayback*: bool
  50. mp4Playback*: bool
  51. proxyVideos*: bool
  52. muteVideos*: bool
  53. autoplayGifs*: bool
  54. hideTweetStats*: bool
  55. hideBanner*: bool
  56. stickyProfile*: bool
  57. replaceYouTube*: string
  58. replaceTwitter*: string
  59. type
  60. QueryKind* = enum
  61. replies, media, multi, custom = "search"
  62. Query* = object
  63. kind*: QueryKind
  64. filters*: seq[string]
  65. includes*: seq[string]
  66. excludes*: seq[string]
  67. fromUser*: seq[string]
  68. sep*: string
  69. Gif* = object
  70. url*: string
  71. thumb*: string
  72. GalleryPhoto* = object
  73. url*: string
  74. tweetId*: string
  75. color*: string
  76. Poll* = object
  77. options*: seq[string]
  78. values*: seq[int]
  79. votes*: string
  80. status*: string
  81. leader*: int
  82. CardKind* = enum
  83. summary = "summary"
  84. summaryLarge = "summary_large_image"
  85. promoWebsite = "promo_website"
  86. promoVideo = "promo_video_website"
  87. player = "player"
  88. liveEvent = "live_event"
  89. Card* = object
  90. kind*: CardKind
  91. id*: string
  92. query*: string
  93. url*: string
  94. title*: string
  95. dest*: string
  96. text*: string
  97. image*: Option[string]
  98. video*: Option[Video]
  99. Quote* = object
  100. id*: string
  101. profile*: Profile
  102. text*: string
  103. reply*: seq[string]
  104. hasThread*: bool
  105. sensitive*: bool
  106. available*: bool
  107. thumb*: string
  108. badge*: string
  109. Retweet* = object
  110. by*: string
  111. id*: string
  112. TweetStats* = object
  113. replies*: string
  114. retweets*: string
  115. likes*: string
  116. Tweet* = ref object
  117. id*: string
  118. threadId*: string
  119. profile*: Profile
  120. text*: string
  121. time*: Time
  122. shortTime*: string
  123. reply*: seq[string]
  124. pinned*: bool
  125. available*: bool
  126. hasThread*: bool
  127. stats*: TweetStats
  128. retweet*: Option[Retweet]
  129. quote*: Option[Quote]
  130. card*: Option[Card]
  131. gif*: Option[Gif]
  132. video*: Option[Video]
  133. photos*: seq[string]
  134. poll*: Option[Poll]
  135. Thread* = ref object
  136. tweets*: seq[Tweet]
  137. more*: int
  138. Conversation* = ref object
  139. tweet*: Tweet
  140. before*: Thread
  141. after*: Thread
  142. replies*: seq[Thread]
  143. Timeline* = ref object
  144. tweets*: seq[Tweet]
  145. minId*: string
  146. maxId*: string
  147. hasMore*: bool
  148. beginning*: bool
  149. query*: Option[Query]
  150. Config* = ref object
  151. address*: string
  152. port*: int
  153. useHttps*: bool
  154. title*: string
  155. staticDir*: string
  156. cacheDir*: string
  157. profileCacheTime*: int
  158. proc contains*(thread: Thread; tweet: Tweet): bool =
  159. thread.tweets.anyIt(it.id == tweet.id)