本文整理汇总了Python中helpers.media_helper.MediaParser.partial_media_dict_from_url方法的典型用法代码示例。如果您正苦于以下问题:Python MediaParser.partial_media_dict_from_url方法的具体用法?Python MediaParser.partial_media_dict_from_url怎么用?Python MediaParser.partial_media_dict_from_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.media_helper.MediaParser
的用法示例。
在下文中一共展示了MediaParser.partial_media_dict_from_url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_youtube_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_youtube_parse(self):
yt_long = MediaParser.partial_media_dict_from_url("http://www.youtube.com/watch?v=I-IrVbsl_K8")
self.assertEqual(yt_long["media_type_enum"], MediaType.YOUTUBE)
self.assertEqual(yt_long["foreign_key"], "I-IrVbsl_K8")
yt_short = MediaParser.partial_media_dict_from_url("http://youtu.be/I-IrVbsl_K8")
self.assertEqual(yt_short["media_type_enum"], MediaType.YOUTUBE)
self.assertEqual(yt_short["foreign_key"], "I-IrVbsl_K8")
示例2: test_imgur_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_imgur_parse(self):
imgur_img = MediaParser.partial_media_dict_from_url("http://imgur.com/zYqWbBh")
self.assertEqual(imgur_img['media_type_enum'], MediaType.IMGUR)
self.assertEqual(imgur_img['foreign_key'], "zYqWbBh")
imgur_img = MediaParser.partial_media_dict_from_url("http://i.imgur.com/zYqWbBh.png")
self.assertEqual(imgur_img['media_type_enum'], MediaType.IMGUR)
self.assertEqual(imgur_img['foreign_key'], "zYqWbBh")
self.assertEqual(MediaParser.partial_media_dict_from_url("http://imgur.com/r/aww"), None)
self.assertEqual(MediaParser.partial_media_dict_from_url("http://imgur.com/a/album"), None)
示例3: test_youtube_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_youtube_parse(self):
yt_long = MediaParser.partial_media_dict_from_url("http://www.youtube.com/watch?v=I-IrVbsl_K8")
self.assertEqual(yt_long['media_type_enum'], MediaType.YOUTUBE_VIDEO)
self.assertEqual(yt_long['foreign_key'], "I-IrVbsl_K8")
yt_short = MediaParser.partial_media_dict_from_url("http://youtu.be/I-IrVbsl_K8")
self.assertEqual(yt_short['media_type_enum'], MediaType.YOUTUBE_VIDEO)
self.assertEqual(yt_short['foreign_key'], "I-IrVbsl_K8")
yt_from_playlist = MediaParser.partial_media_dict_from_url("https://www.youtube.com/watch?v=VP992UKFbko&index=1&list=PLZT9pIgNOV6ZE0EgstWeoRWGWT3uoaszm")
self.assertEqual(yt_from_playlist['media_type_enum'], MediaType.YOUTUBE_VIDEO)
self.assertEqual(yt_from_playlist['foreign_key'], 'VP992UKFbko')
示例4: test_youtube_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_youtube_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://www.youtube.com/user/Uberbots1124")
self.assertEqual(result['media_type_enum'], MediaType.YOUTUBE_CHANNEL)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'uberbots1124')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.YOUTUBE_CHANNEL])
self.assertEqual(result['profile_url'], 'https://www.youtube.com/user/uberbots1124')
short_result = MediaParser.partial_media_dict_from_url("https://www.youtube.com/Uberbots1124")
self.assertEqual(short_result['media_type_enum'], MediaType.YOUTUBE_CHANNEL)
self.assertEqual(short_result['is_social'], True)
self.assertEqual(short_result['foreign_key'], 'uberbots1124')
self.assertEqual(short_result['site_name'], MediaType.type_names[MediaType.YOUTUBE_CHANNEL])
self.assertEqual(short_result['profile_url'], 'https://www.youtube.com/user/uberbots1124')
示例5: createTeamMediaSuggestion
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def createTeamMediaSuggestion(cls, author_account_key, media_url, team_key, year_str):
"""Create a Team Media Suggestion. Returns status (success, exists, bad_url)"""
media_dict = MediaParser.partial_media_dict_from_url(media_url)
if media_dict is not None:
existing_media = Media.get_by_id(Media.render_key_name(media_dict['media_type_enum'], media_dict['foreign_key']))
if existing_media is None or team_key not in [reference.id() for reference in existing_media.references]:
foreign_type = Media.SLUG_NAMES[media_dict['media_type_enum']]
suggestion_id = Suggestion.render_key_name(year_str, 'team', team_key, foreign_type, media_dict['foreign_key'])
suggestion = Suggestion.get_by_id(suggestion_id)
if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
media_dict['year'] = int(year_str)
media_dict['reference_type'] = 'team'
media_dict['reference_key'] = team_key
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_model="media",
)
suggestion.contents = media_dict
suggestion.put()
return 'success'
else:
return 'suggestion_exists'
else:
return 'media_exists'
else:
return 'bad_url'
示例6: test_snapchat_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_snapchat_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://www.snapchat.com/add/evolution2626")
self.assertEqual(result['media_type_enum'], MediaType.SNAPCHAT_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'evolution2626')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.SNAPCHAT_PROFILE])
self.assertEqual(result['profile_url'], 'https://www.snapchat.com/add/evolution2626')
示例7: test_twitter_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_twitter_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://twitter.com/team1124")
self.assertEqual(result['media_type_enum'], MediaType.TWITTER_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'team1124')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.TWITTER_PROFILE])
self.assertEqual(result['profile_url'], 'https://twitter.com/team1124')
示例8: test_github_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_github_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://github.com/frc1124")
self.assertEqual(result['media_type_enum'], MediaType.GITHUB_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'frc1124')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.GITHUB_PROFILE])
self.assertEqual(result['profile_url'], 'https://github.com/frc1124')
示例9: createEventMediaSuggestion
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def createEventMediaSuggestion(cls, author_account_key, media_url, event_key, private_details_json=None):
"""Create an Event Media Suggestion. Returns status (success, suggestion_exists, media_exists, bad_url)"""
media_dict = MediaParser.partial_media_dict_from_url(media_url)
if media_dict is not None:
if media_dict['media_type_enum'] != MediaType.YOUTUBE_VIDEO:
return 'bad_url', None
existing_media = Media.get_by_id(Media.render_key_name(media_dict['media_type_enum'], media_dict['foreign_key']))
if existing_media is None or event_key not in [reference.id() for reference in existing_media.references]:
foreign_type = Media.SLUG_NAMES[media_dict['media_type_enum']]
suggestion_id = Suggestion.render_media_key_name(event_key[:4], 'event', event_key, foreign_type, media_dict['foreign_key'])
suggestion = Suggestion.get_by_id(suggestion_id)
if not suggestion or suggestion.review_state != Suggestion.REVIEW_PENDING:
media_dict['year'] = event_key[:4]
media_dict['reference_type'] = 'event'
media_dict['reference_key'] = event_key
target_model = 'event_media'
if private_details_json is not None:
media_dict['private_details_json'] = private_details_json
suggestion = Suggestion(
id=suggestion_id,
author=author_account_key,
target_model=target_model,
)
suggestion.contents = media_dict
suggestion.put()
return 'success', suggestion
else:
return 'suggestion_exists', None
else:
return 'media_exists', None
else:
return 'bad_url', None
示例10: test_fb_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_fb_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("http://facebook.com/theuberbots")
self.assertEqual(result['media_type_enum'], MediaType.FACEBOOK_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'theuberbots')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.FACEBOOK_PROFILE])
self.assertEqual(result['profile_url'], 'https://www.facebook.com/theuberbots')
示例11: test_twitch_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_twitch_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://www.twitch.tv/evolution2626")
self.assertEqual(result['media_type_enum'], MediaType.TWITCH_CHANNEL)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'evolution2626')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.TWITCH_CHANNEL])
self.assertEqual(result['profile_url'], 'https://www.twitch.tv/evolution2626')
示例12: test_instagram_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_instagram_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://www.instagram.com/4hteamneutrino")
self.assertEqual(result['media_type_enum'], MediaType.INSTAGRAM_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], '4hteamneutrino')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.INSTAGRAM_PROFILE])
self.assertEqual(result['profile_url'], 'https://www.instagram.com/4hteamneutrino')
示例13: test_periscope_profile_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_periscope_profile_parse(self):
result = MediaParser.partial_media_dict_from_url("https://www.periscope.tv/evolution2626")
self.assertEqual(result['media_type_enum'], MediaType.PERISCOPE_PROFILE)
self.assertEqual(result['is_social'], True)
self.assertEqual(result['foreign_key'], 'evolution2626')
self.assertEqual(result['site_name'], MediaType.type_names[MediaType.PERISCOPE_PROFILE])
self.assertEqual(result['profile_url'], 'https://www.periscope.tv/evolution2626')
示例14: test_cdphotothread_parse
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_cdphotothread_parse(self):
cd = MediaParser.partial_media_dict_from_url("https://www.chiefdelphi.com/media/photos/41999")
self.assertEqual(cd['media_type_enum'], MediaType.CD_PHOTO_THREAD)
self.assertEqual(cd['foreign_key'], "41999")
self.assertTrue(cd['details_json'])
details = json.loads(cd['details_json'])
self.assertEqual(details['image_partial'], "a88/a880fa0d65c6b49ddb93323bc7d2e901_l.jpg")
示例15: test_instagram_image
# 需要导入模块: from helpers.media_helper import MediaParser [as 别名]
# 或者: from helpers.media_helper.MediaParser import partial_media_dict_from_url [as 别名]
def test_instagram_image(self):
result = MediaParser.partial_media_dict_from_url("https://www.instagram.com/p/BUnZiriBYre/")
self.assertEqual(result['media_type_enum'], MediaType.INSTAGRAM_IMAGE)
self.assertEqual(result['foreign_key'], "BUnZiriBYre")
details = json.loads(result['details_json'])
self.assertEqual(details['title'], "FRC 195 @ 2017 Battlecry @ WPI")
self.assertEqual(details['author_name'], '1stroboticsrocks')
self.assertIsNotNone(details.get('thumbnail_url', None))