def post(self): self.parser.add_argument( 'url', type=inputs.regex(CONSTANTS.YOUTUBE_URL_REGEX), help='Url is required', required=True ) self.parser.add_argument( 'type', help='Type is required', required=True ) args = self.parser.parse_args() videoId = args['url'].split('watch?v=')[1] r = requests.get(buildYoutubeQueryURL(videoId)) response = r.json() if len(response['items']) == 0: return buildResponse('Video not found', 404) youtubeDetails = response['items'][0] #At the time of this development the youtube API does not work properly to the embeddable property if not youtubeDetails['status']['embeddable']: return buildResponse('Video is not embeddable', 400) print youtubeDetails['snippet']['title'] music = MusicModel() music.title = youtubeDetails['snippet']['title'] music.description = youtubeDetails['snippet']['description'] music.channel_title = youtubeDetails['snippet']['channelTitle'] music.type = args['type'] music.video_id = videoId music.save() return buildResponse('', 201)
def post(self): self.parser.add_argument('url', type=inputs.regex( CONSTANTS.YOUTUBE_URL_REGEX), help='Url is required', required=True) self.parser.add_argument('type', help='Type is required', required=True) args = self.parser.parse_args() videoId = args['url'].split('watch?v=')[1] r = requests.get(buildYoutubeQueryURL(videoId)) response = r.json() if len(response['items']) == 0: return buildResponse('Video not found', 404) youtubeDetails = response['items'][0] #At the time of this development the youtube API does not work properly to the embeddable property if not youtubeDetails['status']['embeddable']: return buildResponse('Video is not embeddable', 400) print youtubeDetails['snippet']['title'] music = MusicModel() music.title = youtubeDetails['snippet']['title'] music.description = youtubeDetails['snippet']['description'] music.channel_title = youtubeDetails['snippet']['channelTitle'] music.type = args['type'] music.video_id = videoId music.save() return buildResponse('', 201)
def generateMusic(url): music = MusicModel() music.type = 'YOUTUBE' music.url = url music.save()