class BlogAmaraTool: def __init__(self, amara_headers, config_file): self.amara_headers = amara_headers self.amara_tools = AmaraTools(self.amara_headers) self.blog_client = BlogClient(config_file) def post_video_from_blog(self, blogId, postId, language_code): videoId = self.blog_client.extract_video(blogId, postId) lyrics = self.blog_client.retrieve_lyrics(blogId, postId) conv_lyrics = self.amara_tools.convert_to_lyrics(lyrics) amara_id = self.amara_tools.get_video_id( video_url='https://youtu.be/' + videoId, language_code=language_code) amara_video = AmaraVideo(self.amara_headers, amara_id) amara_video.get_actions(language_code) amara_video.post_subtitles(language_code, conv_lyrics) def subtitles_workflow(self, blogId, postId, language_code): self.blog_client.insert_amara_tags(blogId, postId, language_code) self.post_video_from_blog(blogId, postId, language_code)
def show_lyrics(blog_id, post_id, language): blog_client = BlogClient(os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')) video_id = blog_client.extract_video(blog_id, post_id) lyrics = blog_client.retrieve_lyrics(blog_id, post_id) print(video_id) print(lyrics) blog_client.insert_amara_tags(blog_id, post_id, language)
from blogspotapi import BlogClient import os from oauth2client.tools import argparser def show_lyrics(blog_id, post_id, language): blog_client = BlogClient(os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')) video_id = blog_client.extract_video(blog_id, post_id) lyrics = blog_client.retrieve_lyrics(blog_id, post_id) print(video_id) print(lyrics) blog_client.insert_amara_tags(blog_id, post_id, language) if __name__ == "__main__": argparser.add_argument('--blogId') args = argparser.parse_args() blog_client = BlogClient(os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')) blog_id = args.blogId for blog_post in blog_client.iterate_blog_posts(args.blogId): print(blog_post) post_id = blog_post.postId video_id = blog_client.extract_video(blog_id, post_id) lyrics = blog_client.retrieve_lyrics(blog_id, post_id) print(video_id) print(lyrics)
from blogspotapi import BlogClient, BlogPost, BlogRepository from amara.amara_env import amara_headers if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--blogId') parser.add_argument('--mongo_connection', type=str, 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]))
dest='verify_urls', action='store_true') parser.add_argument('--no-verify_urls', dest='verify_urls', action='store_false') parser.set_defaults(update_blogs=True) parser.set_defaults(update_subtitles=True) parser.set_defaults(verify_urls=True) args = parser.parse_args() logging.info( f'Args: update_blogs: {args.update_blogs}, update_subtitles: {args.update_subtitles}, verify_urls: {args.verify_urls}' ) blog_repository = BlogRepository(args.mongo_connection, args.blogId) blog_client = BlogClient( os.path.join(os.path.dirname(__file__), 'client_secrets.json')) youtube_client = YoutubeClient( os.path.join(os.path.dirname(__file__), 'client_secrets.json')) if args.update_blogs: update_blog_collection(blog_repository, blog_client, args.blogId) if args.update_subtitles: update_subtitles_collection(blog_repository, blog_client, args.blogId, args.languages, amara_headers) if args.verify_urls: verify_blog_collection(blog_repository, youtube_client, blog_client, args.blogId) if args.update_blogs: blog_repository.delete_old_posts() if args.update_subtitles: blog_repository.delete_old_subtitles()
from blogspotapi import BlogClient import os import logging import argparse import os from blogspotapi.blog_repository import BlogRepository from amara.amara_env import amara_headers logging.basicConfig(level=logging.DEBUG) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument('--blogId', type=str) parser.add_argument('--postId', type=str) parser.add_argument('--videoUrl', type=str) parser.add_argument('--mongo_connection', type=str, default='mongodb://localhost:27017/musicblogs') parser.set_defaults(update_subtitles=True) args = parser.parse_args() blog_client = BlogClient( os.path.join(os.path.dirname(__file__), '..', 'client_secrets.json')) blog_repository = BlogRepository(args.mongo_connection, args.blogId) blog_repository.invalidate_link(args.postId, args.videoUrl) blog_client.invalidate_post(args.blogId, args.postId)
def __init__(self, amara_headers, config_file): self.amara_headers = amara_headers self.amara_tools = AmaraTools(self.amara_headers) self.blog_client = BlogClient(config_file)