default='mongodb://localhost:27017/musicblogs')
    args = parser.parse_args()
    channelsDict = dict()
    client_secrets_file = os.path.join(os.path.dirname(__file__),
                                       'client_secrets.json')
    youtube_client = YoutubeClient(client_secrets_file)
    blog_client = BlogClient(client_secrets_file)
    blog_repository = BlogRepository(args.mongo_connection, args.blogId,
                                     amara_headers)
    blogId = args.blogId
    for post_id, blog_post in blog_repository.posts_map.items():
        try:
            videoId = blog_post.videoId
            print('Found video ' + videoId)
            youtube_client.like_video(videoId)
            channelId = youtube_client.get_channel_id(videoId)
            print('Found channel ' + channelId)
            if not channelId in channelsDict:
                channelsDict[channelId] = 0
            channelsDict[channelId] = channelsDict[channelId] + 1
            print('Found channel ' + channelId + ':' +
                  str(channelsDict[channelId]))
        except HttpError as e:
            print("An HTTP error %d occurred:\n%s" %
                  (e.resp.status, e.content))
        except Exception as e:
            traceback.print_exc()
        else:
            print('Liked video ' + videoId)

    sorted_channels = sorted(channelsDict.items(),
Пример #2
0
from youtube3 import YoutubeClient
from oauth2client.tools import argparser
import os

if __name__ == "__main__":
    argparser.add_argument('--videoId')
    args = argparser.parse_args()
    if args.videoId == None:
        print("required argument --videoId <videoId>")
    else:
        youtube = YoutubeClient(
            os.path.join(os.path.dirname(__file__), 'client_secrets.json'))
        videoInfo = youtube.get_video(args.videoId)
        video_snippet = youtube.get_video_snippet(args.videoId)
        channelId = youtube.get_channel_id(args.videoId)

        print(videoInfo['items'][0]['snippet'])
        print(video_snippet)
        relatedVideos = youtube.get_related_videos(args.videoId)
        print(videoInfo)
        print(channelId)
        print(relatedVideos)