/gdata/youtube/data.py

http://radioappz.googlecode.com/ · Python · 477 lines · 436 code · 20 blank · 21 comment · 6 complexity · 34b472c2eae2b392335a55545a489198 MD5 · raw file

  1. #!/usr/bin/python
  2. #
  3. # Copyright (C) 2009 Google Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """Contains the data classes of the YouTube Data API"""
  17. __author__ = 'j.s@google.com (Jeff Scudder)'
  18. import atom.core
  19. import atom.data
  20. import gdata.data
  21. import gdata.geo.data
  22. import gdata.media.data
  23. import gdata.opensearch.data
  24. import gdata.youtube.data
  25. YT_TEMPLATE = '{http://gdata.youtube.com/schemas/2007/}%s'
  26. class ComplaintEntry(gdata.data.GDEntry):
  27. """Describes a complaint about a video"""
  28. class ComplaintFeed(gdata.data.GDFeed):
  29. """Describes complaints about a video"""
  30. entry = [ComplaintEntry]
  31. class RatingEntry(gdata.data.GDEntry):
  32. """A rating about a video"""
  33. rating = gdata.data.Rating
  34. class RatingFeed(gdata.data.GDFeed):
  35. """Describes ratings for a video"""
  36. entry = [RatingEntry]
  37. class YouTubeMediaContent(gdata.media.data.MediaContent):
  38. """Describes a you tube media content"""
  39. _qname = gdata.media.data.MEDIA_TEMPLATE % 'content'
  40. format = 'format'
  41. class YtAge(atom.core.XmlElement):
  42. """User's age"""
  43. _qname = YT_TEMPLATE % 'age'
  44. class YtBooks(atom.core.XmlElement):
  45. """User's favorite books"""
  46. _qname = YT_TEMPLATE % 'books'
  47. class YtCompany(atom.core.XmlElement):
  48. """User's company"""
  49. _qname = YT_TEMPLATE % 'company'
  50. class YtDescription(atom.core.XmlElement):
  51. """Description"""
  52. _qname = YT_TEMPLATE % 'description'
  53. class YtDuration(atom.core.XmlElement):
  54. """Video duration"""
  55. _qname = YT_TEMPLATE % 'duration'
  56. seconds = 'seconds'
  57. class YtFirstName(atom.core.XmlElement):
  58. """User's first name"""
  59. _qname = YT_TEMPLATE % 'firstName'
  60. class YtGender(atom.core.XmlElement):
  61. """User's gender"""
  62. _qname = YT_TEMPLATE % 'gender'
  63. class YtHobbies(atom.core.XmlElement):
  64. """User's hobbies"""
  65. _qname = YT_TEMPLATE % 'hobbies'
  66. class YtHometown(atom.core.XmlElement):
  67. """User's hometown"""
  68. _qname = YT_TEMPLATE % 'hometown'
  69. class YtLastName(atom.core.XmlElement):
  70. """User's last name"""
  71. _qname = YT_TEMPLATE % 'lastName'
  72. class YtLocation(atom.core.XmlElement):
  73. """Location"""
  74. _qname = YT_TEMPLATE % 'location'
  75. class YtMovies(atom.core.XmlElement):
  76. """User's favorite movies"""
  77. _qname = YT_TEMPLATE % 'movies'
  78. class YtMusic(atom.core.XmlElement):
  79. """User's favorite music"""
  80. _qname = YT_TEMPLATE % 'music'
  81. class YtNoEmbed(atom.core.XmlElement):
  82. """Disables embedding for the video"""
  83. _qname = YT_TEMPLATE % 'noembed'
  84. class YtOccupation(atom.core.XmlElement):
  85. """User's occupation"""
  86. _qname = YT_TEMPLATE % 'occupation'
  87. class YtPlaylistId(atom.core.XmlElement):
  88. """Playlist id"""
  89. _qname = YT_TEMPLATE % 'playlistId'
  90. class YtPosition(atom.core.XmlElement):
  91. """Video position on the playlist"""
  92. _qname = YT_TEMPLATE % 'position'
  93. class YtPrivate(atom.core.XmlElement):
  94. """Flags the entry as private"""
  95. _qname = YT_TEMPLATE % 'private'
  96. class YtQueryString(atom.core.XmlElement):
  97. """Keywords or query string associated with a subscription"""
  98. _qname = YT_TEMPLATE % 'queryString'
  99. class YtRacy(atom.core.XmlElement):
  100. """Mature content"""
  101. _qname = YT_TEMPLATE % 'racy'
  102. class YtRecorded(atom.core.XmlElement):
  103. """Date when the video was recorded"""
  104. _qname = YT_TEMPLATE % 'recorded'
  105. class YtRelationship(atom.core.XmlElement):
  106. """User's relationship status"""
  107. _qname = YT_TEMPLATE % 'relationship'
  108. class YtSchool(atom.core.XmlElement):
  109. """User's school"""
  110. _qname = YT_TEMPLATE % 'school'
  111. class YtStatistics(atom.core.XmlElement):
  112. """Video and user statistics"""
  113. _qname = YT_TEMPLATE % 'statistics'
  114. favorite_count = 'favoriteCount'
  115. video_watch_count = 'videoWatchCount'
  116. view_count = 'viewCount'
  117. last_web_access = 'lastWebAccess'
  118. subscriber_count = 'subscriberCount'
  119. class YtStatus(atom.core.XmlElement):
  120. """Status of a contact"""
  121. _qname = YT_TEMPLATE % 'status'
  122. class YtUserProfileStatistics(YtStatistics):
  123. """User statistics"""
  124. _qname = YT_TEMPLATE % 'statistics'
  125. class YtUsername(atom.core.XmlElement):
  126. """Youtube username"""
  127. _qname = YT_TEMPLATE % 'username'
  128. class FriendEntry(gdata.data.BatchEntry):
  129. """Describes a contact in friend list"""
  130. username = YtUsername
  131. status = YtStatus
  132. email = gdata.data.Email
  133. class FriendFeed(gdata.data.BatchFeed):
  134. """Describes user's friends"""
  135. entry = [FriendEntry]
  136. class YtVideoStatistics(YtStatistics):
  137. """Video statistics"""
  138. _qname = YT_TEMPLATE % 'statistics'
  139. class ChannelEntry(gdata.data.GDEntry):
  140. """Describes a video channel"""
  141. class ChannelFeed(gdata.data.GDFeed):
  142. """Describes channels"""
  143. entry = [ChannelEntry]
  144. class FavoriteEntry(gdata.data.BatchEntry):
  145. """Describes a favorite video"""
  146. class FavoriteFeed(gdata.data.BatchFeed):
  147. """Describes favorite videos"""
  148. entry = [FavoriteEntry]
  149. class YouTubeMediaCredit(gdata.media.data.MediaCredit):
  150. """Describes a you tube media credit"""
  151. _qname = gdata.media.data.MEDIA_TEMPLATE % 'credit'
  152. type = 'type'
  153. class YouTubeMediaRating(gdata.media.data.MediaRating):
  154. """Describes a you tube media rating"""
  155. _qname = gdata.media.data.MEDIA_TEMPLATE % 'rating'
  156. country = 'country'
  157. class YtAboutMe(atom.core.XmlElement):
  158. """User's self description"""
  159. _qname = YT_TEMPLATE % 'aboutMe'
  160. class UserProfileEntry(gdata.data.BatchEntry):
  161. """Describes an user's profile"""
  162. relationship = YtRelationship
  163. description = YtDescription
  164. location = YtLocation
  165. statistics = YtUserProfileStatistics
  166. school = YtSchool
  167. music = YtMusic
  168. first_name = YtFirstName
  169. gender = YtGender
  170. occupation = YtOccupation
  171. hometown = YtHometown
  172. company = YtCompany
  173. movies = YtMovies
  174. books = YtBooks
  175. username = YtUsername
  176. about_me = YtAboutMe
  177. last_name = YtLastName
  178. age = YtAge
  179. thumbnail = gdata.media.data.MediaThumbnail
  180. hobbies = YtHobbies
  181. class UserProfileFeed(gdata.data.BatchFeed):
  182. """Describes a feed of user's profile"""
  183. entry = [UserProfileEntry]
  184. class YtAspectRatio(atom.core.XmlElement):
  185. """The aspect ratio of a media file"""
  186. _qname = YT_TEMPLATE % 'aspectRatio'
  187. class YtBasePublicationState(atom.core.XmlElement):
  188. """Status of an unpublished entry"""
  189. _qname = YT_TEMPLATE % 'state'
  190. help_url = 'helpUrl'
  191. class YtPublicationState(YtBasePublicationState):
  192. """Status of an unpublished video"""
  193. _qname = YT_TEMPLATE % 'state'
  194. name = 'name'
  195. reason_code = 'reasonCode'
  196. class YouTubeAppControl(atom.data.Control):
  197. """Describes a you tube app control"""
  198. _qname = (atom.data.APP_TEMPLATE_V1 % 'control',
  199. atom.data.APP_TEMPLATE_V2 % 'control')
  200. state = YtPublicationState
  201. class YtCaptionPublicationState(YtBasePublicationState):
  202. """Status of an unpublished caption track"""
  203. _qname = YT_TEMPLATE % 'state'
  204. reason_code = 'reasonCode'
  205. name = 'name'
  206. class YouTubeCaptionAppControl(atom.data.Control):
  207. """Describes a you tube caption app control"""
  208. _qname = atom.data.APP_TEMPLATE_V2 % 'control'
  209. state = YtCaptionPublicationState
  210. class CaptionTrackEntry(gdata.data.GDEntry):
  211. """Describes a caption track"""
  212. class CaptionTrackFeed(gdata.data.GDFeed):
  213. """Describes caption tracks"""
  214. entry = [CaptionTrackEntry]
  215. class YtCountHint(atom.core.XmlElement):
  216. """Hint as to how many entries the linked feed contains"""
  217. _qname = YT_TEMPLATE % 'countHint'
  218. class PlaylistLinkEntry(gdata.data.BatchEntry):
  219. """Describes a playlist"""
  220. description = YtDescription
  221. playlist_id = YtPlaylistId
  222. count_hint = YtCountHint
  223. private = YtPrivate
  224. class PlaylistLinkFeed(gdata.data.BatchFeed):
  225. """Describes list of playlists"""
  226. entry = [PlaylistLinkEntry]
  227. class YtModerationStatus(atom.core.XmlElement):
  228. """Moderation status"""
  229. _qname = YT_TEMPLATE % 'moderationStatus'
  230. class YtPlaylistTitle(atom.core.XmlElement):
  231. """Playlist title"""
  232. _qname = YT_TEMPLATE % 'playlistTitle'
  233. class SubscriptionEntry(gdata.data.BatchEntry):
  234. """Describes user's channel subscritpions"""
  235. count_hint = YtCountHint
  236. playlist_title = YtPlaylistTitle
  237. thumbnail = gdata.media.data.MediaThumbnail
  238. username = YtUsername
  239. query_string = YtQueryString
  240. playlist_id = YtPlaylistId
  241. class SubscriptionFeed(gdata.data.BatchFeed):
  242. """Describes list of user's video subscriptions"""
  243. entry = [SubscriptionEntry]
  244. class YtSpam(atom.core.XmlElement):
  245. """Indicates that the entry probably contains spam"""
  246. _qname = YT_TEMPLATE % 'spam'
  247. class CommentEntry(gdata.data.BatchEntry):
  248. """Describes a comment for a video"""
  249. spam = YtSpam
  250. class CommentFeed(gdata.data.BatchFeed):
  251. """Describes comments for a video"""
  252. entry = [CommentEntry]
  253. class YtUploaded(atom.core.XmlElement):
  254. """Date/Time at which the video was uploaded"""
  255. _qname = YT_TEMPLATE % 'uploaded'
  256. class YtVideoId(atom.core.XmlElement):
  257. """Video id"""
  258. _qname = YT_TEMPLATE % 'videoid'
  259. class YouTubeMediaGroup(gdata.media.data.MediaGroup):
  260. """Describes a you tube media group"""
  261. _qname = gdata.media.data.MEDIA_TEMPLATE % 'group'
  262. videoid = YtVideoId
  263. private = YtPrivate
  264. duration = YtDuration
  265. aspect_ratio = YtAspectRatio
  266. uploaded = YtUploaded
  267. class VideoEntryBase(gdata.data.GDEntry):
  268. """Elements that describe or contain videos"""
  269. group = YouTubeMediaGroup
  270. statistics = YtVideoStatistics
  271. racy = YtRacy
  272. recorded = YtRecorded
  273. where = gdata.geo.data.GeoRssWhere
  274. rating = gdata.data.Rating
  275. noembed = YtNoEmbed
  276. location = YtLocation
  277. comments = gdata.data.Comments
  278. class PlaylistEntry(gdata.data.BatchEntry):
  279. """Describes a video in a playlist"""
  280. description = YtDescription
  281. position = YtPosition
  282. class PlaylistFeed(gdata.data.BatchFeed):
  283. """Describes videos in a playlist"""
  284. private = YtPrivate
  285. group = YouTubeMediaGroup
  286. playlist_id = YtPlaylistId
  287. entry = [PlaylistEntry]
  288. class VideoEntry(gdata.data.BatchEntry):
  289. """Describes a video"""
  290. class VideoFeed(gdata.data.BatchFeed):
  291. """Describes a video feed"""
  292. entry = [VideoEntry]
  293. class VideoMessageEntry(gdata.data.BatchEntry):
  294. """Describes a video message"""
  295. description = YtDescription
  296. class VideoMessageFeed(gdata.data.BatchFeed):
  297. """Describes videos in a videoMessage"""
  298. entry = [VideoMessageEntry]
  299. class UserEventEntry(gdata.data.GDEntry):
  300. """Describes a user event"""
  301. playlist_id = YtPlaylistId
  302. videoid = YtVideoId
  303. username = YtUsername
  304. query_string = YtQueryString
  305. rating = gdata.data.Rating
  306. class UserEventFeed(gdata.data.GDFeed):
  307. """Describes list of events"""
  308. entry = [UserEventEntry]
  309. class VideoModerationEntry(gdata.data.GDEntry):
  310. """Describes video moderation"""
  311. moderation_status = YtModerationStatus
  312. videoid = YtVideoId
  313. class VideoModerationFeed(gdata.data.GDFeed):
  314. """Describes a video moderation feed"""
  315. entry = [VideoModerationEntry]