<s> """<STR_LIT>""" <EOL> __author__ = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> try : <EOL> from xml . etree import cElementTree as ElementTree <EOL> except ImportError : <EOL> try : <EOL> import cElementTree as ElementTree <EOL> except ImportError : <EOL> try : <EOL> from xml . etree import ElementTree <EOL> except ImportError : <EOL> from elementtree import ElementTree <EOL> import os <EOL> import atom <EOL> import gdata <EOL> import gdata . service <EOL> import gdata . youtube <EOL> YOUTUBE_SERVER = '<STR_LIT>' <EOL> YOUTUBE_SERVICE = '<STR_LIT>' <EOL> YOUTUBE_CLIENTLOGIN_AUTHENTICATION_URL = '<STR_LIT>' <EOL> YOUTUBE_SUPPORTED_UPLOAD_TYPES = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> YOUTUBE_QUERY_VALID_TIME_PARAMETERS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_QUERY_VALID_RACY_PARAMETERS = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS = ( '<STR_LIT:1>' , '<STR_LIT:5>' , '<STR_LIT>' ) <EOL> YOUTUBE_STANDARDFEEDS = ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> YOUTUBE_UPLOAD_URI = '<STR_LIT>' <EOL> YOUTUBE_UPLOAD_TOKEN_URI = '<STR_LIT>' <EOL> YOUTUBE_VIDEO_URI = '<STR_LIT>' <EOL> YOUTUBE_USER_FEED_URI = '<STR_LIT>' <EOL> YOUTUBE_PLAYLIST_FEED_URI = '<STR_LIT>' <EOL> YOUTUBE_STANDARD_FEEDS = '<STR_LIT>' <EOL> YOUTUBE_STANDARD_TOP_RATED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_MOST_VIEWED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_RECENTLY_FEATURED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_WATCH_ON_MOBILE_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_TOP_FAVORITES_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_MOST_RECENT_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_MOST_DISCUSSED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_MOST_LINKED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_STANDARD_MOST_RESPONDED_URI = '<STR_LIT>' % ( YOUTUBE_STANDARD_FEEDS , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_SCHEMA = '<STR_LIT>' <EOL> YOUTUBE_RATING_LINK_REL = '<STR_LIT>' % YOUTUBE_SCHEMA <EOL> YOUTUBE_COMPLAINT_CATEGORY_SCHEME = '<STR_LIT>' % ( YOUTUBE_SCHEMA , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME = '<STR_LIT>' % ( YOUTUBE_SCHEMA , <EOL> '<STR_LIT>' ) <EOL> YOUTUBE_COMPLAINT_CATEGORY_TERMS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> YOUTUBE_CONTACT_STATUS = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> YOUTUBE_CONTACT_CATEGORY = ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> UNKOWN_ERROR = <NUM_LIT:1000> <EOL> YOUTUBE_BAD_REQUEST = <NUM_LIT> <EOL> YOUTUBE_CONFLICT = <NUM_LIT> <EOL> YOUTUBE_INTERNAL_SERVER_ERROR = <NUM_LIT> <EOL> YOUTUBE_INVALID_ARGUMENT = <NUM_LIT> <EOL> YOUTUBE_INVALID_CONTENT_TYPE = <NUM_LIT> <EOL> YOUTUBE_NOT_A_VIDEO = <NUM_LIT> <EOL> YOUTUBE_INVALID_KIND = <NUM_LIT> <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class RequestError ( Error ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class YouTubeError ( Error ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class YouTubeService ( gdata . service . GDataService ) : <EOL> """<STR_LIT>""" <EOL> ssl = True <EOL> def __init__ ( self , email = None , password = None , source = None , <EOL> server = YOUTUBE_SERVER , additional_headers = None , client_id = None , <EOL> developer_key = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> gdata . service . GDataService . __init__ ( <EOL> self , email = email , password = password , service = YOUTUBE_SERVICE , <EOL> source = source , server = server , additional_headers = additional_headers , <EOL> ** kwargs ) <EOL> if client_id is not None : <EOL> self . additional_headers [ '<STR_LIT>' ] = client_id <EOL> if developer_key is not None : <EOL> self . additional_headers [ '<STR_LIT>' ] = '<STR_LIT>' % developer_key <EOL> self . auth_service_url = YOUTUBE_CLIENTLOGIN_AUTHENTICATION_URL <EOL> def GetYouTubeVideoFeed ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeVideoFeedFromString ) <EOL> def GetYouTubeVideoEntry ( self , uri = None , video_id = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and video_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif video_id and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id ) <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeVideoEntryFromString ) <EOL> def GetYouTubeContactFeed ( self , uri = None , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' ) <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeContactFeedFromString ) <EOL> def GetYouTubeContactEntry ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeContactEntryFromString ) <EOL> def GetYouTubeVideoCommentFeed ( self , uri = None , video_id = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and video_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif video_id and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id , '<STR_LIT>' ) <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeVideoCommentFeedFromString ) <EOL> def GetYouTubeVideoCommentEntry ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeVideoCommentEntryFromString ) <EOL> def GetYouTubeUserFeed ( self , uri = None , username = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and username is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif username and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' ) <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeUserFeedFromString ) <EOL> def GetYouTubeUserEntry ( self , uri = None , username = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and username is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif username and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username ) <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubeUserEntryFromString ) <EOL> def GetYouTubePlaylistFeed ( self , uri = None , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' ) <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubePlaylistFeedFromString ) <EOL> def GetYouTubePlaylistEntry ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( uri , converter = gdata . youtube . YouTubePlaylistEntryFromString ) <EOL> def GetYouTubePlaylistVideoFeed ( self , uri = None , playlist_id = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and playlist_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif playlist_id and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_PLAYLIST_FEED_URI , playlist_id ) <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubePlaylistVideoFeedFromString ) <EOL> def GetYouTubeVideoResponseFeed ( self , uri = None , video_id = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and video_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif video_id and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id , '<STR_LIT>' ) <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeVideoResponseFeedFromString ) <EOL> def GetYouTubeVideoResponseEntry ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeVideoResponseEntryFromString ) <EOL> def GetYouTubeSubscriptionFeed ( self , uri = None , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if uri is None : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' ) <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeSubscriptionFeedFromString ) <EOL> def GetYouTubeSubscriptionEntry ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeSubscriptionEntryFromString ) <EOL> def GetYouTubeRelatedVideoFeed ( self , uri = None , video_id = None ) : <EOL> """<STR_LIT>""" <EOL> if uri is None and video_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif video_id and not uri : <EOL> uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id , '<STR_LIT>' ) <EOL> return self . Get ( <EOL> uri , converter = gdata . youtube . YouTubeVideoFeedFromString ) <EOL> def GetTopRatedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_TOP_RATED_URI ) <EOL> def GetMostViewedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_MOST_VIEWED_URI ) <EOL> def GetRecentlyFeaturedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_RECENTLY_FEATURED_URI ) <EOL> def GetWatchOnMobileVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_WATCH_ON_MOBILE_URI ) <EOL> def GetTopFavoritesVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_TOP_FAVORITES_URI ) <EOL> def GetMostRecentVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_MOST_RECENT_URI ) <EOL> def GetMostDiscussedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_MOST_DISCUSSED_URI ) <EOL> def GetMostLinkedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_MOST_LINKED_URI ) <EOL> def GetMostRespondedVideoFeed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . GetYouTubeVideoFeed ( YOUTUBE_STANDARD_MOST_RESPONDED_URI ) <EOL> def GetUserFavoritesFeed ( self , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> favorites_feed_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , <EOL> '<STR_LIT>' ) <EOL> return self . GetYouTubeVideoFeed ( favorites_feed_uri ) <EOL> def InsertVideoEntry ( self , video_entry , filename_or_handle , <EOL> youtube_username = '<STR_LIT:default>' , <EOL> content_type = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> assert ( isinstance ( video_entry , gdata . youtube . YouTubeVideoEntry ) ) <EOL> except AssertionError : <EOL> raise YouTubeError ( { '<STR_LIT:status>' : YOUTUBE_INVALID_ARGUMENT , <EOL> '<STR_LIT:body>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' % type ( video_entry ) <EOL> } ) <EOL> if ( isinstance ( filename_or_handle , str ) <EOL> and os . path . exists ( filename_or_handle ) ) : <EOL> mediasource = gdata . MediaSource ( ) <EOL> mediasource . setFile ( filename_or_handle , content_type ) <EOL> elif hasattr ( filename_or_handle , '<STR_LIT>' ) : <EOL> import io <EOL> if hasattr ( filename_or_handle , '<STR_LIT>' ) : <EOL> filename_or_handle . seek ( <NUM_LIT:0> ) <EOL> file_handle = filename_or_handle <EOL> name = '<STR_LIT>' <EOL> if hasattr ( filename_or_handle , '<STR_LIT:name>' ) : <EOL> name = filename_or_handle . name <EOL> mediasource = gdata . MediaSource ( file_handle , content_type , <EOL> content_length = file_handle . len , file_name = name ) <EOL> else : <EOL> raise YouTubeError ( { '<STR_LIT:status>' : YOUTUBE_INVALID_ARGUMENT , '<STR_LIT:body>' : <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : ( '<STR_LIT>' <EOL> '<STR_LIT>' % type ( filename_or_handle ) ) } ) <EOL> upload_uri = '<STR_LIT>' % ( YOUTUBE_UPLOAD_URI , youtube_username , <EOL> '<STR_LIT>' ) <EOL> self . additional_headers [ '<STR_LIT>' ] = mediasource . file_name <EOL> try : <EOL> try : <EOL> return self . Post ( video_entry , uri = upload_uri , media_source = mediasource , <EOL> converter = gdata . youtube . YouTubeVideoEntryFromString ) <EOL> except gdata . service . RequestError as e : <EOL> raise YouTubeError ( e . args [ <NUM_LIT:0> ] ) <EOL> finally : <EOL> del ( self . additional_headers [ '<STR_LIT>' ] ) <EOL> def CheckUploadStatus ( self , video_entry = None , video_id = None ) : <EOL> """<STR_LIT>""" <EOL> if video_entry is None and video_id is None : <EOL> raise YouTubeError ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> elif video_id and not video_entry : <EOL> video_entry = self . GetYouTubeVideoEntry ( video_id = video_id ) <EOL> control = video_entry . control <EOL> if control is not None : <EOL> draft = control . draft <EOL> if draft is not None : <EOL> if draft . text == '<STR_LIT:yes>' : <EOL> yt_state = control . extension_elements [ <NUM_LIT:0> ] <EOL> if yt_state is not None : <EOL> state_value = yt_state . attributes [ '<STR_LIT:name>' ] <EOL> message = '<STR_LIT>' <EOL> if yt_state . text is not None : <EOL> message = yt_state . text <EOL> return ( state_value , message ) <EOL> def GetFormUploadToken ( self , video_entry , uri = YOUTUBE_UPLOAD_TOKEN_URI ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> response = self . Post ( video_entry , uri ) <EOL> except gdata . service . RequestError as e : <EOL> raise YouTubeError ( e . args [ <NUM_LIT:0> ] ) <EOL> tree = ElementTree . fromstring ( response ) <EOL> for child in tree : <EOL> if child . tag == '<STR_LIT:url>' : <EOL> post_url = child . text <EOL> elif child . tag == '<STR_LIT>' : <EOL> youtube_token = child . text <EOL> return ( post_url , youtube_token ) <EOL> def UpdateVideoEntry ( self , video_entry ) : <EOL> """<STR_LIT>""" <EOL> for link in video_entry . link : <EOL> if link . rel == '<STR_LIT>' : <EOL> edit_uri = link . href <EOL> return self . Put ( video_entry , uri = edit_uri , <EOL> converter = gdata . youtube . YouTubeVideoEntryFromString ) <EOL> def DeleteVideoEntry ( self , video_entry ) : <EOL> """<STR_LIT>""" <EOL> for link in video_entry . link : <EOL> if link . rel == '<STR_LIT>' : <EOL> edit_uri = link . href <EOL> return self . Delete ( edit_uri ) <EOL> def AddRating ( self , rating_value , video_entry ) : <EOL> """<STR_LIT>""" <EOL> if rating_value < <NUM_LIT:1> or rating_value > <NUM_LIT:5> : <EOL> raise YouTubeError ( '<STR_LIT>' ) <EOL> entry = gdata . GDataEntry ( ) <EOL> rating = gdata . youtube . Rating ( min = '<STR_LIT:1>' , max = '<STR_LIT:5>' ) <EOL> rating . extension_attributes [ '<STR_LIT:name>' ] = '<STR_LIT:value>' <EOL> rating . extension_attributes [ '<STR_LIT:value>' ] = str ( rating_value ) <EOL> entry . extension_elements . append ( rating ) <EOL> for link in video_entry . link : <EOL> if link . rel == YOUTUBE_RATING_LINK_REL : <EOL> rating_uri = link . href <EOL> return self . Post ( entry , uri = rating_uri ) <EOL> def AddComment ( self , comment_text , video_entry ) : <EOL> """<STR_LIT>""" <EOL> content = atom . Content ( text = comment_text ) <EOL> comment_entry = gdata . youtube . YouTubeVideoCommentEntry ( content = content ) <EOL> comment_post_uri = video_entry . comments . feed_link [ <NUM_LIT:0> ] . href <EOL> return self . Post ( comment_entry , uri = comment_post_uri ) <EOL> def AddVideoResponse ( self , video_id_to_respond_to , video_response ) : <EOL> """<STR_LIT>""" <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id_to_respond_to , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( video_response , uri = post_uri ) <EOL> def DeleteVideoResponse ( self , video_id , response_video_id ) : <EOL> """<STR_LIT>""" <EOL> delete_uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id , '<STR_LIT>' , <EOL> response_video_id ) <EOL> return self . Delete ( delete_uri ) <EOL> def AddComplaint ( self , complaint_text , complaint_term , video_id ) : <EOL> """<STR_LIT>""" <EOL> if complaint_term not in YOUTUBE_COMPLAINT_CATEGORY_TERMS : <EOL> raise YouTubeError ( '<STR_LIT>' ) <EOL> content = atom . Content ( text = complaint_text ) <EOL> category = atom . Category ( term = complaint_term , <EOL> scheme = YOUTUBE_COMPLAINT_CATEGORY_SCHEME ) <EOL> complaint_entry = gdata . GDataEntry ( content = content , category = [ category ] ) <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_VIDEO_URI , video_id , '<STR_LIT>' ) <EOL> return self . Post ( complaint_entry , post_uri ) <EOL> def AddVideoEntryToFavorites ( self , video_entry , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' ) <EOL> return self . Post ( video_entry , post_uri , <EOL> converter = gdata . youtube . YouTubeVideoEntryFromString ) <EOL> def DeleteVideoEntryFromFavorites ( self , video_id , username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> edit_link = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , '<STR_LIT>' , <EOL> video_id ) <EOL> return self . Delete ( edit_link ) <EOL> def AddPlaylist ( self , playlist_title , playlist_description , <EOL> playlist_private = None ) : <EOL> """<STR_LIT>""" <EOL> playlist_entry = gdata . youtube . YouTubePlaylistEntry ( <EOL> title = atom . Title ( text = playlist_title ) , <EOL> description = gdata . youtube . Description ( text = playlist_description ) ) <EOL> if playlist_private : <EOL> playlist_entry . private = gdata . youtube . Private ( ) <EOL> playlist_post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , '<STR_LIT:default>' , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( playlist_entry , playlist_post_uri , <EOL> converter = gdata . youtube . YouTubePlaylistEntryFromString ) <EOL> def UpdatePlaylist ( self , playlist_id , new_playlist_title , <EOL> new_playlist_description , playlist_private = None , <EOL> username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> updated_playlist = gdata . youtube . YouTubePlaylistEntry ( <EOL> title = atom . Title ( text = new_playlist_title ) , <EOL> description = gdata . youtube . Description ( text = new_playlist_description ) ) <EOL> if playlist_private : <EOL> updated_playlist . private = gdata . youtube . Private ( ) <EOL> playlist_put_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , username , <EOL> playlist_id ) <EOL> return self . Put ( updated_playlist , playlist_put_uri , <EOL> converter = gdata . youtube . YouTubePlaylistEntryFromString ) <EOL> def DeletePlaylist ( self , playlist_uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Delete ( playlist_uri ) <EOL> def AddPlaylistVideoEntryToPlaylist ( <EOL> self , playlist_uri , video_id , custom_video_title = None , <EOL> custom_video_description = None ) : <EOL> """<STR_LIT>""" <EOL> playlist_video_entry = gdata . youtube . YouTubePlaylistVideoEntry ( <EOL> atom_id = atom . Id ( text = video_id ) ) <EOL> if custom_video_title : <EOL> playlist_video_entry . title = atom . Title ( text = custom_video_title ) <EOL> if custom_video_description : <EOL> playlist_video_entry . description = gdata . youtube . Description ( <EOL> text = custom_video_description ) <EOL> return self . Post ( playlist_video_entry , playlist_uri , <EOL> converter = gdata . youtube . YouTubePlaylistVideoEntryFromString ) <EOL> def UpdatePlaylistVideoEntryMetaData ( <EOL> self , playlist_uri , playlist_entry_id , new_video_title , <EOL> new_video_description , new_video_position ) : <EOL> """<STR_LIT>""" <EOL> playlist_video_entry = gdata . youtube . YouTubePlaylistVideoEntry ( <EOL> title = atom . Title ( text = new_video_title ) , <EOL> description = gdata . youtube . Description ( text = new_video_description ) , <EOL> position = gdata . youtube . Position ( text = str ( new_video_position ) ) ) <EOL> playlist_put_uri = playlist_uri + '<STR_LIT:/>' + playlist_entry_id <EOL> return self . Put ( playlist_video_entry , playlist_put_uri , <EOL> converter = gdata . youtube . YouTubePlaylistVideoEntryFromString ) <EOL> def DeletePlaylistVideoEntry ( self , playlist_uri , playlist_video_entry_id ) : <EOL> """<STR_LIT>""" <EOL> delete_uri = '<STR_LIT>' % ( playlist_uri , playlist_video_entry_id ) <EOL> return self . Delete ( delete_uri ) <EOL> def AddSubscriptionToChannel ( self , username_to_subscribe_to , <EOL> my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> subscription_category = atom . Category ( <EOL> scheme = YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME , <EOL> term = '<STR_LIT>' ) <EOL> subscription_username = gdata . youtube . Username ( <EOL> text = username_to_subscribe_to ) <EOL> subscription_entry = gdata . youtube . YouTubeSubscriptionEntry ( <EOL> category = subscription_category , <EOL> username = subscription_username ) <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( subscription_entry , post_uri , <EOL> converter = gdata . youtube . YouTubeSubscriptionEntryFromString ) <EOL> def AddSubscriptionToFavorites ( self , username , my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> subscription_category = atom . Category ( <EOL> scheme = YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME , <EOL> term = '<STR_LIT>' ) <EOL> subscription_username = gdata . youtube . Username ( text = username ) <EOL> subscription_entry = gdata . youtube . YouTubeSubscriptionEntry ( <EOL> category = subscription_category , <EOL> username = subscription_username ) <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( subscription_entry , post_uri , <EOL> converter = gdata . youtube . YouTubeSubscriptionEntryFromString ) <EOL> def AddSubscriptionToQuery ( self , query , my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> subscription_category = atom . Category ( <EOL> scheme = YOUTUBE_SUBSCRIPTION_CATEGORY_SCHEME , <EOL> term = '<STR_LIT>' ) <EOL> subscription_query_string = gdata . youtube . QueryString ( text = query ) <EOL> subscription_entry = gdata . youtube . YouTubeSubscriptionEntry ( <EOL> category = subscription_category , <EOL> query_string = subscription_query_string ) <EOL> post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( subscription_entry , post_uri , <EOL> converter = gdata . youtube . YouTubeSubscriptionEntryFromString ) <EOL> def DeleteSubscription ( self , subscription_uri ) : <EOL> """<STR_LIT>""" <EOL> return self . Delete ( subscription_uri ) <EOL> def AddContact ( self , contact_username , my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> contact_category = atom . Category ( <EOL> scheme = '<STR_LIT>' , <EOL> term = '<STR_LIT>' ) <EOL> contact_username = gdata . youtube . Username ( text = contact_username ) <EOL> contact_entry = gdata . youtube . YouTubeContactEntry ( <EOL> category = contact_category , <EOL> username = contact_username ) <EOL> contact_post_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' ) <EOL> return self . Post ( contact_entry , contact_post_uri , <EOL> converter = gdata . youtube . YouTubeContactEntryFromString ) <EOL> def UpdateContact ( self , contact_username , new_contact_status , <EOL> new_contact_category , my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> if new_contact_status not in YOUTUBE_CONTACT_STATUS : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> ( '<STR_LIT:U+0020>' . join ( YOUTUBE_CONTACT_STATUS ) ) ) <EOL> if new_contact_category not in YOUTUBE_CONTACT_CATEGORY : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> ( '<STR_LIT:U+0020>' . join ( YOUTUBE_CONTACT_CATEGORY ) ) ) <EOL> contact_category = atom . Category ( <EOL> scheme = '<STR_LIT>' , <EOL> term = new_contact_category ) <EOL> contact_status = gdata . youtube . Status ( text = new_contact_status ) <EOL> contact_entry = gdata . youtube . YouTubeContactEntry ( <EOL> category = contact_category , <EOL> status = contact_status ) <EOL> contact_put_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' , contact_username ) <EOL> return self . Put ( contact_entry , contact_put_uri , <EOL> converter = gdata . youtube . YouTubeContactEntryFromString ) <EOL> def DeleteContact ( self , contact_username , my_username = '<STR_LIT:default>' ) : <EOL> """<STR_LIT>""" <EOL> contact_edit_uri = '<STR_LIT>' % ( YOUTUBE_USER_FEED_URI , my_username , <EOL> '<STR_LIT>' , contact_username ) <EOL> return self . Delete ( contact_edit_uri ) <EOL> def _GetDeveloperKey ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in self . additional_headers : <EOL> return self . additional_headers [ '<STR_LIT>' ] [ <NUM_LIT:4> : ] <EOL> else : <EOL> return None <EOL> def _SetDeveloperKey ( self , developer_key ) : <EOL> """<STR_LIT>""" <EOL> self . additional_headers [ '<STR_LIT>' ] = '<STR_LIT>' + developer_key <EOL> developer_key = property ( _GetDeveloperKey , _SetDeveloperKey , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetClientId ( self ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in self . additional_headers : <EOL> return self . additional_headers [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetClientId ( self , client_id ) : <EOL> """<STR_LIT>""" <EOL> self . additional_headers [ '<STR_LIT>' ] = client_id <EOL> client_id = property ( _GetClientId , _SetClientId , <EOL> doc = """<STR_LIT>""" ) <EOL> def Query ( self , uri ) : <EOL> """<STR_LIT>""" <EOL> result = self . Get ( uri ) <EOL> return result <EOL> def YouTubeQuery ( self , query ) : <EOL> """<STR_LIT>""" <EOL> result = self . Query ( query . ToUri ( ) ) <EOL> if isinstance ( query , YouTubeUserQuery ) : <EOL> return gdata . youtube . YouTubeUserFeedFromString ( result . ToString ( ) ) <EOL> elif isinstance ( query , YouTubePlaylistQuery ) : <EOL> return gdata . youtube . YouTubePlaylistFeedFromString ( result . ToString ( ) ) <EOL> elif isinstance ( query , YouTubeVideoQuery ) : <EOL> return gdata . youtube . YouTubeVideoFeedFromString ( result . ToString ( ) ) <EOL> else : <EOL> return result <EOL> class YouTubeVideoQuery ( gdata . service . Query ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , video_id = None , feed_type = None , text_query = None , <EOL> params = None , categories = None , feed = None ) : <EOL> if feed_type in YOUTUBE_STANDARDFEEDS and feed is None : <EOL> feed = '<STR_LIT>' % ( YOUTUBE_SERVER , feed_type ) <EOL> elif ( feed_type is '<STR_LIT>' or feed_type is '<STR_LIT>' and video_id <EOL> and feed is None ) : <EOL> feed = '<STR_LIT>' % ( YOUTUBE_SERVER , video_id , <EOL> feed_type ) <EOL> elif feed is None : <EOL> feed = '<STR_LIT>' % ( YOUTUBE_SERVER ) <EOL> gdata . service . Query . __init__ ( self , feed , text_query = text_query , <EOL> params = params , categories = categories ) <EOL> def _GetVideoQuery ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetVideoQuery ( self , val ) : <EOL> self [ '<STR_LIT>' ] = val <EOL> vq = property ( _GetVideoQuery , _SetVideoQuery , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetOrderBy ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetOrderBy ( self , val ) : <EOL> if val not in YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS : <EOL> if val . startswith ( '<STR_LIT>' ) is False : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> '<STR_LIT:U+0020>' . join ( YOUTUBE_QUERY_VALID_ORDERBY_PARAMETERS ) ) <EOL> self [ '<STR_LIT>' ] = val <EOL> orderby = property ( _GetOrderBy , _SetOrderBy , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetTime ( self ) : <EOL> if '<STR_LIT:time>' in self : <EOL> return self [ '<STR_LIT:time>' ] <EOL> else : <EOL> return None <EOL> def _SetTime ( self , val ) : <EOL> if val not in YOUTUBE_QUERY_VALID_TIME_PARAMETERS : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> '<STR_LIT:U+0020>' . join ( YOUTUBE_QUERY_VALID_TIME_PARAMETERS ) ) <EOL> self [ '<STR_LIT:time>' ] = val <EOL> time = property ( _GetTime , _SetTime , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetFormat ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetFormat ( self , val ) : <EOL> if val not in YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> '<STR_LIT:U+0020>' . join ( YOUTUBE_QUERY_VALID_FORMAT_PARAMETERS ) ) <EOL> self [ '<STR_LIT>' ] = val <EOL> format = property ( _GetFormat , _SetFormat , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetRacy ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetRacy ( self , val ) : <EOL> if val not in YOUTUBE_QUERY_VALID_RACY_PARAMETERS : <EOL> raise YouTubeError ( '<STR_LIT>' % <EOL> '<STR_LIT:U+0020>' . join ( YOUTUBE_QUERY_VALID_RACY_PARAMETERS ) ) <EOL> self [ '<STR_LIT>' ] = val <EOL> racy = property ( _GetRacy , _SetRacy , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetLanguageRestriction ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetLanguageRestriction ( self , val ) : <EOL> self [ '<STR_LIT>' ] = val <EOL> lr = property ( _GetLanguageRestriction , _SetLanguageRestriction , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetIPRestriction ( self ) : <EOL> if '<STR_LIT>' in self : <EOL> return self [ '<STR_LIT>' ] <EOL> else : <EOL> return None <EOL> def _SetIPRestriction ( self , val ) : <EOL> self [ '<STR_LIT>' ] = val <EOL> restriction = property ( _GetIPRestriction , _SetIPRestriction , <EOL> doc = """<STR_LIT>""" ) <EOL> def _GetLocation ( self ) : <EOL> if '<STR_LIT:location>' in self : <EOL> return self [ '<STR_LIT:location>' ] <EOL> else : <EOL> return None <EOL> def _SetLocation ( self , val ) : <EOL> self [ '<STR_LIT:location>' ] = val <EOL> location = property ( _GetLocation , _SetLocation , <EOL> doc = """<STR_LIT>""" ) <EOL> class YouTubeUserQuery ( YouTubeVideoQuery ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , username = None , feed_type = None , subscription_id = None , <EOL> text_query = None , params = None , categories = None ) : <EOL> uploads_favorites_playlists = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if feed_type is '<STR_LIT>' and subscription_id and username : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER , username , <EOL> feed_type , subscription_id ) <EOL> elif feed_type is '<STR_LIT>' and not subscription_id and username : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER , username , <EOL> feed_type ) <EOL> elif feed_type in uploads_favorites_playlists : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER , username , <EOL> feed_type ) <EOL> else : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER ) <EOL> YouTubeVideoQuery . __init__ ( self , feed = feed , text_query = text_query , <EOL> params = params , categories = categories ) <EOL> class YouTubePlaylistQuery ( YouTubeVideoQuery ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , playlist_id , text_query = None , params = None , <EOL> categories = None ) : <EOL> if playlist_id : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER , playlist_id ) <EOL> else : <EOL> feed = "<STR_LIT>" % ( YOUTUBE_SERVER ) <EOL> YouTubeVideoQuery . __init__ ( self , feed = feed , text_query = text_query , <EOL> params = params , categories = categories ) </s>
