├── .gitignore ├── cli ├── .rspec ├── .bundle │ └── config ├── bin │ ├── radicaster │ ├── setup │ ├── console │ └── rspec ├── Gemfile ├── lib │ ├── cli │ │ ├── s3.rb │ │ ├── lambda.rb │ │ ├── eventbridge.rb │ │ ├── handler.rb │ │ ├── execution_schedule.rb │ │ └── definition.rb │ └── cli.rb ├── spec │ ├── s3_spec.rb │ ├── lambda_spec.rb │ ├── eventbridge_spec.rb │ ├── execution_schedule_spec.rb │ ├── spec_helper.rb │ └── definition_spec.rb ├── Guardfile └── Gemfile.lock ├── rec_radiko ├── .dockerignore ├── .rspec ├── .bundle │ └── config ├── lib │ ├── rec-radiko │ │ ├── version.rb │ │ ├── combined_schedule_item.rb │ │ ├── episode.rb │ │ ├── schedule.rb │ │ ├── recorder.rb │ │ ├── ffmpeg.rb │ │ ├── s3.rb │ │ ├── radigo.rb │ │ ├── handler.rb │ │ ├── schedule_item.rb │ │ └── definition.rb │ └── rec-radiko.rb ├── bin │ ├── setup │ └── console ├── Gemfile ├── spec │ ├── ffmpeg_spec.rb │ ├── combined_schedule_item_spec.rb │ ├── s3_spec.rb │ ├── schedule_spec.rb │ ├── radigo_spec.rb │ ├── schedule_item_spec.rb │ ├── recorder_spec.rb │ ├── spec_helper.rb │ └── definition_spec.rb ├── function.rb ├── Rakefile ├── Dockerfile └── Gemfile.lock ├── gen_feed ├── .rspec ├── .bundle │ └── config ├── lib │ ├── gen-feed │ │ ├── version.rb │ │ ├── feed_generator.rb │ │ ├── definition.rb │ │ ├── episode.rb │ │ ├── templates │ │ │ └── podcast.xml.erb │ │ ├── handler.rb │ │ └── s3.rb │ └── gen-feed.rb ├── bin │ ├── setup │ └── console ├── Gemfile ├── Dockerfile ├── function.rb ├── Rakefile ├── Gemfile.lock └── spec │ ├── feed_generator_spec.rb │ ├── s3_spec.rb │ └── spec_helper.rb ├── radicaster.png ├── deployment ├── .npmignore ├── .gitignore ├── jest.config.js ├── test │ └── deployment.test.ts ├── README.md ├── tsconfig.json ├── cdk.json ├── package.json ├── bin │ └── deployment.ts ├── assets │ └── basic_auth │ │ └── function.js └── lib │ └── radicaster-stack.ts ├── .env.example ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | *.env 2 | vendor/ 3 | -------------------------------------------------------------------------------- /cli/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /rec_radiko/.dockerignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | -------------------------------------------------------------------------------- /gen_feed/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /rec_radiko/.rspec: -------------------------------------------------------------------------------- 1 | --require spec_helper 2 | -------------------------------------------------------------------------------- /cli/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_PATH: "vendor/bundle/" 3 | -------------------------------------------------------------------------------- /gen_feed/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_BIN: "vendor/bin" 3 | -------------------------------------------------------------------------------- /rec_radiko/.bundle/config: -------------------------------------------------------------------------------- 1 | --- 2 | BUNDLE_BIN: "vendor/bin" 3 | -------------------------------------------------------------------------------- /radicaster.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mtmtcode/radicaster/HEAD/radicaster.png -------------------------------------------------------------------------------- /deployment/.npmignore: -------------------------------------------------------------------------------- 1 | *.ts 2 | !*.d.ts 3 | 4 | # CDK asset staging directory 5 | .cdk.staging 6 | cdk.out 7 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/version.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module GenFeed 3 | VERSION = "0.1.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/version.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | VERSION = "0.1.0" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /deployment/.gitignore: -------------------------------------------------------------------------------- 1 | !jest.config.js 2 | *.d.ts 3 | node_modules 4 | 5 | # CDK asset staging directory 6 | .cdk.staging 7 | cdk.out 8 | -------------------------------------------------------------------------------- /cli/bin/radicaster: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift "./lib" 4 | 5 | require "bundler/setup" 6 | require "cli" 7 | 8 | Radicaster::CLI.main($*) 9 | -------------------------------------------------------------------------------- /cli/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /gen_feed/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /rec_radiko/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /deployment/jest.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | testEnvironment: 'node', 3 | roots: ['/test'], 4 | testMatch: ['**/*.test.ts'], 5 | transform: { 6 | '^.+\\.tsx?$': 'ts-jest' 7 | } 8 | }; 9 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed.rb: -------------------------------------------------------------------------------- 1 | require "gen-feed/definition" 2 | require "gen-feed/episode" 3 | require "gen-feed/feed_generator" 4 | require "gen-feed/handler" 5 | require "gen-feed/s3" 6 | require "gen-feed/version" 7 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/feed_generator.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module GenFeed 3 | class FeedGenerator 4 | def generate(definition, episodes) 5 | open(Pathname.new(__FILE__).join("../templates/podcast.xml.erb").expand_path) do |f| 6 | ERB.new(f.read).result(binding) 7 | end 8 | end 9 | end 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /gen_feed/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | git_source(:github) do |repo_name| 4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 | "https://github.com/#{repo_name}.git" 6 | end 7 | 8 | ruby "~> 2.7.0" 9 | 10 | gem "rake", "~> 12.0" 11 | gem "aws-sdk-s3" 12 | gem "rspec", "~> 3.0" 13 | gem "rspec-its" 14 | gem "rspec-parameterized" 15 | gem "rspec-mocks" 16 | -------------------------------------------------------------------------------- /rec_radiko/Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | git_source(:github) do |repo_name| 4 | repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5 | "https://github.com/#{repo_name}.git" 6 | end 7 | 8 | ruby "~> 2.7.0" 9 | 10 | gem "rake", "~> 12.0" 11 | gem "aws-sdk-s3" 12 | gem "rspec", "~> 3.0" 13 | gem "rspec-its" 14 | gem "rspec-parameterized" 15 | gem "rspec-mocks" 16 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko.rb: -------------------------------------------------------------------------------- 1 | require "rec-radiko/combined_schedule_item" 2 | require "rec-radiko/definition" 3 | require "rec-radiko/episode" 4 | require "rec-radiko/ffmpeg" 5 | require "rec-radiko/handler" 6 | require "rec-radiko/radigo" 7 | require "rec-radiko/recorder" 8 | require "rec-radiko/s3" 9 | require "rec-radiko/schedule" 10 | require "rec-radiko/schedule_item" 11 | require "rec-radiko/version" 12 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/definition.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module GenFeed 3 | # Podcastの定義 4 | class Definition 5 | attr_reader :title, :author, :summary, :image 6 | 7 | def initialize(title:, author: nil, summary: nil, image: nil) 8 | @title = title 9 | @author = author 10 | @summary = summary 11 | @image = image 12 | end 13 | end 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/episode.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module GenFeed 3 | class Episode 4 | attr_reader :url, :size, :last_modified 5 | 6 | def initialize(url:, size:, last_modified:) 7 | @url = url 8 | @size = size 9 | @last_modified = last_modified 10 | end 11 | 12 | def title 13 | url.split("/")[-1] 14 | end 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /cli/bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift "./lib" 4 | 5 | require "bundler/setup" 6 | require "cli" 7 | 8 | # You can add fixtures and/or initialization code here to make experimenting 9 | # with your gem easier. You can also use a different console, if you like. 10 | 11 | # (If you use this, don't forget to add pry to your Gemfile!) 12 | # require "pry" 13 | # Pry.start 14 | 15 | require "irb" 16 | IRB.start(__FILE__) 17 | -------------------------------------------------------------------------------- /gen_feed/bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift "./lib" 4 | 5 | require "bundler/setup" 6 | require "gen-feed" 7 | 8 | # You can add fixtures and/or initialization code here to make experimenting 9 | # with your gem easier. You can also use a different console, if you like. 10 | 11 | # (If you use this, don't forget to add pry to your Gemfile!) 12 | # require "pry" 13 | # Pry.start 14 | 15 | require "irb" 16 | IRB.start(__FILE__) 17 | -------------------------------------------------------------------------------- /rec_radiko/bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | $:.unshift "./lib" 4 | 5 | require "bundler/setup" 6 | require "rec-radiko" 7 | 8 | # You can add fixtures and/or initialization code here to make experimenting 9 | # with your gem easier. You can also use a different console, if you like. 10 | 11 | # (If you use this, don't forget to add pry to your Gemfile!) 12 | # require "pry" 13 | # Pry.start 14 | 15 | require "irb" 16 | IRB.start(__FILE__) 17 | -------------------------------------------------------------------------------- /gen_feed/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazon/aws-lambda-ruby:2.7 AS bundler 2 | WORKDIR /var/task 3 | RUN yum groupinstall -y "Development Tools" 4 | COPY ./Gemfile ./Gemfile 5 | COPY ./Gemfile.lock ./Gemfile.lock 6 | RUN bundle install --path=vendor/bundle 7 | 8 | 9 | FROM amazon/aws-lambda-ruby:2.7 10 | WORKDIR /var/task 11 | 12 | ENV TZ=Asia/Tokyo 13 | 14 | COPY --from=bundler /var/task/vendor ./vendor 15 | COPY ./ ./ 16 | 17 | CMD ["function.Handler.handle"] 18 | -------------------------------------------------------------------------------- /cli/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source "https://rubygems.org" 4 | 5 | git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } 6 | 7 | ruby "~> 2.7.0" 8 | 9 | gem "aws-sdk-s3" 10 | gem "aws-sdk-eventbridge" 11 | gem "aws-sdk-lambda" 12 | 13 | group :development, :test do 14 | gem "rspec", "~> 3.0" 15 | gem "rspec-its" 16 | gem "rspec-parameterized" 17 | gem "rspec-mocks" 18 | gem "guard-rspec", require: false 19 | end 20 | -------------------------------------------------------------------------------- /cli/lib/cli/s3.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::CLI 2 | class S3 3 | def initialize(client, bucket) 4 | @client = client 5 | @bucket = bucket 6 | end 7 | 8 | def save_definition(def_) 9 | client.put_object( 10 | bucket: bucket, 11 | key: "#{def_.id}/radicaster.yaml", 12 | body: StringIO.new(def_.to_yaml), 13 | ) 14 | end 15 | 16 | private 17 | 18 | attr_reader :client, :bucket 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /deployment/test/deployment.test.ts: -------------------------------------------------------------------------------- 1 | import { expect as expectCDK, matchTemplate, MatchStyle } from '@aws-cdk/assert'; 2 | import * as cdk from '@aws-cdk/core'; 3 | import * as Deployment from '../lib/deployment-stack'; 4 | 5 | test('Empty Stack', () => { 6 | const app = new cdk.App(); 7 | // WHEN 8 | const stack = new Deployment.RadicasterStack(app, 'MyTestStack'); 9 | // THEN 10 | expectCDK(stack).to(matchTemplate({ 11 | "Resources": {} 12 | }, MatchStyle.EXACT)) 13 | }); 14 | -------------------------------------------------------------------------------- /cli/lib/cli/lambda.rb: -------------------------------------------------------------------------------- 1 | require "aws-sdk-eventbridge" 2 | 3 | module Radicaster 4 | module CLI 5 | class Lambda 6 | attr_reader :client, :rec_radiko_arn 7 | 8 | def initialize(client, rec_radiko_arn) 9 | @client = client 10 | @rec_radiko_arn = rec_radiko_arn 11 | end 12 | 13 | def record_latest(def_) 14 | client.invoke( 15 | function_name: rec_radiko_arn, 16 | payload: %Q/{"id": "#{def_.id}"}/, 17 | ) 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/combined_schedule_item.rb: -------------------------------------------------------------------------------- 1 | require "date" 2 | 3 | module Radicaster 4 | module RecRadiko 5 | class CombinedScheduleItem 6 | attr_reader :elements 7 | 8 | def initialize(*elements) 9 | @elements = elements 10 | end 11 | 12 | def ==(other) 13 | return false unless other.is_a?(self.class) 14 | elements == other.elements 15 | end 16 | 17 | def latest(now) 18 | elements.map { |x| x.latest(now) } 19 | end 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/episode.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | class Episode 4 | attr_reader :id, :station, :start_time, :local_path 5 | 6 | def initialize(id:, station:, start_time:, local_path:) 7 | @id = id 8 | @start_time = start_time 9 | @local_path = local_path 10 | end 11 | 12 | def ==(other) 13 | return false unless other.is_a? Episode 14 | id == other.id && start_time = other.start_time && local_path == other.local_path 15 | end 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /deployment/README.md: -------------------------------------------------------------------------------- 1 | # Welcome to your CDK TypeScript project! 2 | 3 | This is a blank project for TypeScript development with CDK. 4 | 5 | The `cdk.json` file tells the CDK Toolkit how to execute your app. 6 | 7 | ## Useful commands 8 | 9 | * `npm run build` compile typescript to js 10 | * `npm run watch` watch for changes and compile 11 | * `npm run test` perform the jest unit tests 12 | * `cdk deploy` deploy this stack to your default AWS account/region 13 | * `cdk diff` compare deployed stack with current state 14 | * `cdk synth` emits the synthesized CloudFormation template 15 | -------------------------------------------------------------------------------- /gen_feed/function.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.dirname(__FILE__) + "/lib") 2 | 3 | require "logger" 4 | require "gen-feed" 5 | require "aws-sdk-s3" 6 | 7 | logger = Logger.new(STDOUT) 8 | 9 | bucket = ENV["RADICASTER_S3_BUCKET"] or raise "ENV['RADICASTER_S3_BUCKET'] must be set" 10 | url = ENV["RADICASTER_BUCKET_URL"] or raise "ENV['RADICASTER_BUCKET_URL'] must be set" 11 | 12 | s3_client = Aws::S3::Client.new 13 | storage = Radicaster::GenFeed::S3.new(s3_client, bucket, url) 14 | 15 | generator = Radicaster::GenFeed::FeedGenerator.new 16 | 17 | Handler = Radicaster::GenFeed::Handler.new(logger, storage, generator) 18 | -------------------------------------------------------------------------------- /rec_radiko/spec/ffmpeg_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe Ffmpeg do 3 | describe "#concat" do 4 | let(:paths) { 5 | [ 6 | "/path/to/1.aac", 7 | "/path/to/2.aac", 8 | ] 9 | } 10 | subject(:concater) { Ffmpeg.new() } 11 | it "concats passed files and returns result's path" do 12 | # NOTE: ffmpegでconcatっぽいことをしていればOK 13 | expect(concater).to receive(:system).with(/\Affmpeg.*\Wconcat\W/, exception: true) 14 | ret = concater.concat(paths) 15 | expect(ret).to eq("/path/to/1.m4a") 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/schedule.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | class Schedule 4 | attr_reader :items 5 | 6 | def initialize(*items) 7 | @items = items 8 | end 9 | 10 | def ==(other) 11 | return false unless other.is_a? Schedule 12 | items == other.items 13 | end 14 | 15 | def latest(now) 16 | # 各itemをlatestを取得して、最初の要素が直近のものを返す 17 | items.map { |x| 18 | latest = x.latest(now) 19 | latest.is_a?(Array) ? latest : [latest] 20 | } 21 | .sort { |a, b| a[0] <=> b[0] } 22 | .last 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /deployment/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "ES2018", 4 | "module": "commonjs", 5 | "lib": ["es2018"], 6 | "declaration": true, 7 | "strict": true, 8 | "noImplicitAny": true, 9 | "strictNullChecks": true, 10 | "noImplicitThis": true, 11 | "alwaysStrict": true, 12 | "noUnusedLocals": false, 13 | "noUnusedParameters": false, 14 | "noImplicitReturns": true, 15 | "noFallthroughCasesInSwitch": false, 16 | "inlineSourceMap": true, 17 | "inlineSources": true, 18 | "experimentalDecorators": true, 19 | "strictPropertyInitialization": false, 20 | "typeRoots": ["./node_modules/@types"] 21 | }, 22 | "exclude": ["cdk.out"] 23 | } 24 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/recorder.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | class Recorder 4 | def initialize(radiko, concater) 5 | @radiko = radiko 6 | @concater = concater 7 | end 8 | 9 | def rec(def_, now) 10 | start_times = def_.latest_start_times(now) 11 | paths = start_times.map { |st| radiko.rec(def_.area, def_.station, st) } 12 | concated_path = concater.concat(paths) 13 | 14 | Episode.new( 15 | id: def_.id, 16 | station: def_.station, 17 | start_time: start_times[0], 18 | local_path: concated_path, 19 | ) 20 | end 21 | 22 | private 23 | 24 | attr_reader :radiko, :concater 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /rec_radiko/function.rb: -------------------------------------------------------------------------------- 1 | $LOAD_PATH.unshift(File.dirname(__FILE__) + "/lib") 2 | 3 | require "logger" 4 | require "rec-radiko" 5 | require "aws-sdk-s3" 6 | 7 | logger = Logger.new(STDOUT) 8 | 9 | radigo_home = "/tmp" 10 | radiko_mail = ENV["RADICASTER_RADIKO_MAIL"] 11 | radiko_password = ENV["RADICASTER_RADIKO_PASSWORD"] 12 | radiko = Radicaster::RecRadiko::Radigo.new(radigo_home, radiko_mail, radiko_password) 13 | concater = Radicaster::RecRadiko::Ffmpeg.new 14 | recorder = Radicaster::RecRadiko::Recorder.new(radiko, concater) 15 | 16 | bucket = ENV["RADICASTER_S3_BUCKET"] or raise "ENV['RADICASTER_S3_BUCKET'] must be set" 17 | s3 = Aws::S3::Client.new 18 | storage = Radicaster::RecRadiko::S3.new(s3, bucket) 19 | 20 | Handler = Radicaster::RecRadiko::Handler.new(logger, recorder, storage) 21 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/ffmpeg.rb: -------------------------------------------------------------------------------- 1 | require "tempfile" 2 | 3 | module Radicaster 4 | module RecRadiko 5 | class Ffmpeg 6 | def concat(aac_paths) 7 | # NOTE: 8 | # ffmpegでファイルを連結するには元ファイルのリストを書いたテキストを 9 | # 入力ファイルとして食わせる必要がある 10 | # https://trac.ffmpeg.org/wiki/Concatenate 11 | f = Tempfile.new("inputs") 12 | aac_paths.each do |aac_path| 13 | f.write("file '#{aac_path}'\n") 14 | end 15 | f.close 16 | 17 | # NOTE: 18 | # Apple Podcast Appでaacをうまく扱えなかったので連結ついでにm4aに変換 19 | m4a_path = aac_paths[0].sub(/.aac\z/, ".m4a") 20 | system("ffmpeg -y -f concat -safe 0 -i #{f.path} -c copy #{m4a_path}", exception: true) 21 | m4a_path 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /deployment/cdk.json: -------------------------------------------------------------------------------- 1 | { 2 | "app": "npx ts-node --prefer-ts-exts bin/deployment.ts", 3 | "context": { 4 | "@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true, 5 | "@aws-cdk/core:enableStackNameDuplicates": "true", 6 | "aws-cdk:enableDiffNoFail": "true", 7 | "@aws-cdk/core:stackRelativeExports": "true", 8 | "@aws-cdk/aws-ecr-assets:dockerIgnoreSupport": true, 9 | "@aws-cdk/aws-secretsmanager:parseOwnedSecretName": true, 10 | "@aws-cdk/aws-kms:defaultKeyPolicies": true, 11 | "@aws-cdk/aws-s3:grantWriteWithoutAcl": true, 12 | "@aws-cdk/aws-ecs-patterns:removeDefaultDesiredCount": true, 13 | "@aws-cdk/aws-rds:lowercaseDbIdentifier": true, 14 | "@aws-cdk/aws-efs:defaultEncryptionAtRest": true, 15 | "@aws-cdk/aws-lambda:recognizeVersionProps": true 16 | } 17 | } -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/s3.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | class S3 4 | def initialize(client, bucket) 5 | @client = client 6 | @bucket = bucket 7 | end 8 | 9 | def find_definition(id) 10 | resp = client.get_object(bucket: bucket, key: "#{id}/radicaster.yaml") 11 | Definition.parse(resp.body.read) 12 | end 13 | 14 | def save_episode(episode) 15 | key = make_key(episode) 16 | open(episode.local_path) do |f| 17 | client.put_object(bucket: bucket, key: key, body: f) 18 | end 19 | end 20 | 21 | private 22 | 23 | attr_reader :client, :bucket 24 | 25 | def make_key(episode) 26 | id = episode.id 27 | yyyymmdd = episode.start_time.strftime("%Y%m%d") 28 | "#{id}/#{yyyymmdd}.m4a" 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /cli/bin/rspec: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # frozen_string_literal: true 3 | 4 | # 5 | # This file was generated by Bundler. 6 | # 7 | # The application 'rspec' is installed as part of a gem, and 8 | # this file is here to facilitate running it. 9 | # 10 | 11 | require "pathname" 12 | ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", 13 | Pathname.new(__FILE__).realpath) 14 | 15 | bundle_binstub = File.expand_path("../bundle", __FILE__) 16 | 17 | if File.file?(bundle_binstub) 18 | if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ 19 | load(bundle_binstub) 20 | else 21 | abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. 22 | Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") 23 | end 24 | end 25 | 26 | require "rubygems" 27 | require "bundler/setup" 28 | 29 | load Gem.bin_path("rspec-core", "rspec") 30 | -------------------------------------------------------------------------------- /gen_feed/Rakefile: -------------------------------------------------------------------------------- 1 | task :run => :build do 2 | sh <<~EOS 3 | docker run \ 4 | -it \ 5 | --rm \ 6 | --platform=linux/amd64 \ 7 | -p 9001:8080 \ 8 | -e AWS_REGION \ 9 | -e RADICASTER_S3_BUCKET \ 10 | -e RADICASTER_BUCKET_URL \ 11 | -e AWS_ACCESS_KEY_ID \ 12 | -e AWS_SECRET_ACCESS_KEY \ 13 | radicaster/gen-feed:latest 14 | EOS 15 | end 16 | 17 | task :build do 18 | sh "docker build --platform linux/amd64 -t radicaster/gen-feed ." 19 | end 20 | 21 | task :push => :build do 22 | sh "aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com" 23 | sh "docker tag radicaster/gen-feed:latest 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com/radicaster/gen-feed:latest" 24 | sh "docker push 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com/radicaster/gen-feed:latest" 25 | end 26 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/templates/podcast.xml.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | <%= definition.title %> 5 | <%= definition.author %> 6 | <%= definition.summary %> 7 | <% if definition.image %> 8 | 9 | <% end %> 10 | <% episodes.each do |ep| %> 11 | 12 | <%= ep.title %> 13 | <%= definition.author %> 14 | <% if definition.image %> 15 | 16 | <% end %> 17 | <%= ep.last_modified.rfc822 %> 18 | 19 | 20 | <% end %> 21 | 22 | 23 | -------------------------------------------------------------------------------- /cli/lib/cli/eventbridge.rb: -------------------------------------------------------------------------------- 1 | require "aws-sdk-eventbridge" 2 | 3 | module Radicaster 4 | module CLI 5 | class EventBridge 6 | TARGET_ID_RADIKO = "rec-radiko" 7 | 8 | def initialize(client, rec_radiko_arn) 9 | @client = client 10 | @rec_radiko_arn = rec_radiko_arn 11 | end 12 | 13 | def register(def_) 14 | def_.execution_schedule.each_with_index do |item, index| 15 | name = "#{def_.id}_#{index}" 16 | client.put_rule( 17 | name: name, 18 | schedule_expression: item.to_cron, 19 | ) 20 | 21 | client.put_targets( 22 | rule: name, 23 | targets: [{ 24 | id: TARGET_ID_RADIKO, 25 | arn: rec_radiko_arn, 26 | input: JSON.generate({ id: def_.id }), 27 | }], 28 | ) 29 | end 30 | end 31 | 32 | private 33 | 34 | attr_reader :client, :rec_radiko_arn 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /rec_radiko/Rakefile: -------------------------------------------------------------------------------- 1 | task :run => :build do 2 | sh <<~EOS 3 | docker run \ 4 | -it \ 5 | --rm \ 6 | --platform=linux/amd64 \ 7 | -p 9000:8080 \ 8 | -e RADICASTER_RADIKO_MAIL \ 9 | -e RADICASTER_RADIKO_PASSWORD \ 10 | -e RADICASTER_S3_BUCKET \ 11 | -e AWS_REGION \ 12 | -e AWS_ACCESS_KEY_ID \ 13 | -e AWS_SECRET_ACCESS_KEY \ 14 | radicaster/rec-radiko:latest 15 | EOS 16 | end 17 | 18 | task :build do 19 | sh "docker build --platform linux/amd64 -t radicaster/rec-radiko ." 20 | end 21 | 22 | task :push => :build do 23 | sh "aws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com" 24 | sh "docker tag radicaster/rec-radiko:latest 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com/radicaster/rec-radiko:latest" 25 | sh "docker push 164278227419.dkr.ecr.ap-northeast-1.amazonaws.com/radicaster/rec-radiko:latest" 26 | end 27 | -------------------------------------------------------------------------------- /deployment/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "deployment", 3 | "version": "0.1.0", 4 | "bin": { 5 | "deployment": "bin/deployment.js" 6 | }, 7 | "scripts": { 8 | "build": "tsc", 9 | "watch": "tsc -w", 10 | "test": "jest", 11 | "cdk": "cdk" 12 | }, 13 | "devDependencies": { 14 | "@aws-cdk/assert": "^1.107.0", 15 | "@types/jest": "^26.0.10", 16 | "@types/node": "10.17.27", 17 | "aws-cdk": "^1.107.1", 18 | "jest": "^26.4.2", 19 | "ts-jest": "^26.2.0", 20 | "ts-node": "^9.0.0", 21 | "typescript": "~3.9.7" 22 | }, 23 | "dependencies": { 24 | "@aws-cdk/aws-certificatemanager": "^1.107.0", 25 | "@aws-cdk/aws-cloudfront": "^1.107.0", 26 | "@aws-cdk/aws-cloudfront-origins": "^1.107.0", 27 | "@aws-cdk/aws-iam": "^1.107.0", 28 | "@aws-cdk/aws-lambda": "^1.107.0", 29 | "@aws-cdk/aws-lambda-event-sources": "^1.107.0", 30 | "@aws-cdk/aws-s3": "^1.107.0", 31 | "@aws-cdk/core": "^1.107.0", 32 | "source-map-support": "^0.5.16" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rec_radiko/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM amazon/aws-lambda-ruby:2.7 AS bundler 2 | WORKDIR /var/task 3 | RUN yum groupinstall -y "Development Tools" 4 | COPY ./Gemfile ./Gemfile 5 | COPY ./Gemfile.lock ./Gemfile.lock 6 | RUN bundle install --path=vendor/bundle 7 | 8 | 9 | FROM amazon/aws-lambda-ruby:2.7 AS download 10 | WORKDIR /tmp 11 | ADD https://github.com/yyoshiki41/radigo/releases/download/v0.11.0/radigo_v0.11.0_linux_amd64.zip /tmp/radigo.zip 12 | ADD https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz /tmp/ffmpeg.tar.xz 13 | RUN yum install -y unzip tar xz \ 14 | && unzip /tmp/radigo.zip \ 15 | && tar -Jxf /tmp/ffmpeg.tar.xz \ 16 | && cp /tmp/ffmpeg-*/ffmpeg ffmpeg 17 | 18 | 19 | FROM amazon/aws-lambda-ruby:2.7 20 | WORKDIR /var/task 21 | 22 | ENV TZ=Asia/Tokyo 23 | 24 | COPY --from=bundler /var/task/vendor ./vendor 25 | COPY --from=download /tmp/radigo /usr/local/bin/radigo 26 | COPY --from=download /tmp/ffmpeg /usr/local/bin/ffmpeg 27 | COPY ./ ./ 28 | 29 | CMD ["function.Handler.handle"] 30 | -------------------------------------------------------------------------------- /cli/lib/cli.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "aws-sdk-s3" 4 | require "aws-sdk-lambda" 5 | require "aws-sdk-eventbridge" 6 | 7 | require "cli/handler" 8 | require "cli/definition" 9 | require "cli/eventbridge" 10 | require "cli/execution_schedule" 11 | require "cli/lambda" 12 | require "cli/s3" 13 | 14 | module Radicaster 15 | module CLI 16 | def main(argv) 17 | bucket = ENV["RADICASTER_S3_BUCKET"] or raise "ENV['RADICASTER_S3_BUCKET'] must be set" 18 | s3_client = Aws::S3::Client.new 19 | storage = S3.new(s3_client, bucket) 20 | 21 | rec_radiko_arn = ENV["RADICASTER_REC_RADIKO_ARN"] or raise "ENV['RADICASTER_REC_RADIKO_ARN'] must be set" 22 | 23 | eb_client = Aws::EventBridge::Client.new 24 | scheduler = EventBridge.new(eb_client, rec_radiko_arn) 25 | 26 | lambda_client = Aws::Lambda::Client.new 27 | recorder = Lambda.new(lambda_client, rec_radiko_arn) 28 | 29 | h = Handler.new(storage, scheduler, recorder) 30 | h.handle(argv) 31 | end 32 | 33 | module_function :main 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /deployment/bin/deployment.ts: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import 'source-map-support/register'; 3 | import * as cdk from '@aws-cdk/core'; 4 | import { RadicasterStack } from '../lib/radicaster-stack'; 5 | 6 | const suffix = process.env.RADICASTER_CDK_SUFFIX || ''; 7 | 8 | const app = new cdk.App(); 9 | new RadicasterStack(app, `RadicasterStack${suffix}`, { 10 | 11 | /* If you don't specify 'env', this stack will be environment-agnostic. 12 | * Account/Region-dependent features and context lookups will not work, 13 | * but a single synthesized template can be deployed anywhere. */ 14 | 15 | /* Uncomment the next line to specialize this stack for the AWS Account 16 | * and Region that are implied by the current CLI configuration. */ 17 | env: { account: process.env.CDK_DEFAULT_ACCOUNT, region: process.env.CDK_DEFAULT_REGION }, 18 | 19 | /* Uncomment the next line if you know exactly what Account and Region you 20 | * want to deploy the stack to. */ 21 | // env: { account: '123456789012', region: 'us-east-1' }, 22 | 23 | /* For more information, see https://docs.aws.amazon.com/cdk/latest/guide/environments.html */ 24 | }); 25 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/radigo.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module RecRadiko 3 | class Radigo 4 | def initialize(workdir, email = nil, password = nil) 5 | @workdir = workdir 6 | 7 | raise "email and password must be passed in together" if email.nil? ^ password.nil? 8 | @email = email 9 | @password = password 10 | end 11 | 12 | def rec(area, station, start_time) 13 | env = ["RADIGO_HOME=#{workdir}"] 14 | if !email.nil? && !password.nil? 15 | env.push("RADIKO_MAIL=#{email}", "RADIKO_PASSWORD=#{password}") 16 | end 17 | start_str = start_time.strftime("%Y%m%d%H%M%S") 18 | system("rm -f #{output_path(workdir, start_str, station)}") 19 | system("env #{env.join(" ")} radigo rec -area=#{area} -id=#{station} -s=#{start_str}", exception: true) 20 | output_path(workdir, start_str, station) 21 | end 22 | 23 | private 24 | 25 | def output_path(workdir, start, station) 26 | "#{workdir}/#{start}-#{station}.aac" 27 | end 28 | 29 | attr_reader :workdir, :email, :password 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | # 必須の設定 2 | ############################## 3 | 4 | # 録音ファイルやPodcastフィードを格納するS3バケット名 5 | # CDK実行により新規に作成される。既存のバケットは今のところ使用不可。 6 | export RADICASTER_S3_BUCKET=radicaster-example 7 | 8 | # バケットに設定するBasic認証の情報 9 | export RADICASTER_BASIC_AUTH_USER=radicaster 10 | export RADICASTER_BASIC_AUTH_PASSWORD=password 11 | 12 | # rec-radiko関数のARN 13 | # CLIで録音予約を登録する際に使用する。 14 | # `cdk deploy --all` を実行して出力される値を以下に記入する 15 | #export RADICASTER_REC_RADIKO_ARN=arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:radicaster-rec-radiko 16 | 17 | 18 | # 以下は任意の設定 19 | ############################## 20 | 21 | # バケットに独自ドメインを割り当てる場合は、ドメイン名と事前にACMに登録されている証明書のARNを記入 22 | #export RADICASTER_CUSTOM_DOMAIN=podcast.example.com 23 | #export RADICASTER_CUSTOM_DOMAIN_CERT_ARN=arn:aws:acm:us-east-1:000000000000:certificate/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxxx 24 | 25 | # エリアフリーでLambdaをデプロイした地域(東京リージョンはJP13)以外の番組を録音する場合はradikoプレミアムの認証情報を記入 26 | #export RADICASTER_RADIKO_MAIL=foo@example.com 27 | #export RADICASTER_RADIKO_PASSWORD=password 28 | 29 | 30 | # 作成されるAWSリソース名の末尾に付与する文字列 31 | # 開発時など、1アカウント内に複数バージョンをデプロイしたい場合にコメントアウトする 32 | #export RADICASTER_CDK_SUFFIX=-dev 33 | -------------------------------------------------------------------------------- /cli/spec/s3_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::CLI 2 | describe S3 do 3 | describe "#save_definition" do 4 | let(:client) { instance_double(Aws::S3::Client) } 5 | let(:bucket) { "radicaster.test" } 6 | let(:def_) { 7 | Definition.new( 8 | id: "test", 9 | title: "test title", 10 | author: "test author", 11 | image: "http://radicaster.test/example.png", 12 | program_schedule: [ 13 | ["Tue 01:00:00", "Tue 02:00:00"], 14 | ], 15 | execution_schedule: ExecutionSchedule.new("Tue", 3, 3), 16 | station: "TEST", 17 | area: "JP13", 18 | ) 19 | } 20 | subject(:s3) { S3.new(client, bucket) } 21 | 22 | it "puts definition file to S3 bucket" do 23 | allow(def_).to receive(:to_yaml).and_return("test yaml") 24 | expect(client).to receive(:put_object).with( 25 | satisfy do |arg| 26 | arg[:bucket] == "radicaster.test" && 27 | arg[:key] == "test/radicaster.yaml" && 28 | arg[:body].read == "test yaml" 29 | end 30 | ) 31 | s3.save_definition(def_) 32 | end 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /cli/lib/cli/handler.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module CLI 3 | class Handler 4 | def initialize(storage, scheduler, recorder) 5 | @storage = storage 6 | @scheduler = scheduler 7 | @recorder = recorder 8 | end 9 | 10 | def handle(argv) 11 | usage unless argv.length == 1 12 | def_path = argv[0] 13 | 14 | exec(def_path) 15 | end 16 | 17 | def usage 18 | puts <<~EOS 19 | radicaster - radicasterの録音予約をする 20 | 21 | Usage: 22 | radicaster 23 | EOS 24 | exit(false) 25 | end 26 | 27 | def exec(def_path) 28 | open(def_path) do |f| 29 | def_ = Definition.parse(f.read) 30 | 31 | puts "Saving the definition to storage..." 32 | storage.save_definition(def_) 33 | 34 | puts "Registering recording schedule..." 35 | scheduler.register(def_) 36 | 37 | puts "Recording latest episode..." 38 | recorder.record_latest(def_) 39 | 40 | puts "Done!" 41 | end 42 | end 43 | 44 | private 45 | 46 | attr_reader :storage, :scheduler, :recorder 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /deployment/assets/basic_auth/function.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.handler = (event, context, callback) => { 4 | const request = event.Records[0].cf.request; 5 | const headers = request.headers; 6 | 7 | if (request.uri.endsWith("/")) { 8 | request.uri = request.uri + "index.rss"; 9 | } 10 | 11 | if (!headers.authorization) { 12 | console.log('Authorization header not found.') 13 | callback(null, { 14 | status: '401', 15 | statusDescription: 'Unauthorized', 16 | headers: { 17 | 'www-authenticate': [{ key: 'WWW-Authenticate', value: 'Basic' }] 18 | } 19 | }); 20 | return; 21 | } 22 | 23 | const authUser = '__BASIC_AUTH_USER__'; 24 | const authPassword = '__BASIC_AUTH_PASSWORD__'; 25 | const authString = `Basic ${new Buffer.from(authUser + ':' + authPassword).toString('base64')}`; 26 | 27 | if (headers.authorization[0].value === authString) { 28 | console.log('Authorization succeeded.'); 29 | callback(null, request); 30 | return; 31 | } 32 | 33 | console.log('Authorization failed.'); 34 | return callback(null, { 35 | status: '403', 36 | statusDescription: 'Forbidden', 37 | }); 38 | }; 39 | -------------------------------------------------------------------------------- /cli/spec/lambda_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::CLI 2 | describe Lambda do 3 | describe "#record_latest" do 4 | 5 | let(:program_schedule) { 6 | [ 7 | ["Mon 08:30:00"], 8 | ["Tue 08:30:00"], 9 | ] 10 | } 11 | let(:execution_schedule) { 12 | [ 13 | ExecutionSchedule.new("Mon", 12, 0), 14 | ExecutionSchedule.new("Tue", 12, 0), 15 | ] 16 | } 17 | 18 | let(:def_) { 19 | Definition.new( 20 | id: "test", 21 | title: "test title", 22 | author: "test author", 23 | image: "https://radicaster.test/exmaple.png", 24 | program_schedule: [["Tue 01:00:00"]], 25 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 26 | station: "TEST", 27 | area: "JP13", 28 | ) 29 | } 30 | let(:rec_radiko_arn) { "arn:aws:lambda:dummy" } 31 | let(:client) { instance_double(Aws::Lambda::Client) } 32 | 33 | subject(:lambda) { Lambda.new(client, rec_radiko_arn) } 34 | 35 | it "invokes recording lambda" do 36 | expect(client).to receive(:invoke).with({ 37 | function_name: "arn:aws:lambda:dummy", 38 | payload: '{"id": "test"}', 39 | }) 40 | lambda.record_latest(def_) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/handler.rb: -------------------------------------------------------------------------------- 1 | require "date" 2 | 3 | require "aws-sdk-s3" 4 | 5 | module Radicaster 6 | module RecRadiko 7 | class RecCommand 8 | attr_reader :id 9 | 10 | def initialize(id:) 11 | @id = id 12 | end 13 | end 14 | 15 | # CloudWatchのイベントをハンドルしてradikoを録音する 16 | class Handler 17 | def initialize(logger, recorder, storage) 18 | @logger = logger 19 | @recorder = recorder 20 | @storage = storage 21 | end 22 | 23 | def handle(event:, context:) 24 | logger.debug(event) 25 | validate(event) 26 | cmd = build_command(event) 27 | exec(cmd) 28 | end 29 | 30 | private 31 | 32 | attr_reader :logger, :recorder, :storage 33 | 34 | def validate(event) 35 | raise "id must be set" unless event["id"] 36 | end 37 | 38 | def build_command(event) 39 | id = event["id"] 40 | RecCommand.new( 41 | id: id, 42 | ) 43 | end 44 | 45 | def exec(cmd) 46 | def_ = storage.find_definition(cmd.id) 47 | logger.info("Definition #{cmd.id} found") 48 | 49 | logger.info("Starting recording") 50 | episode = recorder.rec(def_, Time.now) 51 | logger.info("Recording finished") 52 | 53 | logger.info("Saving the episode to storage") 54 | storage.save_episode(episode) 55 | logger.info("Finished saving the episode.") 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/handler.rb: -------------------------------------------------------------------------------- 1 | require "erb" 2 | require "pathname" 3 | 4 | require "aws-sdk-s3" 5 | require "yaml" 6 | 7 | module Radicaster 8 | module GenFeed 9 | class GenerateFeedCommand 10 | attr_reader :id 11 | 12 | def initialize(id:) 13 | @id = id 14 | end 15 | end 16 | 17 | # CloudWatchのイベントをハンドルしてPodcastフィードを生成する 18 | class Handler 19 | def initialize(logger, storage, generator) 20 | @logger = logger 21 | @storage = storage 22 | @generator = generator 23 | end 24 | 25 | def handle(event:, context:) 26 | logger.info("Start event handling.") 27 | cmd = build_cmd(event) 28 | exec(cmd) 29 | logger.info("Event handling finished.") 30 | end 31 | 32 | private 33 | 34 | attr_reader :logger, :storage, :generator 35 | 36 | def build_cmd(event) 37 | raise '"s3" is not contained in the event' unless event["Records"][0]["s3"] 38 | key = event["Records"][0]["s3"]["object"]["key"] 39 | logger.debug(key) 40 | id = Pathname.new(key).dirname.to_s 41 | GenerateFeedCommand.new( 42 | id: id, 43 | ) 44 | end 45 | 46 | def exec(cmd) 47 | logger.debug("Start exec. id: #{cmd}") 48 | definition = storage.find_definition(cmd.id) 49 | episodes = storage.list_episodes(cmd.id) 50 | feed = generator.generate(definition, episodes) 51 | storage.save_feed(cmd.id, feed) 52 | end 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /cli/lib/cli/execution_schedule.rb: -------------------------------------------------------------------------------- 1 | module Radicaster 2 | module CLI 3 | class ExecutionSchedule 4 | DAYS_OF_WEEK = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"] 5 | 6 | attr_reader :wday, :hour, :min 7 | 8 | def self.parse(s) 9 | m = /\A(Sun|Mon|Tue|Wed|Thu|Fri|Sat)\s*([0-5]?[0-9]):([0-5]?[0-9])(?::([0-5]?[0-9]))?\z/i.match(s) 10 | raise ArgumentError, "execution schedule format is invalid" if m == nil 11 | 12 | wday = m[1].downcase.capitalize 13 | hour = m[2].to_i 14 | min = m[3].to_i 15 | # secは不要 16 | 17 | self.new(wday, hour, min) 18 | end 19 | 20 | def initialize(wday, hour, min) 21 | @wday = wday.capitalize 22 | @hour = hour 23 | @min = min 24 | end 25 | 26 | def to_cron() 27 | jst_wday = DAYS_OF_WEEK.index(wday) 28 | jst_hour = hour 29 | # タイムゾーンをJSTからUTCに変換 30 | if jst_hour >= 9 31 | utc_wday = jst_wday 32 | utc_hour = jst_hour - 9 33 | else 34 | utc_wday = (jst_wday == 0 ? 6 : jst_wday - 1) 35 | utc_hour = 24 + jst_hour - 9 36 | end 37 | "cron(#{min} #{utc_hour} ? * #{DAYS_OF_WEEK[utc_wday]} *)" 38 | end 39 | 40 | def to_yaml() 41 | hour_pad = "%#02d" % hour 42 | min_pad = "%#02d" % min 43 | "#{wday} #{hour_pad}:#{min_pad}:00" 44 | end 45 | 46 | def ==(other) 47 | other.is_a?(self.class) && wday == other.wday && hour == other.hour && min == other.min 48 | end 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /cli/Guardfile: -------------------------------------------------------------------------------- 1 | # A sample Guardfile 2 | # More info at https://github.com/guard/guard#readme 3 | 4 | ## Uncomment and set this to only include directories you want to watch 5 | # directories %w(app lib config test spec features) \ 6 | # .select{|d| Dir.exist?(d) ? d : UI.warning("Directory #{d} does not exist")} 7 | 8 | ## Note: if you are using the `directories` clause above and you are not 9 | ## watching the project directory ('.'), then you will want to move 10 | ## the Guardfile to a watched dir and symlink it back, e.g. 11 | # 12 | # $ mkdir config 13 | # $ mv Guardfile config/ 14 | # $ ln -s config/Guardfile . 15 | # 16 | # and, you'll have to watch "config/Guardfile" instead of "Guardfile" 17 | 18 | # Note: The cmd option is now required due to the increasing number of ways 19 | # rspec may be run, below are examples of the most common uses. 20 | # * bundler: 'bundle exec rspec' 21 | # * bundler binstubs: 'bin/rspec' 22 | # * spring: 'bin/rspec' (This will use spring if running and you have 23 | # installed the spring binstubs per the docs) 24 | # * zeus: 'zeus rspec' (requires the server to be started separately) 25 | # * 'just' rspec: 'rspec' 26 | 27 | guard :rspec, cmd: "bundle exec rspec" do 28 | require "guard/rspec/dsl" 29 | dsl = Guard::RSpec::Dsl.new(self) 30 | 31 | # Feel free to open issues for suggestions and improvements 32 | 33 | # RSpec files 34 | rspec = dsl.rspec 35 | watch(rspec.spec_helper) { rspec.spec_dir } 36 | watch(rspec.spec_support) { rspec.spec_dir } 37 | watch(rspec.spec_files) 38 | 39 | # Ruby files 40 | ruby = dsl.ruby 41 | dsl.watch_spec_files_for(ruby.lib_files) 42 | end 43 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/schedule_item.rb: -------------------------------------------------------------------------------- 1 | require "date" 2 | 3 | module Radicaster 4 | module RecRadiko 5 | class ScheduleItem 6 | DAYS_OF_WEEK = ["sun", "mon", "tue", "wed", "thu", "fri", "sat"] 7 | TIMEZONE_JP = "+09:00" 8 | 9 | def self.parse(s) 10 | m = s.chomp.downcase.match(/\A(sun|mon|tue|wed|thu|fri|sat) ([0-2]?[0-9]):([0-5]?[0-9])(:([0-5]?[0-9]))?\z/) 11 | raise ArgumentError, "invalid format" unless m 12 | 13 | wday = m[1] 14 | hour = m[2].to_i 15 | min = m[3].to_i 16 | sec = m[5] ? m[5].to_i : 0 17 | self.new(wday, hour, min, sec) 18 | end 19 | 20 | def initialize(wday, hour, min, sec) 21 | raise "wday is invalid" if DAYS_OF_WEEK.index(wday.downcase).nil? 22 | @wday = wday.downcase 23 | @hour = hour 24 | @min = min 25 | @sec = sec 26 | end 27 | 28 | def ==(other) 29 | return false unless other.is_a? ScheduleItem 30 | (wday.downcase == other.wday.downcase && 31 | hour == other.hour && 32 | min == other.min && 33 | sec == other.sec) 34 | end 35 | 36 | def latest(now) 37 | day_gap = now.wday - wday_index 38 | latest_date = now.to_date - day_gap 39 | latest_time = Time.new(latest_date.year, latest_date.month, latest_date.day, hour, min, sec, TIMEZONE_JP) 40 | latest_time <= now ? latest_time : latest_time - (7 * 24 * 60 * 60) 41 | end 42 | 43 | attr_reader :wday, :hour, :min, :sec 44 | 45 | private 46 | 47 | def wday_index() 48 | DAYS_OF_WEEK.index(wday.downcase) 49 | end 50 | end 51 | end 52 | end 53 | -------------------------------------------------------------------------------- /rec_radiko/lib/rec-radiko/definition.rb: -------------------------------------------------------------------------------- 1 | require "yaml" 2 | 3 | module Radicaster 4 | module RecRadiko 5 | class Definition 6 | attr_reader :id, :area, :station, :program_schedule 7 | 8 | def self.parse(s) 9 | d = YAML.load(s) 10 | 11 | begin 12 | id = d.fetch("id") 13 | area = d.fetch("area") 14 | station = d.fetch("station") 15 | schedule = d.fetch("program_schedule") 16 | rescue KeyError => e 17 | raise ArgumentError, "requird key `#{e.key}` not found" 18 | end 19 | 20 | unless schedule.is_a?(Array) 21 | parsed_schedule = Schedule.new(ScheduleItem.parse(schedule)) 22 | else 23 | parsed_items = schedule.map { |item| 24 | if item.is_a?(Array) 25 | elements = item.map { |elem| ScheduleItem.parse(elem) } 26 | CombinedScheduleItem.new(*elements) 27 | else 28 | ScheduleItem.parse(item) 29 | end 30 | } 31 | parsed_schedule = Schedule.new(*parsed_items) 32 | end 33 | 34 | Definition.new(id: id, area: area, station: station, program_schedule: parsed_schedule) 35 | end 36 | 37 | def initialize(id:, area:, station:, program_schedule:) 38 | @id = id 39 | @area = area 40 | @station = station 41 | @program_schedule = program_schedule 42 | end 43 | 44 | def ==(other) 45 | id == other.id && area == other.area && station == other.station && program_schedule == other.program_schedule 46 | end 47 | 48 | def latest_start_times(now) 49 | program_schedule.latest(now) 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /rec_radiko/spec/combined_schedule_item_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe CombinedScheduleItem do 3 | describe "#==" do 4 | let(:this) do 5 | CombinedScheduleItem.new( 6 | ScheduleItem.new("Mon", 8, 30, 0), 7 | ScheduleItem.new("Mon", 10, 0, 0), 8 | ) 9 | end 10 | 11 | where(:other, :expected) do 12 | [ 13 | # 完全に同じ 14 | [CombinedScheduleItem.new( 15 | ScheduleItem.new("Mon", 8, 30, 0), 16 | ScheduleItem.new("Mon", 10, 0, 0), 17 | ), true], 18 | # 要素が等しくない 19 | [CombinedScheduleItem.new( 20 | ScheduleItem.new("Mon", 8, 30, 1), 21 | ScheduleItem.new("Mon", 10, 0, 0), 22 | ), false], 23 | # 型が違う 24 | [ScheduleItem.new("Mon", 8, 30, 1), false], 25 | [nil, false], 26 | ] 27 | end 28 | 29 | with_them do 30 | subject { this == other } 31 | it { is_expected.to eq(expected) } 32 | end 33 | end 34 | 35 | describe "#latest" do 36 | let(:now) { Time.new(2021, 6, 14, 12, 0, 0, "+09:00") } # monday 37 | let(:item) do 38 | CombinedScheduleItem.new( 39 | ScheduleItem.new("Mon", 8, 30, 0), 40 | ScheduleItem.new("Mon", 10, 0, 0), 41 | ) 42 | end 43 | subject(:latest) { item.latest(now) } 44 | 45 | it "returns latest scheduled time of the first element" do 46 | expect(latest).to eq([ 47 | Time.new(2021, 6, 14, 8, 30, 0, "+09:00"), 48 | Time.new(2021, 6, 14, 10, 0, 0, "+09:00"), 49 | ]) 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /gen_feed/lib/gen-feed/s3.rb: -------------------------------------------------------------------------------- 1 | require "yaml" 2 | 3 | module Radicaster 4 | module GenFeed 5 | class S3 6 | FEED_FILENAME = "index.rss" 7 | DEFINITION_FILENAME = "radicaster.yaml" 8 | EPISODE_EXTS = [".m4a"] 9 | 10 | def initialize(client, bucket, url) 11 | @client = client 12 | @bucket = bucket 13 | @url = url 14 | end 15 | 16 | def find_definition(id) 17 | key = "#{id}/#{DEFINITION_FILENAME}" 18 | resp = client.get_object(bucket: bucket, key: key) 19 | def_hash = YAML.load(resp.body.read) 20 | Definition.new( 21 | title: def_hash["title"], 22 | author: def_hash["author"], 23 | summary: def_hash["summary"], 24 | image: def_hash["image"], 25 | ) 26 | end 27 | 28 | def list_episodes(id) 29 | prefix = id + "/" 30 | resp = client.list_objects_v2(bucket: bucket, prefix: prefix) 31 | resp 32 | .contents 33 | .filter { |c| EPISODE_EXTS.include?(Pathname.new(c.key).extname) } 34 | .map { |c| 35 | Episode.new( 36 | url: build_public_url(c.key), 37 | size: c.size, 38 | last_modified: c.last_modified, 39 | ) 40 | } 41 | .sort_by(&:title) 42 | .reverse 43 | end 44 | 45 | def save_feed(id, feed_body) 46 | key = "#{id}/#{FEED_FILENAME}" 47 | client.put_object( 48 | bucket: bucket, 49 | key: key, 50 | body: feed_body, 51 | ) 52 | end 53 | 54 | private 55 | 56 | attr_reader :client, :bucket, :url 57 | 58 | def build_public_url(key) 59 | "#{url}/#{key}" 60 | end 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /rec_radiko/spec/s3_spec.rb: -------------------------------------------------------------------------------- 1 | require "tempfile" 2 | 3 | module Radicaster::RecRadiko 4 | describe S3 do 5 | let(:client) { instance_double(Aws::S3::Client, "client") } 6 | let(:bucket) { "dummy-bucket" } 7 | let(:s3) { S3.new(client, bucket) } 8 | let(:id) { "test" } 9 | 10 | describe "#find_definition" do 11 | let(:def_body) do 12 | <<~EOS 13 | id: test 14 | area: JP13 15 | station: TEST 16 | title: dummy-title 17 | author: dummy-author 18 | summary: dummy-summary 19 | image: http://foo.test/bar.png 20 | program_schedule: Tue 01:00:00 21 | EOS 22 | end 23 | 24 | it "finds a defintion file by id and returns a Definition object" do 25 | resp = instance_double(Aws::S3::Types::GetObjectOutput, "resp", body: StringIO.new(def_body)) 26 | expect(client).to receive(:get_object) 27 | .with(bucket: bucket, key: "test/radicaster.yaml") 28 | .and_return(resp) 29 | expect(s3.find_definition(id)).to eq(Definition.new( 30 | id: "test", 31 | area: "JP13", 32 | station: "TEST", 33 | program_schedule: Schedule.new(ScheduleItem.new("Tue", 1, 0, 0)), 34 | )) 35 | end 36 | end 37 | 38 | describe "#save_episode" do 39 | let(:episode) { 40 | Episode.new( 41 | id: "test", 42 | station: "TEST", 43 | start_time: Time.new(2021, 6, 22, 1, 0, 0, "+09:00"), 44 | local_path: Tempfile.new.path, 45 | ) 46 | } 47 | it "uploads episode to s3" do 48 | expect(client).to receive(:put_object).with(hash_including( 49 | bucket: bucket, 50 | key: "test/20210622.m4a", 51 | )) 52 | s3.save_episode(episode) 53 | end 54 | end 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /rec_radiko/spec/schedule_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe Schedule do 3 | describe "#==" do 4 | let(:this) { 5 | Schedule.new( 6 | CombinedScheduleItem.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Mon", 10, 0, 0)), 7 | ScheduleItem.new("Tue", 8, 30, 0), 8 | ) 9 | } 10 | where(:other, :expected) do 11 | [ 12 | [ 13 | Schedule.new( 14 | CombinedScheduleItem.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Mon", 10, 0, 0)), 15 | ScheduleItem.new("Tue", 8, 30, 0), 16 | ), true, 17 | ], 18 | [nil, false], 19 | [Schedule.new(CombinedScheduleItem.new(ScheduleItem.new("Mon", 8, 30, 0))), false], 20 | ] 21 | end 22 | 23 | with_them do 24 | subject { this == other } 25 | it { is_expected.to eq(expected) } 26 | end 27 | end 28 | 29 | describe "#latest" do 30 | let(:now) { Time.new(2021, 6, 15, 0, 0, 0, "+09:00") } # tuesday 31 | 32 | it "returns latest schedule item" do 33 | schedule = Schedule.new( 34 | CombinedScheduleItem.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Mon", 10, 0, 0)), 35 | ScheduleItem.new("Tue", 8, 30, 0), 36 | CombinedScheduleItem.new(ScheduleItem.new("Wed", 8, 30, 0), ScheduleItem.new("Wed", 10, 0, 0)), 37 | CombinedScheduleItem.new(ScheduleItem.new("Thu", 8, 30, 0), ScheduleItem.new("Thu", 10, 0, 0)), 38 | CombinedScheduleItem.new(ScheduleItem.new("Fri", 8, 30, 0), ScheduleItem.new("Fri", 10, 0, 0)) 39 | ) 40 | 41 | expected = [ 42 | Time.new(2021, 6, 14, 8, 30, 0, "+09:00"), 43 | Time.new(2021, 6, 14, 10, 0, 0, "+09:00"), 44 | ] 45 | expect(schedule.latest(now)).to eq(expected) 46 | end 47 | end 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /gen_feed/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | ast (2.4.2) 5 | aws-eventstream (1.1.1) 6 | aws-partitions (1.432.0) 7 | aws-sdk-core (3.112.1) 8 | aws-eventstream (~> 1, >= 1.0.2) 9 | aws-partitions (~> 1, >= 1.239.0) 10 | aws-sigv4 (~> 1.1) 11 | jmespath (~> 1.0) 12 | aws-sdk-kms (1.42.0) 13 | aws-sdk-core (~> 3, >= 3.112.0) 14 | aws-sigv4 (~> 1.1) 15 | aws-sdk-s3 (1.90.0) 16 | aws-sdk-core (~> 3, >= 3.112.0) 17 | aws-sdk-kms (~> 1) 18 | aws-sigv4 (~> 1.1) 19 | aws-sigv4 (1.2.3) 20 | aws-eventstream (~> 1, >= 1.0.2) 21 | binding_ninja (0.2.3) 22 | coderay (1.1.3) 23 | diff-lcs (1.4.4) 24 | jmespath (1.4.0) 25 | parser (3.0.1.1) 26 | ast (~> 2.4.1) 27 | proc_to_ast (0.1.0) 28 | coderay 29 | parser 30 | unparser 31 | rake (12.3.3) 32 | rspec (3.10.0) 33 | rspec-core (~> 3.10.0) 34 | rspec-expectations (~> 3.10.0) 35 | rspec-mocks (~> 3.10.0) 36 | rspec-core (3.10.1) 37 | rspec-support (~> 3.10.0) 38 | rspec-expectations (3.10.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.10.0) 41 | rspec-its (1.3.0) 42 | rspec-core (>= 3.0.0) 43 | rspec-expectations (>= 3.0.0) 44 | rspec-mocks (3.10.2) 45 | diff-lcs (>= 1.2.0, < 2.0) 46 | rspec-support (~> 3.10.0) 47 | rspec-parameterized (0.4.2) 48 | binding_ninja (>= 0.2.3) 49 | parser 50 | proc_to_ast 51 | rspec (>= 2.13, < 4) 52 | unparser 53 | rspec-support (3.10.2) 54 | unparser (0.6.0) 55 | diff-lcs (~> 1.3) 56 | parser (>= 3.0.0) 57 | 58 | PLATFORMS 59 | ruby 60 | 61 | DEPENDENCIES 62 | aws-sdk-s3 63 | rake (~> 12.0) 64 | rspec (~> 3.0) 65 | rspec-its 66 | rspec-mocks 67 | rspec-parameterized 68 | 69 | RUBY VERSION 70 | ruby 2.7.2p137 71 | 72 | BUNDLED WITH 73 | 2.1.4 74 | -------------------------------------------------------------------------------- /rec_radiko/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | ast (2.4.2) 5 | aws-eventstream (1.1.1) 6 | aws-partitions (1.441.0) 7 | aws-sdk-core (3.113.1) 8 | aws-eventstream (~> 1, >= 1.0.2) 9 | aws-partitions (~> 1, >= 1.239.0) 10 | aws-sigv4 (~> 1.1) 11 | jmespath (~> 1.0) 12 | aws-sdk-kms (1.43.0) 13 | aws-sdk-core (~> 3, >= 3.112.0) 14 | aws-sigv4 (~> 1.1) 15 | aws-sdk-s3 (1.93.0) 16 | aws-sdk-core (~> 3, >= 3.112.0) 17 | aws-sdk-kms (~> 1) 18 | aws-sigv4 (~> 1.1) 19 | aws-sigv4 (1.2.3) 20 | aws-eventstream (~> 1, >= 1.0.2) 21 | binding_ninja (0.2.3) 22 | coderay (1.1.3) 23 | diff-lcs (1.4.4) 24 | jmespath (1.4.0) 25 | parser (3.0.1.0) 26 | ast (~> 2.4.1) 27 | proc_to_ast (0.1.0) 28 | coderay 29 | parser 30 | unparser 31 | rake (12.3.3) 32 | rspec (3.10.0) 33 | rspec-core (~> 3.10.0) 34 | rspec-expectations (~> 3.10.0) 35 | rspec-mocks (~> 3.10.0) 36 | rspec-core (3.10.1) 37 | rspec-support (~> 3.10.0) 38 | rspec-expectations (3.10.1) 39 | diff-lcs (>= 1.2.0, < 2.0) 40 | rspec-support (~> 3.10.0) 41 | rspec-its (1.3.0) 42 | rspec-core (>= 3.0.0) 43 | rspec-expectations (>= 3.0.0) 44 | rspec-mocks (3.10.2) 45 | diff-lcs (>= 1.2.0, < 2.0) 46 | rspec-support (~> 3.10.0) 47 | rspec-parameterized (0.4.2) 48 | binding_ninja (>= 0.2.3) 49 | parser 50 | proc_to_ast 51 | rspec (>= 2.13, < 4) 52 | unparser 53 | rspec-support (3.10.2) 54 | unparser (0.6.0) 55 | diff-lcs (~> 1.3) 56 | parser (>= 3.0.0) 57 | 58 | PLATFORMS 59 | ruby 60 | 61 | DEPENDENCIES 62 | aws-sdk-s3 63 | rake (~> 12.0) 64 | rspec (~> 3.0) 65 | rspec-its 66 | rspec-mocks 67 | rspec-parameterized 68 | 69 | RUBY VERSION 70 | ruby 2.7.2p137 71 | 72 | BUNDLED WITH 73 | 2.1.4 74 | -------------------------------------------------------------------------------- /cli/spec/eventbridge_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::CLI 2 | describe EventBridge do 3 | describe "#schedule" do 4 | let(:def_) { 5 | Definition.new( 6 | id: "test", 7 | title: "test title", 8 | author: "test author", 9 | image: "https://radicaster.test/exmaple.png", 10 | program_schedule: program_schedule, 11 | execution_schedule: execution_schedule, 12 | station: "TBS", 13 | area: "JP13", 14 | ) 15 | } 16 | let(:program_schedule) { 17 | [ 18 | ["Mon 08:30:00"], 19 | ["Tue 08:30:00"], 20 | ] 21 | } 22 | let(:execution_schedule) { 23 | [ 24 | ExecutionSchedule.new("Mon", 12, 0), 25 | ExecutionSchedule.new("Tue", 12, 0), 26 | ] 27 | } 28 | 29 | let(:rec_radiko_arn) { "arn:aws:lambda:dummy" } 30 | let(:client) { instance_double(Aws::EventBridge::Client) } 31 | subject(:eb) { EventBridge.new(client, rec_radiko_arn) } 32 | 33 | it "registers recording schedule to AWS EventBrdige" do 34 | expect(client).to receive(:put_rule).with( 35 | name: "test_0", 36 | schedule_expression: "cron(0 3 ? * Mon *)", 37 | ) 38 | expect(client).to receive(:put_targets).with( 39 | rule: "test_0", 40 | targets: [{ 41 | id: "rec-radiko", 42 | arn: "arn:aws:lambda:dummy", 43 | input: %q/{"id":"test"}/, 44 | }], 45 | ) 46 | expect(client).to receive(:put_rule).with( 47 | name: "test_1", 48 | schedule_expression: "cron(0 3 ? * Tue *)", 49 | ) 50 | expect(client).to receive(:put_targets).with( 51 | rule: "test_1", 52 | targets: [{ 53 | id: "rec-radiko", 54 | arn: "arn:aws:lambda:dummy", 55 | input: %q/{"id":"test"}/, 56 | }], 57 | ) 58 | eb.register(def_) 59 | end 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /cli/spec/execution_schedule_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::CLI 2 | describe ExecutionSchedule do 3 | describe ".parse" do 4 | context "normal cases" do 5 | where(:s, :expected) do 6 | [ 7 | ["Tue 08:05:00", ExecutionSchedule.new("Tue", 8, 5)], 8 | ["tue 08:05:00", ExecutionSchedule.new("Tue", 8, 5)], 9 | ["Tue 8:5", ExecutionSchedule.new("Tue", 8, 5)], 10 | ] 11 | end 12 | subject { ExecutionSchedule.parse(s) } 13 | 14 | with_them do 15 | it { is_expected.to eq(expected) } 16 | end 17 | end 18 | 19 | context "abnormal cases" do 20 | where(:s) do 21 | [ 22 | ["Tue 0805"], 23 | ["Hoge 08:30:00"], 24 | ["Hoge 25:30:00"], 25 | ] 26 | end 27 | with_them do 28 | it { expect { ExecutionSchedule.parse(s) }.to raise_error(ArgumentError) } 29 | end 30 | end 31 | end 32 | 33 | describe "#to_cron" do 34 | where(:wday, :hour, :min, :cron) do 35 | [ 36 | ["Sun", 9, 0, "cron(0 0 ? * Sun *)"], 37 | ["Sun", 8, 59, "cron(59 23 ? * Sat *)"], 38 | ] 39 | end 40 | 41 | with_them do 42 | subject { ExecutionSchedule.new(wday, hour, min).to_cron } 43 | it { is_expected.to eq(cron) } 44 | end 45 | end 46 | 47 | describe "#to_yaml" do 48 | subject { ExecutionSchedule.new("Tue", 1, 2).to_yaml } 49 | it { is_expected.to eq("Tue 01:02:00") } 50 | end 51 | 52 | describe "#==" do 53 | let(:this) { ExecutionSchedule.new("Tue", 12, 0) } 54 | 55 | where(:wday, :hour, :min, :expected) do 56 | [ 57 | ["Tue", 12, 0, true], 58 | ["tue", 12, 0, true], 59 | ["Mon", 12, 0, false], 60 | ["Tue", 13, 0, false], 61 | ["Tue", 12, 1, false], 62 | ] 63 | end 64 | 65 | let(:other) { ExecutionSchedule.new(wday, hour, min) } 66 | subject { this == other } 67 | 68 | with_them do 69 | it { is_expected.to eq expected } 70 | end 71 | end 72 | end 73 | end 74 | -------------------------------------------------------------------------------- /gen_feed/spec/feed_generator_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::GenFeed 2 | describe FeedGenerator do 3 | subject(:generator) { FeedGenerator.new } 4 | 5 | describe "#generate" do 6 | let(:definition) { Definition.new(title: "dummy title", author: "dummy author", summary: "dummy summary", image: "http://radicaster.test/dummy.png") } 7 | let(:episodes) { 8 | [ 9 | Episode.new(url: "http://radicaster.test/dummy/20210102.m4a", size: 100, last_modified: Time.utc(2021, 1, 2)), 10 | Episode.new(url: "http://radicaster.test/dummy/20210101.m4a", size: 100, last_modified: Time.utc(2021, 1, 1)), 11 | ] 12 | } 13 | 14 | it "generates podcast feed" do 15 | feed = generator.generate(definition, episodes) 16 | expected = <<~EOS 17 | 18 | 19 | 20 | dummy title 21 | dummy author 22 | dummy summary 23 | 24 | 25 | 26 | 27 | 28 | 20210102.m4a 29 | dummy author 30 | 31 | 32 | 33 | Sat, 02 Jan 2021 00:00:00 -0000 34 | 35 | 36 | 37 | 38 | 20210101.m4a 39 | dummy author 40 | 41 | 42 | 43 | Fri, 01 Jan 2021 00:00:00 -0000 44 | 45 | 46 | 47 | 48 | 49 | EOS 50 | expect(feed).to eq(expected) 51 | end 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /rec_radiko/spec/radigo_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe Radigo do 3 | let(:workdir) { "/tmp" } 4 | 5 | describe "#initialize" do 6 | context "normal caess" do 7 | where(:email, :password) do 8 | [ 9 | [nil, nil], 10 | ["test@radicaster.test", "password"], 11 | ] 12 | end 13 | 14 | with_them do 15 | it "does not raise error" do 16 | expect { Radigo.new(workdir, email, password) }.to_not raise_error 17 | end 18 | end 19 | end 20 | 21 | context "abnormal cases" do 22 | where(:email, :password) do 23 | [ 24 | ["test@radicaster.net", nil], 25 | [nil, "password"], 26 | ] 27 | end 28 | 29 | with_them do 30 | it "raises RuntimeError" do 31 | expect { Radigo.new(workdir, email, password) }.to raise_error(RuntimeError) 32 | end 33 | end 34 | end 35 | end 36 | 37 | describe "#rec" do 38 | let(:area) { "JP13" } 39 | let(:id) { "TEST" } 40 | let(:start_time) { Time.new(2020, 11, 22, 1, 0, 0, "+09:00") } 41 | 42 | context "when credentials are not specified" do 43 | subject(:radiko) { Radigo.new(workdir) } 44 | it "executes radigo without credentials" do 45 | allow(radiko).to receive(:system) 46 | 47 | ret = radiko.rec(area, id, start_time) 48 | 49 | expect(ret).to eq("/tmp/20201122010000-TEST.aac") 50 | expect(radiko).to have_received(:system).with("rm -f /tmp/20201122010000-TEST.aac").ordered 51 | expect(radiko).to have_received(:system).with("env RADIGO_HOME=/tmp radigo rec -area=JP13 -id=TEST -s=20201122010000", exception: true).ordered 52 | end 53 | end 54 | 55 | context "when credentials are specified" do 56 | let(:email) { "test@radicaster.test" } 57 | let(:password) { "password" } 58 | subject(:radiko) { Radigo.new(workdir, email, password) } 59 | it "executes radigo with credentials" do 60 | allow(radiko).to receive(:system) 61 | 62 | ret = radiko.rec(area, id, start_time) 63 | 64 | expect(ret).to eq("/tmp/20201122010000-TEST.aac") 65 | expect(radiko).to have_received(:system).with("rm -f /tmp/20201122010000-TEST.aac").ordered 66 | expect(radiko).to have_received(:system).with("env RADIGO_HOME=/tmp RADIKO_MAIL=test@radicaster.test RADIKO_PASSWORD=password radigo rec -area=JP13 -id=TEST -s=20201122010000", exception: true).ordered 67 | end 68 | end 69 | end 70 | end 71 | end 72 | -------------------------------------------------------------------------------- /cli/lib/cli/definition.rb: -------------------------------------------------------------------------------- 1 | require "yaml" 2 | 3 | module Radicaster 4 | module CLI 5 | class Definition 6 | attr_reader( 7 | :id, 8 | :station, 9 | :area, 10 | :title, 11 | :author, 12 | :image, 13 | :program_schedule, 14 | :execution_schedule, 15 | :raw 16 | ) 17 | 18 | def self.parse(yaml_def) 19 | h = YAML.load(yaml_def, symbolize_names: true) 20 | 21 | # TODO スキーマに従ってバリデーション 22 | 23 | # 番組スケジュールが二次元配列でない場合は二次元配列に変換 24 | program_schedule = h[:program_schedule].is_a?(Array) ? h[:program_schedule] : [h[:program_schedule]] 25 | program_schedule = program_schedule.map { |item| item.is_a?(Array) ? item : [item] } 26 | 27 | # 実行スケジュールが配列でない場合は配列に変換 28 | execution_schedule = h[:execution_schedule].is_a?(Array) ? h[:execution_schedule] : [h[:execution_schedule]] 29 | 30 | self.new( 31 | id: h[:id], 32 | station: h[:station], 33 | area: h[:area], 34 | title: h[:title], 35 | author: h[:author], 36 | image: h[:image], 37 | program_schedule: program_schedule, 38 | execution_schedule: execution_schedule.map { |s| ExecutionSchedule.parse(s) }, 39 | ) 40 | end 41 | 42 | def initialize( 43 | id:, 44 | title:, 45 | station:, 46 | area:, 47 | author:, 48 | image:, 49 | program_schedule:, 50 | execution_schedule: 51 | ) 52 | @id = id 53 | @title = title 54 | @station = station 55 | @area = area 56 | @author = author 57 | @image = image 58 | @program_schedule = program_schedule 59 | @execution_schedule = execution_schedule 60 | end 61 | 62 | def to_yaml() 63 | { 64 | "id" => id, 65 | "area" => area, 66 | "station" => station, 67 | "title" => title, 68 | "author" => author, 69 | "image" => image, 70 | "program_schedule" => program_schedule, 71 | "execution_schedule" => execution_schedule.map(&:to_yaml), 72 | }.to_yaml 73 | end 74 | 75 | def ==(other) 76 | other.is_a?(self.class) && 77 | id == other.id && 78 | station == other.station && 79 | area == other.area && 80 | title == other.title && 81 | author == other.author && 82 | image == other.image && 83 | program_schedule == other.program_schedule && 84 | execution_schedule == other.execution_schedule 85 | end 86 | end 87 | end 88 | end 89 | -------------------------------------------------------------------------------- /rec_radiko/spec/schedule_item_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe ScheduleItem do 3 | describe ".parse" do 4 | subject { ScheduleItem.parse(input) } 5 | context "valid format" do 6 | where(:input) do 7 | [ 8 | ["tue 01:02:03"], 9 | ["Tue 01:02:03"], 10 | ["TUE 01:02:03"], 11 | ["tue 1:2:3"], 12 | ] 13 | end 14 | 15 | let(:expected) { ScheduleItem.new("tue", 1, 2, 3) } 16 | with_them do 17 | it { is_expected.to eq(expected) } 18 | end 19 | end 20 | 21 | context "second can be omited" do 22 | let(:input) { "Tue 1:2" } 23 | it { is_expected.to eq(ScheduleItem.new("Tue", 1, 2, 0)) } 24 | end 25 | 26 | context "invalid format" do 27 | where(:input) do 28 | [ 29 | ["aaa 01:00:00"], 30 | ["tue 30:00:00"], 31 | ["tue 01:60:00"], 32 | ["tue 01:00:60"], 33 | ] 34 | end 35 | 36 | with_them do 37 | it "raises a RuntimeError" do 38 | expect { ScheduleItem.parse(input) }.to raise_error(ArgumentError) 39 | end 40 | end 41 | end 42 | end 43 | 44 | describe "#==" do 45 | let(:this) { ScheduleItem.new("tue", 1, 0, 0) } 46 | where(:other, :expected) do 47 | [ 48 | [ScheduleItem.new("tue", 1, 0, 0), true], 49 | [ScheduleItem.new("Tue", 1, 0, 0), true], 50 | [ScheduleItem.new("TUE", 1, 0, 0), true], 51 | [ScheduleItem.new("tue", 1, 0, 1), false], 52 | [ScheduleItem.new("tue", 1, 1, 0), false], 53 | [ScheduleItem.new("tue", 0, 0, 0), false], 54 | [ScheduleItem.new("mon", 0, 0, 0), false], 55 | [nil, false], 56 | ] 57 | end 58 | 59 | with_them do 60 | it "returns expected value" do 61 | expect(this == other).to eq(expected) 62 | end 63 | end 64 | end 65 | 66 | describe "#latest" do 67 | let(:now) { Time.new(2021, 6, 14, 12, 0, 0, "+09:00") } # monday 68 | subject(:latest) { ScheduleItem.new(wday, hour, sec, min).latest(now) } 69 | 70 | where(:wday, :hour, :sec, :min, :expected) do 71 | [ 72 | ["Sun", 12, 0, 0, Time.new(2021, 6, 13, 12, 0, 0, "+09:00")], 73 | ["Mon", 11, 59, 59, Time.new(2021, 6, 14, 11, 59, 59, "+09:00")], 74 | ["Mon", 12, 0, 0, Time.new(2021, 6, 14, 12, 0, 0, "+09:00")], 75 | ["Mon", 12, 0, 1, Time.new(2021, 6, 7, 12, 0, 1, "+09:00")], 76 | ["Tue", 0, 0, 0, Time.new(2021, 6, 8, 0, 0, 0, "+09:00")], 77 | ] 78 | end 79 | 80 | with_them do 81 | it "returns latest scheduled time" do 82 | expect(latest).to eq(expected) 83 | end 84 | end 85 | end 86 | end 87 | end 88 | -------------------------------------------------------------------------------- /rec_radiko/spec/recorder_spec.rb: -------------------------------------------------------------------------------- 1 | require "date" 2 | 3 | module Radicaster::RecRadiko 4 | describe Recorder do 5 | describe "#rec" do 6 | let(:radiko) { double("radiko") } 7 | let(:concater) { double("concater") } 8 | let(:recorder) { Recorder.new(radiko, concater) } 9 | 10 | let(:id) { "test" } 11 | let(:area) { "JP13" } 12 | let(:station) { "TEST" } 13 | 14 | let(:def_) { 15 | Definition.new( 16 | id: id, 17 | area: area, 18 | station: station, 19 | program_schedule: schedule, 20 | ) 21 | } 22 | let(:now) { Time.new(2021, 6, 23, 0, 0, 0, "+09:00") } # wednesday 23 | 24 | context "simple schdule program" do 25 | let(:schedule) { 26 | Schedule.new( 27 | ScheduleItem.new("Tue", 1, 0, 0) 28 | ) 29 | } 30 | 31 | it "record and concat multiple episodes" do 32 | recorded_paths = [ 33 | "/path/to/1.aac", 34 | ] 35 | expect(radiko).to receive(:rec).with("JP13", "TEST", Time.new(2021, 6, 22, 1, 0, 0, "+09:00")).and_return(recorded_paths[0]) 36 | expect(concater).to receive(:concat).with(recorded_paths).and_return("/path/to/concated.m4a") 37 | 38 | episode = recorder.rec(def_, now) 39 | expect(episode).to eq( 40 | Episode.new( 41 | id: "test", 42 | station: "TEST", 43 | start_time: Time.new(2021, 6, 22, 1, 0, 0, "+09:00"), 44 | local_path: "/path/to/concated.m4a", 45 | ) 46 | ) 47 | end 48 | end 49 | 50 | context "combined schdule program" do 51 | let(:schedule) { 52 | Schedule.new( 53 | CombinedScheduleItem.new( 54 | ScheduleItem.new("Tue", 1, 0, 0), 55 | ScheduleItem.new("Tue", 2, 0, 0) 56 | ) 57 | ) 58 | } 59 | 60 | it "record and concat multiple episodes" do 61 | recorded_paths = [ 62 | "/path/to/1.aac", 63 | "/path/to/2.aac", 64 | ] 65 | expect(radiko).to receive(:rec).with("JP13", "TEST", Time.new(2021, 6, 22, 1, 0, 0, "+09:00")).and_return(recorded_paths[0]) 66 | expect(radiko).to receive(:rec).with("JP13", "TEST", Time.new(2021, 6, 22, 2, 0, 0, "+09:00")).and_return(recorded_paths[1]) 67 | expect(concater).to receive(:concat).with(recorded_paths).and_return("/path/to/concated.m4a") 68 | 69 | episode = recorder.rec(def_, now) 70 | expect(episode).to eq( 71 | Episode.new( 72 | id: "test", 73 | station: "TEST", 74 | start_time: Time.new(2021, 6, 22, 1, 0, 0, "+09:00"), 75 | local_path: "/path/to/concated.m4a", 76 | ) 77 | ) 78 | end 79 | end 80 | end 81 | end 82 | end 83 | -------------------------------------------------------------------------------- /gen_feed/spec/s3_spec.rb: -------------------------------------------------------------------------------- 1 | require "aws-sdk-s3" 2 | 3 | module Radicaster::GenFeed 4 | describe S3 do 5 | let(:client) { double("client") } 6 | let(:bucket) { "dummy-bucket" } 7 | let(:url) { "http://radicaster.test" } 8 | let(:id) { "dummy-program-id" } 9 | 10 | subject(:s3) { S3.new(client, bucket, url) } 11 | 12 | describe "#find_definition" do 13 | let(:def_body) do 14 | <<~EOS 15 | title: dummy-title 16 | author: dummy-author 17 | summary: dummy-summary 18 | image: http://foo.test/bar.png 19 | EOS 20 | end 21 | 22 | it "finds a defintion file according to passed prefix and returns a Definition object" do 23 | key = "#{id}/radicaster.yaml" 24 | resp = double("response", body: StringIO.new(def_body)) 25 | expect(client).to receive(:get_object) 26 | .with(bucket: bucket, key: key) 27 | .and_return(resp) 28 | 29 | def_ = s3.find_definition(id) 30 | 31 | expect(def_.title).to eq("dummy-title") 32 | expect(def_.author).to eq("dummy-author") 33 | expect(def_.summary).to eq("dummy-summary") 34 | expect(def_.image).to eq("http://foo.test/bar.png") 35 | end 36 | end 37 | 38 | describe "#list_episodes" do 39 | it "search audio files from specified path and returns an array of Episode" do 40 | # mocking s3 response 41 | ep1_key = "#{id}/20210101.m4a" 42 | ep2_key = "#{id}/20210102.m4a" 43 | non_audio_key = "#{id}/20210101.txt" 44 | ep1_obj = instance_double(Aws::S3::Types::Object, "ep1", key: ep1_key, size: 100, last_modified: Time.now) 45 | ep2_obj = instance_double(Aws::S3::Types::Object, "ep2", key: ep2_key, size: 100, last_modified: Time.now) 46 | non_audio_obj = instance_double(Aws::S3::Types::Object, "non-audio", key: non_audio_key, size: 100, last_modified: Time.now) 47 | resp = instance_double(Aws::S3::Types::ListObjectsV2Output, "resp", { 48 | :contents => [ 49 | ep1_obj, 50 | ep2_obj, 51 | non_audio_obj, 52 | ], 53 | }) 54 | expect(client).to receive(:list_objects_v2).with( 55 | bucket: bucket, 56 | prefix: id + "/", 57 | ) 58 | .and_return(resp) 59 | episodes = s3.list_episodes(id) 60 | expect(episodes.map(&:title)).to eq(["20210102.m4a", "20210101.m4a"]) 61 | end 62 | end 63 | 64 | describe "#save_feed" do 65 | let(:feed_body) { "feed_body" } 66 | 67 | it "uploads passed body with proper key" do 68 | key = "dummy-program-id/index.rss" 69 | expect(client).to receive(:put_object).with(bucket: bucket, key: key, body: feed_body) 70 | s3.save_feed(id, feed_body) 71 | end 72 | end 73 | end 74 | end 75 | -------------------------------------------------------------------------------- /cli/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | ast (2.4.2) 5 | aws-eventstream (1.1.1) 6 | aws-partitions (1.461.0) 7 | aws-sdk-core (3.114.0) 8 | aws-eventstream (~> 1, >= 1.0.2) 9 | aws-partitions (~> 1, >= 1.239.0) 10 | aws-sigv4 (~> 1.1) 11 | jmespath (~> 1.0) 12 | aws-sdk-eventbridge (1.24.0) 13 | aws-sdk-core (~> 3, >= 3.112.0) 14 | aws-sigv4 (~> 1.1) 15 | aws-sdk-kms (1.43.0) 16 | aws-sdk-core (~> 3, >= 3.112.0) 17 | aws-sigv4 (~> 1.1) 18 | aws-sdk-lambda (1.62.0) 19 | aws-sdk-core (~> 3, >= 3.112.0) 20 | aws-sigv4 (~> 1.1) 21 | aws-sdk-s3 (1.95.0) 22 | aws-sdk-core (~> 3, >= 3.112.0) 23 | aws-sdk-kms (~> 1) 24 | aws-sigv4 (~> 1.1) 25 | aws-sigv4 (1.2.3) 26 | aws-eventstream (~> 1, >= 1.0.2) 27 | binding_ninja (0.2.3) 28 | coderay (1.1.3) 29 | diff-lcs (1.4.4) 30 | ffi (1.15.1) 31 | formatador (0.2.5) 32 | guard (2.17.0) 33 | formatador (>= 0.2.4) 34 | listen (>= 2.7, < 4.0) 35 | lumberjack (>= 1.0.12, < 2.0) 36 | nenv (~> 0.1) 37 | notiffany (~> 0.0) 38 | pry (>= 0.9.12) 39 | shellany (~> 0.0) 40 | thor (>= 0.18.1) 41 | guard-compat (1.2.1) 42 | guard-rspec (4.7.3) 43 | guard (~> 2.1) 44 | guard-compat (~> 1.1) 45 | rspec (>= 2.99.0, < 4.0) 46 | jmespath (1.4.0) 47 | listen (3.5.1) 48 | rb-fsevent (~> 0.10, >= 0.10.3) 49 | rb-inotify (~> 0.9, >= 0.9.10) 50 | lumberjack (1.2.8) 51 | method_source (1.0.0) 52 | nenv (0.3.0) 53 | notiffany (0.1.3) 54 | nenv (~> 0.1) 55 | shellany (~> 0.0) 56 | parser (3.0.1.1) 57 | ast (~> 2.4.1) 58 | proc_to_ast (0.1.0) 59 | coderay 60 | parser 61 | unparser 62 | pry (0.14.1) 63 | coderay (~> 1.1) 64 | method_source (~> 1.0) 65 | rb-fsevent (0.11.0) 66 | rb-inotify (0.10.1) 67 | ffi (~> 1.0) 68 | rspec (3.10.0) 69 | rspec-core (~> 3.10.0) 70 | rspec-expectations (~> 3.10.0) 71 | rspec-mocks (~> 3.10.0) 72 | rspec-core (3.10.1) 73 | rspec-support (~> 3.10.0) 74 | rspec-expectations (3.10.1) 75 | diff-lcs (>= 1.2.0, < 2.0) 76 | rspec-support (~> 3.10.0) 77 | rspec-its (1.3.0) 78 | rspec-core (>= 3.0.0) 79 | rspec-expectations (>= 3.0.0) 80 | rspec-mocks (3.10.2) 81 | diff-lcs (>= 1.2.0, < 2.0) 82 | rspec-support (~> 3.10.0) 83 | rspec-parameterized (0.4.2) 84 | binding_ninja (>= 0.2.3) 85 | parser 86 | proc_to_ast 87 | rspec (>= 2.13, < 4) 88 | unparser 89 | rspec-support (3.10.2) 90 | shellany (0.0.1) 91 | thor (1.1.0) 92 | unparser (0.6.0) 93 | diff-lcs (~> 1.3) 94 | parser (>= 3.0.0) 95 | 96 | PLATFORMS 97 | ruby 98 | 99 | DEPENDENCIES 100 | aws-sdk-eventbridge 101 | aws-sdk-lambda 102 | aws-sdk-s3 103 | guard-rspec 104 | rspec (~> 3.0) 105 | rspec-its 106 | rspec-mocks 107 | rspec-parameterized 108 | 109 | RUBY VERSION 110 | ruby 2.7.2p137 111 | 112 | BUNDLED WITH 113 | 2.1.4 114 | -------------------------------------------------------------------------------- /cli/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "rspec/its" 2 | require "rspec-parameterized" 3 | require "cli" 4 | 5 | # This file was generated by the `rspec --init` command. Conventionally, all 6 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 7 | # The generated `.rspec` file contains `--require spec_helper` which will cause 8 | # this file to always be loaded, without a need to explicitly require it in any 9 | # files. 10 | # 11 | # Given that it is always loaded, you are encouraged to keep this file as 12 | # light-weight as possible. Requiring heavyweight dependencies from this file 13 | # will add to the boot time of your test suite on EVERY test run, even for an 14 | # individual file that may not need all of that loaded. Instead, consider making 15 | # a separate helper file that requires the additional dependencies and performs 16 | # the additional setup, and require it from the spec files that actually need 17 | # it. 18 | # 19 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 20 | RSpec.configure do |config| 21 | # rspec-expectations config goes here. You can use an alternate 22 | # assertion/expectation library such as wrong or the stdlib/minitest 23 | # assertions if you prefer. 24 | config.expect_with :rspec do |expectations| 25 | # This option will default to `true` in RSpec 4. It makes the `description` 26 | # and `failure_message` of custom matchers include text for helper methods 27 | # defined using `chain`, e.g.: 28 | # be_bigger_than(2).and_smaller_than(4).description 29 | # # => "be bigger than 2 and smaller than 4" 30 | # ...rather than: 31 | # # => "be bigger than 2" 32 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 33 | end 34 | 35 | # rspec-mocks config goes here. You can use an alternate test double 36 | # library (such as bogus or mocha) by changing the `mock_with` option here. 37 | config.mock_with :rspec do |mocks| 38 | # Prevents you from mocking or stubbing a method that does not exist on 39 | # a real object. This is generally recommended, and will default to 40 | # `true` in RSpec 4. 41 | mocks.verify_partial_doubles = true 42 | mocks.verify_doubled_constant_names = true 43 | end 44 | 45 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 46 | # have no way to turn it off -- the option exists only for backwards 47 | # compatibility in RSpec 3). It causes shared context metadata to be 48 | # inherited by the metadata hash of host groups and examples, rather than 49 | # triggering implicit auto-inclusion in groups with matching metadata. 50 | config.shared_context_metadata_behavior = :apply_to_host_groups 51 | 52 | # The settings below are suggested to provide a good initial experience 53 | # with RSpec, but feel free to customize to your heart's content. 54 | =begin 55 | # This allows you to limit a spec run to individual examples or groups 56 | # you care about by tagging them with `:focus` metadata. When nothing 57 | # is tagged with `:focus`, all examples get run. RSpec also provides 58 | # aliases for `it`, `describe`, and `context` that include `:focus` 59 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 60 | config.filter_run_when_matching :focus 61 | 62 | # Allows RSpec to persist some state between runs in order to support 63 | # the `--only-failures` and `--next-failure` CLI options. We recommend 64 | # you configure your source control system to ignore this file. 65 | config.example_status_persistence_file_path = "spec/examples.txt" 66 | 67 | # Limits the available syntax to the non-monkey patched syntax that is 68 | # recommended. For more details, see: 69 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 70 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 71 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 72 | config.disable_monkey_patching! 73 | 74 | # This setting enables warnings. It's recommended, but in some cases may 75 | # be too noisy due to issues in dependencies. 76 | config.warnings = true 77 | 78 | # Many RSpec users commonly either run the entire suite or an individual 79 | # file, and it's useful to allow more verbose output when running an 80 | # individual spec file. 81 | if config.files_to_run.one? 82 | # Use the documentation formatter for detailed output, 83 | # unless a formatter has already been configured 84 | # (e.g. via a command-line flag). 85 | config.default_formatter = "doc" 86 | end 87 | 88 | # Print the 10 slowest examples and example groups at the 89 | # end of the spec run, to help surface which specs are running 90 | # particularly slow. 91 | config.profile_examples = 10 92 | 93 | # Run specs in random order to surface order dependencies. If you find an 94 | # order dependency and want to debug it, you can fix the order by providing 95 | # the seed, which is printed after each run. 96 | # --seed 1234 97 | config.order = :random 98 | 99 | # Seed global randomization in this process using the `--seed` CLI option. 100 | # Setting this allows you to use `--seed` to deterministically reproduce 101 | # test failures related to randomization by passing the same `--seed` value 102 | # as the one that triggered the failure. 103 | Kernel.srand config.seed 104 | =end 105 | end 106 | -------------------------------------------------------------------------------- /gen_feed/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "rspec/its" 2 | require "rspec-parameterized" 3 | require "gen-feed" 4 | 5 | # This file was generated by the `rspec --init` command. Conventionally, all 6 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 7 | # The generated `.rspec` file contains `--require spec_helper` which will cause 8 | # this file to always be loaded, without a need to explicitly require it in any 9 | # files. 10 | # 11 | # Given that it is always loaded, you are encouraged to keep this file as 12 | # light-weight as possible. Requiring heavyweight dependencies from this file 13 | # will add to the boot time of your test suite on EVERY test run, even for an 14 | # individual file that may not need all of that loaded. Instead, consider making 15 | # a separate helper file that requires the additional dependencies and performs 16 | # the additional setup, and require it from the spec files that actually need 17 | # it. 18 | # 19 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 20 | RSpec.configure do |config| 21 | # rspec-expectations config goes here. You can use an alternate 22 | # assertion/expectation library such as wrong or the stdlib/minitest 23 | # assertions if you prefer. 24 | config.expect_with :rspec do |expectations| 25 | # This option will default to `true` in RSpec 4. It makes the `description` 26 | # and `failure_message` of custom matchers include text for helper methods 27 | # defined using `chain`, e.g.: 28 | # be_bigger_than(2).and_smaller_than(4).description 29 | # # => "be bigger than 2 and smaller than 4" 30 | # ...rather than: 31 | # # => "be bigger than 2" 32 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 33 | end 34 | 35 | # rspec-mocks config goes here. You can use an alternate test double 36 | # library (such as bogus or mocha) by changing the `mock_with` option here. 37 | config.mock_with :rspec do |mocks| 38 | # Prevents you from mocking or stubbing a method that does not exist on 39 | # a real object. This is generally recommended, and will default to 40 | # `true` in RSpec 4. 41 | mocks.verify_partial_doubles = true 42 | mocks.verify_doubled_constant_names = true 43 | end 44 | 45 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 46 | # have no way to turn it off -- the option exists only for backwards 47 | # compatibility in RSpec 3). It causes shared context metadata to be 48 | # inherited by the metadata hash of host groups and examples, rather than 49 | # triggering implicit auto-inclusion in groups with matching metadata. 50 | config.shared_context_metadata_behavior = :apply_to_host_groups 51 | 52 | # The settings below are suggested to provide a good initial experience 53 | # with RSpec, but feel free to customize to your heart's content. 54 | =begin 55 | # This allows you to limit a spec run to individual examples or groups 56 | # you care about by tagging them with `:focus` metadata. When nothing 57 | # is tagged with `:focus`, all examples get run. RSpec also provides 58 | # aliases for `it`, `describe`, and `context` that include `:focus` 59 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 60 | config.filter_run_when_matching :focus 61 | 62 | # Allows RSpec to persist some state between runs in order to support 63 | # the `--only-failures` and `--next-failure` CLI options. We recommend 64 | # you configure your source control system to ignore this file. 65 | config.example_status_persistence_file_path = "spec/examples.txt" 66 | 67 | # Limits the available syntax to the non-monkey patched syntax that is 68 | # recommended. For more details, see: 69 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 70 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 71 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 72 | config.disable_monkey_patching! 73 | 74 | # This setting enables warnings. It's recommended, but in some cases may 75 | # be too noisy due to issues in dependencies. 76 | config.warnings = true 77 | 78 | # Many RSpec users commonly either run the entire suite or an individual 79 | # file, and it's useful to allow more verbose output when running an 80 | # individual spec file. 81 | if config.files_to_run.one? 82 | # Use the documentation formatter for detailed output, 83 | # unless a formatter has already been configured 84 | # (e.g. via a command-line flag). 85 | config.default_formatter = "doc" 86 | end 87 | 88 | # Print the 10 slowest examples and example groups at the 89 | # end of the spec run, to help surface which specs are running 90 | # particularly slow. 91 | config.profile_examples = 10 92 | 93 | # Run specs in random order to surface order dependencies. If you find an 94 | # order dependency and want to debug it, you can fix the order by providing 95 | # the seed, which is printed after each run. 96 | # --seed 1234 97 | config.order = :random 98 | 99 | # Seed global randomization in this process using the `--seed` CLI option. 100 | # Setting this allows you to use `--seed` to deterministically reproduce 101 | # test failures related to randomization by passing the same `--seed` value 102 | # as the one that triggered the failure. 103 | Kernel.srand config.seed 104 | =end 105 | end 106 | -------------------------------------------------------------------------------- /rec_radiko/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "rspec/its" 2 | require "rspec-parameterized" 3 | require "rec-radiko" 4 | 5 | # This file was generated by the `rspec --init` command. Conventionally, all 6 | # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. 7 | # The generated `.rspec` file contains `--require spec_helper` which will cause 8 | # this file to always be loaded, without a need to explicitly require it in any 9 | # files. 10 | # 11 | # Given that it is always loaded, you are encouraged to keep this file as 12 | # light-weight as possible. Requiring heavyweight dependencies from this file 13 | # will add to the boot time of your test suite on EVERY test run, even for an 14 | # individual file that may not need all of that loaded. Instead, consider making 15 | # a separate helper file that requires the additional dependencies and performs 16 | # the additional setup, and require it from the spec files that actually need 17 | # it. 18 | # 19 | # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration 20 | RSpec.configure do |config| 21 | # rspec-expectations config goes here. You can use an alternate 22 | # assertion/expectation library such as wrong or the stdlib/minitest 23 | # assertions if you prefer. 24 | config.expect_with :rspec do |expectations| 25 | # This option will default to `true` in RSpec 4. It makes the `description` 26 | # and `failure_message` of custom matchers include text for helper methods 27 | # defined using `chain`, e.g.: 28 | # be_bigger_than(2).and_smaller_than(4).description 29 | # # => "be bigger than 2 and smaller than 4" 30 | # ...rather than: 31 | # # => "be bigger than 2" 32 | expectations.include_chain_clauses_in_custom_matcher_descriptions = true 33 | end 34 | 35 | # rspec-mocks config goes here. You can use an alternate test double 36 | # library (such as bogus or mocha) by changing the `mock_with` option here. 37 | config.mock_with :rspec do |mocks| 38 | # Prevents you from mocking or stubbing a method that does not exist on 39 | # a real object. This is generally recommended, and will default to 40 | # `true` in RSpec 4. 41 | mocks.verify_partial_doubles = true 42 | mocks.verify_doubled_constant_names = true 43 | end 44 | 45 | # This option will default to `:apply_to_host_groups` in RSpec 4 (and will 46 | # have no way to turn it off -- the option exists only for backwards 47 | # compatibility in RSpec 3). It causes shared context metadata to be 48 | # inherited by the metadata hash of host groups and examples, rather than 49 | # triggering implicit auto-inclusion in groups with matching metadata. 50 | config.shared_context_metadata_behavior = :apply_to_host_groups 51 | 52 | # The settings below are suggested to provide a good initial experience 53 | # with RSpec, but feel free to customize to your heart's content. 54 | =begin 55 | # This allows you to limit a spec run to individual examples or groups 56 | # you care about by tagging them with `:focus` metadata. When nothing 57 | # is tagged with `:focus`, all examples get run. RSpec also provides 58 | # aliases for `it`, `describe`, and `context` that include `:focus` 59 | # metadata: `fit`, `fdescribe` and `fcontext`, respectively. 60 | config.filter_run_when_matching :focus 61 | 62 | # Allows RSpec to persist some state between runs in order to support 63 | # the `--only-failures` and `--next-failure` CLI options. We recommend 64 | # you configure your source control system to ignore this file. 65 | config.example_status_persistence_file_path = "spec/examples.txt" 66 | 67 | # Limits the available syntax to the non-monkey patched syntax that is 68 | # recommended. For more details, see: 69 | # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ 70 | # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ 71 | # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode 72 | config.disable_monkey_patching! 73 | 74 | # This setting enables warnings. It's recommended, but in some cases may 75 | # be too noisy due to issues in dependencies. 76 | config.warnings = true 77 | 78 | # Many RSpec users commonly either run the entire suite or an individual 79 | # file, and it's useful to allow more verbose output when running an 80 | # individual spec file. 81 | if config.files_to_run.one? 82 | # Use the documentation formatter for detailed output, 83 | # unless a formatter has already been configured 84 | # (e.g. via a command-line flag). 85 | config.default_formatter = "doc" 86 | end 87 | 88 | # Print the 10 slowest examples and example groups at the 89 | # end of the spec run, to help surface which specs are running 90 | # particularly slow. 91 | config.profile_examples = 10 92 | 93 | # Run specs in random order to surface order dependencies. If you find an 94 | # order dependency and want to debug it, you can fix the order by providing 95 | # the seed, which is printed after each run. 96 | # --seed 1234 97 | config.order = :random 98 | 99 | # Seed global randomization in this process using the `--seed` CLI option. 100 | # Setting this allows you to use `--seed` to deterministically reproduce 101 | # test failures related to randomization by passing the same `--seed` value 102 | # as the one that triggered the failure. 103 | Kernel.srand config.seed 104 | =end 105 | end 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | **Please do not use this project for commercial use. Only for your personal, non-commercial use.**
2 | **個人での視聴の目的以外で利用しないでください.** 3 | 4 | # radicaster 5 | 6 | radicasterはAWSの各種マネージドサービスを活用し、radikoのお好きな番組を録音・Podcast化するアプリケーションです。 7 | 8 | ## 特徴 9 | 10 | - FaaSを活用したアーキテクチャにより低コストで運用可能 11 | - 普通の使い方であればストレージ以外はほぼ無料 12 | - AWS CDKによる簡単なデプロイ 13 | - 分割された番組の結合に対応 14 | - HTTPS+Basic認証によるフィードの保護 15 | - 独自ドメインを使用可能 16 | 17 | ## 構成 18 | 19 | ![](./radicaster.png) 20 | 21 | ### 主な使用サービス 22 | 23 | - Lambda 24 | - EventBridge 25 | - S3 26 | - CloudFront 27 | 28 | ## デプロイ方法 29 | 30 | ### 事前準備 31 | 32 | #### 必要なもの 33 | 34 | - Docker 35 | - Node.js >= 10.13.0 36 | - 13.0.0 〜 13.6.0 はCDKが動かないのでそれ以外のバージョンを使用してください 37 | 38 | #### リポジトリのclone 39 | 40 | ```bash 41 | git@github.com:l3msh0/radicaster.git 42 | ``` 43 | 44 | #### AWSプロファイルの準備 45 | 46 | デプロイに使用するAWSアカウントやリージョンは `AWS_ACCESS_KEY_ID` や `AWS_REGION` などの環境変数でも指定できますが、プロファイルを使用することを推奨します。 47 | 48 | プロファイルの設定を行い、後続の作業は環境変数 `AWS_PROFILE` にプロファイル名をセットした上で実行してください。 49 | 50 | #### AWS CDKのインストール 51 | 52 | デプロイにはAWS CDKを使用します。以下のコマンドを実行してCDKをインストールしてください。 53 | 54 | ```bash 55 | npm install -g aws-cdk 56 | ``` 57 | 58 | AWS CDKについての詳細は[AWSのドキュメント](https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html)を参照してください。 59 | 60 | #### CDK bootstrap 61 | 62 | CDKによるデプロイを行うにあたって、事前にbootstrapという作業が必要となります。 63 | 以下のコマンドを実行してbootstrapを行ってください。Basic認証のためにLambda@Edgeを使用する都合でus-east-1リージョンもbootstrapが必要です。 64 | 65 | ```bash 66 | cdk bootstrap aws:///us-east-1 aws:///ap-northeast-1 67 | ``` 68 | 69 | 参考 70 | - [Bootstrapping - AWS Cloud Development Kit (CDK)](https://docs.aws.amazon.com/cdk/latest/guide/bootstrapping.html) 71 | 72 | ### 環境変数の準備 73 | 74 | cloneしたリポジトリ直下にある `.env.example` ファイルをコピーし、コメントに従って必要な値を入力します。 75 | `RADICASTER_REC_RADIKO_ARN` については、CDKを実行してリソースが作成されないと記入できないためこの時点では無視してください。 76 | 77 | ```bash 78 | cp .env.example .env 79 | vim .env 80 | ``` 81 | 82 | 一通り入力ができたら、sourceコマンドでファイルに記載された環境変数を現在のシェルにセットします。 83 | 84 | ```bash 85 | source .env 86 | ``` 87 | 88 | ### CDK実行 89 | 90 | CDKを実行し、AWS上にradicasterが使用するリソースを作成します。 91 | 92 | ```bash 93 | export AWS_PROFILE=AWSプロファイル名 94 | cd deployment 95 | cdk deploy --all 96 | ``` 97 | 98 | ### 環境変数の更新 99 | 100 | CDKを実行すると実行結果のOutputsが出力されます。その中から `RadicasterStack.RecRadikoARN` の値をコピーし、.envの `RADICASTER_REC_RADIKO_ARN` の値にセットしてください。 101 | 102 | CDK実行結果の例 103 | ``` 104 | Outputs: 105 | RadicasterStack.RecRadikoARN = arn:aws:lambda:ap-northeast-1:xxxxxxxxxxxx:function:radicaster-rec-radiko 106 | RadicasterStack.domainName = https://xxxxxxxxxxxxxx.cloudfront.net 107 | ``` 108 | 109 | 以上でリソースの作成は完了です。 110 | 111 | ## 録音方法 112 | 113 | 番組を録音するには、録音したい番組の情報をYAMLで定義しCLIに渡します。 114 | 115 | CLIはYAMLの内容に基づいて録音ファイル格納用S3のセットアップし、録音用Lambdaの定期実行をスケジュールします。 116 | 117 | ### 依存パッケージのインストール 118 | 119 | ``` 120 | cd cli 121 | bundle install 122 | ``` 123 | 124 | ### 定義ファイルを作成する 125 | 126 | 以下のフォーマットで、Podcast化したい番組の情報を記述します。 127 | 128 | ```yaml 129 | id: example # 番組ID: 番組を一意に識別する文字列で、AWSの各種リソースの命名やURLなどに使用されます 130 | title: テスト番組 # 番組名: 生成されるPodcastフィードの番組名に使用されます 131 | author: テスト太郎 # 作者: 生成されるPodcastの作者フィールドに使用されます 132 | image: http://example.com/cover.png # 画像: Podcastの番組サムネイルに使用する画像のURLを指定します 133 | area: JP13 # エリアID: 録音対象のradikoのエリアIDを指定します。デプロイ時にradikoプレミアムの認証情報を指定しない場合はJP13のみ指定できます。 134 | station: TEST # 放送局: 録音対象の放送局を指定します 135 | program_schedule: Tue 01:00:00 # 番組開始日時: 録音対象番組の放送開始曜日と時間を日本時間で指定します 136 | execution_schedule: Tue 03:03:00 # 録音開始日時: 録音処理を実行する曜日と日時を日本時間で指定します。録音処理はタイムフリーのAPIを使用して行うため、番組終了後の任意の時間を指定してください。 137 | ``` 138 | 139 | #### Tips: 番組の連結、複数曜日の指定 140 | 141 | 定義ファイルの `program_schedule` と `execution_schedule` を配列にすることで複数曜日に放送される番組の録音ができます。さらに二次元配列にすることで、放送時間が長く分割された番組を1エピソードとして連結することができます。 142 | 143 | 例. 月〜木曜に放送される 8:30-10:00, 10:00-11:00 に分割された番組を録音予約する例 144 | 145 | ```yaml 146 | id: example 147 | title: テスト番組 148 | author: テスト太郎 149 | image: http://example.com/cover.png 150 | area: JP13 151 | station: TEST 152 | program_schedule: 153 | - ["Mon 08:30:00", "Mon 10:00:00"] 154 | - ["Tue 08:30:00", "Tue 10:00:00"] 155 | - ["Wed 08:30:00", "Wed 10:00:00"] 156 | - ["Thu 08:30:00", "Thu 10:00:00"] 157 | execution_schedule: 158 | - Mon 12:00:00 159 | - Tue 12:00:00 160 | - Wed 12:00:00 161 | - Thu 12:00:00 162 | ``` 163 | 164 | radikoの番組表上は8:30開始の番組と10:00開始の番組は別のものですが、上記のように `["Mon 08:30:00", "Mon 10:00:00"]` と記載することでPodcast上は1つのエピソードとして扱うことができます。 165 | 166 | 録音処理では直近の1エピソードのみを対象として録音を行います。例えば火曜12:00に起動する処理で録音されるのは `["Tue 08:30:00", "Tue 10:00:00"]` のエピソードのみです。したがって、複数曜日の番組を録音する場合は上記の例のように `execution_schedule` も各曜日分指定してください。 167 | 168 | 169 | ### 録音を予約する 170 | 171 | .envに記載した環境変数を読み込んだ上で、CLIを実行します。`AWS_PROFILE`など、AWSアカウントの認証情報やリージョンを特定する環境変数も忘れずにセットしておいてください。 172 | 173 | ``` 174 | source .env 175 | cd cli 176 | ./bin/radicaster example.yaml 177 | ``` 178 | 179 | 上記のコマンドを実行すると、定義ファイルの内容に基づいて以下の処理が行われます。 180 | 181 | - 録音ファイル出力先のS3バケットに定義ファイルをアップロード 182 | - EventBridge へ録音の定期実行ルールを登録 183 | 184 | ## フィードの購読 185 | 186 | 録音予約を行うと直近の放送分が自動的に録音されPodcastのフィードが生成され購読できる状態になりますので、お好みのPodcastアプリでフィードを購読してください。 187 | 188 | フィードのURLは `https://(CDK実行時に表示されたドメイン名)/(定義ファイルに記載したID)/` の形式です。(e.g. https://xxxxxxxxxxxxxx.cloudfront.net/test/) 189 | 190 | ### Basic認証付きフィード 191 | 192 | radicasterは著作権保護のためPodcastフィードをBasic認証で保護します。このため、Podcastアプリでフィードを購読する際は認証情報を指定する必要があります。 193 | 194 | 認証情報の入力方法はアプリによって異なりますが、認証情報の入力欄がない場合は `https://ユーザ名:パスワード@example.com/` のようにURLに認証情報を含めることで認証付きフィードを購読できることが多いです。(Apple Podcastなど) 195 | 196 | #### 認証付きフィードの購読が確認できているアプリ 197 | 198 | - iOS 199 | - Apple Podcasts 200 | - Overcast 201 | - Android 202 | - Podcast Addict 203 | 204 | #### 認証付きフィードの購読ができないと思われるアプリ 205 | 206 | - Google Podcasts 207 | -------------------------------------------------------------------------------- /rec_radiko/spec/definition_spec.rb: -------------------------------------------------------------------------------- 1 | module Radicaster::RecRadiko 2 | describe Definition do 3 | describe ".parse" do 4 | context "input is valid" do 5 | subject { Definition.parse(input) } 6 | 7 | context "and has single start time" do 8 | let(:input) do 9 | <<~EOS 10 | id: test 11 | title: テスト番組 12 | author: テスト太郎 13 | image: http://example.com/cover.png 14 | area: JP13 15 | station: TEST 16 | program_schedule: Tue 01:00:00 17 | execution_schedule: Tue 03:03:00 18 | EOS 19 | end 20 | it { 21 | is_expected.to eq(Definition.new( 22 | id: "test", 23 | area: "JP13", 24 | station: "TEST", 25 | program_schedule: Schedule.new(ScheduleItem.new("Tue", 1, 0, 0)), 26 | )) 27 | } 28 | end 29 | 30 | context "and has multiple start times" do 31 | let(:input) do 32 | <<~EOS 33 | id: test 34 | title: テスト番組 35 | author: テスト太郎 36 | image: http://example.com/cover.png 37 | area: JP13 38 | station: TEST 39 | program_schedule: 40 | - Mon 08:30:00 41 | - Tue 08:30:00 42 | execution_schedule: Tue 03:03:00 43 | EOS 44 | end 45 | it { 46 | is_expected.to eq(Definition.new( 47 | id: "test", 48 | area: "JP13", 49 | station: "TEST", 50 | program_schedule: Schedule.new( 51 | ScheduleItem.new("Mon", 8, 30, 0), 52 | ScheduleItem.new("Tue", 8, 30, 0), 53 | ), 54 | )) 55 | } 56 | end 57 | 58 | context "and has combined start times" do 59 | let(:input) do 60 | <<~EOS 61 | id: test 62 | title: テスト番組 63 | author: テスト太郎 64 | image: http://example.com/cover.png 65 | area: JP13 66 | station: TEST 67 | program_schedule: 68 | - ["Mon 08:30:00", "Mon 10:00:00"] 69 | execution_schedule: Tue 03:03:00 70 | EOS 71 | end 72 | it { 73 | is_expected.to eq(Definition.new( 74 | id: "test", 75 | area: "JP13", 76 | station: "TEST", 77 | program_schedule: Schedule.new( 78 | CombinedScheduleItem.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Mon", 10, 0, 0)) 79 | ), 80 | )) 81 | } 82 | end 83 | end 84 | 85 | context "input is invlalid" do 86 | context "required key not found" do 87 | where(:input) do 88 | [ 89 | [ 90 | <<~EOS 91 | area: JP13 92 | station: TEST 93 | program_schedule: 94 | - ["Mon 08:30:00", "Mon 10:00:00"] 95 | EOS 96 | ], 97 | [ 98 | <<~EOS 99 | id: test 100 | station: TEST 101 | program_schedule: 102 | - ["Mon 08:30:00", "Mon 10:00:00"] 103 | EOS 104 | ], 105 | [ 106 | <<~EOS 107 | id: test 108 | area: JP13 109 | program_schedule: 110 | - ["Mon 08:30:00", "Mon 10:00:00"] 111 | EOS 112 | ], 113 | [ 114 | <<~EOS 115 | id: test 116 | area: JP13 117 | station: TEST 118 | EOS 119 | ], 120 | ] 121 | end 122 | 123 | with_them do 124 | it "raises an ArgumentError" do 125 | expect { Definition.parse(input) }.to raise_error(ArgumentError) 126 | end 127 | end 128 | end 129 | end 130 | end 131 | 132 | describe "#==" do 133 | let!(:this) do 134 | Definition.new( 135 | id: "test", 136 | area: "JP13", 137 | station: "TEST", 138 | program_schedule: Schedule.new( 139 | ScheduleItem.new("Mon", 8, 30, 0), 140 | ScheduleItem.new("Tue", 8, 30, 0), 141 | ), 142 | ) 143 | end 144 | 145 | where(:id, :area, :station, :starts, :expected) do 146 | [ 147 | ["test", "JP13", "TEST", Schedule.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Tue", 8, 30, 0)), true], 148 | ["testX", "JP13", "TEST", Schedule.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Tue", 8, 30, 0)), false], 149 | ["test", "JP13X", "TEST", Schedule.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Tue", 8, 30, 0)), false], 150 | ["test", "JP13", "TESTX", Schedule.new(ScheduleItem.new("Mon", 8, 30, 0), ScheduleItem.new("Tue", 8, 30, 0)), false], 151 | ["test", "JP13", "TEST", Schedule.new(ScheduleItem.new("Mon", 8, 30, 1), ScheduleItem.new("Tue", 8, 30, 0)), false], 152 | ] 153 | end 154 | 155 | let(:other) { Definition.new(id: id, area: area, station: station, program_schedule: starts) } 156 | subject { this == other } 157 | 158 | with_them do 159 | it { is_expected.to eq expected } 160 | end 161 | end 162 | 163 | describe "#latest_start_times" do 164 | let(:id) { "test" } 165 | let(:area) { "JP13" } 166 | let(:station) { "TEST" } 167 | let(:schedule) { 168 | CombinedScheduleItem.new( 169 | ScheduleItem.new("Tue", 1, 0, 0), 170 | ScheduleItem.new("Tue", 2, 0, 0) 171 | ) 172 | } 173 | let(:def_) { 174 | Definition.new( 175 | id: id, 176 | area: area, 177 | station: station, 178 | program_schedule: schedule, 179 | ) 180 | } 181 | let(:now) { Time.new(2021, 6, 23, 0, 0, 0, "+09:00") } # wednesday 182 | 183 | it do 184 | expect(def_.latest_start_times(now)).to eq( 185 | [ 186 | Time.new(2021, 6, 22, 1, 0, 0, "+09:00"), 187 | Time.new(2021, 6, 22, 2, 0, 0, "+09:00"), 188 | ] 189 | ) 190 | end 191 | end 192 | end 193 | end 194 | -------------------------------------------------------------------------------- /deployment/lib/radicaster-stack.ts: -------------------------------------------------------------------------------- 1 | import { Certificate } from '@aws-cdk/aws-certificatemanager'; 2 | import { CachePolicy, Distribution, experimental, LambdaEdgeEventType, OriginAccessIdentity, ViewerProtocolPolicy } from '@aws-cdk/aws-cloudfront'; 3 | import { S3Origin } from '@aws-cdk/aws-cloudfront-origins'; 4 | import { CanonicalUserPrincipal, Effect, PolicyStatement, ServicePrincipal } from '@aws-cdk/aws-iam'; 5 | import { Code, DockerImageCode, DockerImageFunction, Runtime } from '@aws-cdk/aws-lambda'; 6 | import { S3EventSource } from '@aws-cdk/aws-lambda-event-sources'; 7 | import { Bucket, EventType } from '@aws-cdk/aws-s3'; 8 | import * as cdk from '@aws-cdk/core'; 9 | import { CfnOutput, Duration } from '@aws-cdk/core'; 10 | import { readFileSync } from 'fs'; 11 | import * as path from 'path'; 12 | 13 | interface Params { 14 | suffix: string; 15 | bucketName: string; 16 | customDomain?: string; 17 | customDomainCertificateARN?: string 18 | basicAuthUser: string 19 | basicAuthPassword: string 20 | radikoMail?: string; 21 | radikoPassword?: string; 22 | } 23 | 24 | export class RadicasterStack extends cdk.Stack { 25 | constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { 26 | super(scope, id, props); 27 | 28 | const params: Params = { 29 | suffix: this.getEnv('RADICASTER_CDK_SUFFIX') || '', 30 | bucketName: this.mustGetEnv("RADICASTER_S3_BUCKET"), 31 | customDomain: this.getEnv('RADICASTER_CUSTOM_DOMAIN'), 32 | customDomainCertificateARN: this.getEnv('RADICASTER_CUSTOM_DOMAIN_CERT_ARN'), 33 | basicAuthUser: this.mustGetEnv("RADICASTER_BASIC_AUTH_USER"), 34 | basicAuthPassword: this.mustGetEnv("RADICASTER_BASIC_AUTH_PASSWORD"), 35 | radikoMail: this.getEnv('RADICASTER_RADIKO_MAIL'), 36 | radikoPassword: this.getEnv('RADICASTER_RADIKO_PASSWORD'), 37 | } 38 | 39 | const bucket = this.setUpS3Bucket(params); 40 | const dist = this.setUpCloudFront(bucket, params); 41 | this.setUpFuncRecRadiko(bucket, params); 42 | this.setUpFuncGenFeed(bucket, dist, params); 43 | } 44 | 45 | private setUpS3Bucket(params: Params) { 46 | return new Bucket(this, 'bucket', { 47 | bucketName: params.bucketName, 48 | }); 49 | } 50 | 51 | private setUpFuncRecRadiko(bucket: Bucket, params: Params) { 52 | let recRadikoEnvironment 53 | if (params.radikoMail && params.radikoPassword) { 54 | recRadikoEnvironment = { 55 | "RADICASTER_RADIKO_MAIL": params.radikoMail, 56 | "RADICASTER_RADIKO_PASSWORD": params.radikoPassword, 57 | "RADICASTER_S3_BUCKET": params.bucketName 58 | }; 59 | } else { 60 | recRadikoEnvironment = { 61 | "RADICASTER_S3_BUCKET": params.bucketName 62 | }; 63 | } 64 | 65 | const funcRecRadiko = new DockerImageFunction(this, `func-rec-radiko`, { 66 | code: DockerImageCode.fromImageAsset( 67 | "../rec_radiko" 68 | ), 69 | functionName: `radicaster-rec-radiko${params.suffix}`, 70 | timeout: Duration.minutes(10), 71 | memorySize: 768, 72 | environment: recRadikoEnvironment, 73 | }); 74 | funcRecRadiko.grantInvoke(new ServicePrincipal("events.amazonaws.com")); 75 | if (!funcRecRadiko.role) { 76 | throw new Error("funcRecRadiko.role is undefined"); 77 | } 78 | bucket.grantRead(funcRecRadiko.role); 79 | bucket.grantPut(funcRecRadiko.role); 80 | 81 | new CfnOutput(this, `RecRadikoARN`, { 82 | value: funcRecRadiko.functionArn, 83 | description: 'ARN of rec-radiko function' 84 | }); 85 | 86 | return funcRecRadiko; 87 | } 88 | 89 | private setUpFuncGenFeed(bucket: Bucket, dist: Distribution, params: Params) { 90 | const authPrefix = `${params.basicAuthUser}:${params.basicAuthPassword}@` 91 | const domainName = params.customDomain || dist.domainName; 92 | const funcGenFeed = new DockerImageFunction(this, `func-gen-feed`, { 93 | code: DockerImageCode.fromImageAsset( 94 | "../gen_feed" 95 | ), 96 | functionName: `radicaster-gen-feed${params.suffix}`, 97 | timeout: Duration.minutes(1), 98 | memorySize: 128, 99 | environment: { 100 | "RADICASTER_S3_BUCKET": params.bucketName, 101 | "RADICASTER_BUCKET_URL": `https://${authPrefix}${domainName}`, 102 | } 103 | }); 104 | funcGenFeed.grantInvoke(new ServicePrincipal("events.amazonaws.com")); 105 | if (!funcGenFeed.role) { 106 | throw new Error("funcGenFeed.role is undefined"); 107 | } 108 | bucket.grantRead(funcGenFeed.role); 109 | bucket.grantPut(funcGenFeed.role); 110 | 111 | funcGenFeed.addEventSource(new S3EventSource( 112 | bucket, 113 | { 114 | events: [EventType.OBJECT_CREATED], 115 | filters: [{ 116 | suffix: ".m4a" 117 | }], 118 | } 119 | )); 120 | return funcGenFeed; 121 | } 122 | 123 | private setUpCloudFront(bucket: Bucket, params: Params) { 124 | const code = readFileSync(path.join(__dirname, '../assets/basic_auth/function.js')) 125 | .toString() 126 | .replace(/__BASIC_AUTH_USER__/, params.basicAuthUser) 127 | .replace(/__BASIC_AUTH_PASSWORD__/, params.basicAuthPassword); 128 | const fn = new experimental.EdgeFunction(this, 'basic-auth-func', { 129 | code: Code.fromInline(code), 130 | handler: "index.handler", 131 | // NOTE: Node 14.x does not support inline code 132 | runtime: Runtime.NODEJS_12_X, 133 | functionName: `radicaster-basic-auth${params.suffix}`, 134 | memorySize: 128, 135 | }); 136 | 137 | const oai = new OriginAccessIdentity(this, 'oai'); 138 | bucket.addToResourcePolicy(new PolicyStatement({ 139 | effect: Effect.ALLOW, 140 | actions: ["s3:GetObject"], 141 | principals: [ 142 | new CanonicalUserPrincipal(oai.cloudFrontOriginAccessIdentityS3CanonicalUserId), 143 | ], 144 | resources: [bucket.bucketArn + "/*"], 145 | })); 146 | 147 | const domainNames = params.customDomain ? [params.customDomain] : undefined; 148 | const certificate = params.customDomainCertificateARN ? Certificate.fromCertificateArn(this, 'certificate', params.customDomainCertificateARN) : undefined; 149 | const dist = new Distribution(this, 'cloudfront', { 150 | certificate: certificate, 151 | domainNames: domainNames, 152 | defaultBehavior: { 153 | origin: new S3Origin(bucket, { 154 | originAccessIdentity: oai, 155 | }), 156 | edgeLambdas: [ 157 | { 158 | eventType: LambdaEdgeEventType.VIEWER_REQUEST, 159 | functionVersion: fn.currentVersion, 160 | } 161 | ], 162 | viewerProtocolPolicy: ViewerProtocolPolicy.REDIRECT_TO_HTTPS, 163 | cachePolicy: new CachePolicy(this, 'cache-policy', { 164 | defaultTtl: Duration.minutes(1), 165 | maxTtl: Duration.minutes(1), 166 | }) 167 | }, 168 | }); 169 | 170 | const domainName = domainNames ? domainNames[0] : dist.domainName 171 | new CfnOutput(this, `domainName`, { 172 | value: `https://${domainName}`, 173 | description: 'Root URL of Podcast feeds.' 174 | }) 175 | 176 | return dist; 177 | } 178 | 179 | private mustGetEnv(key: string): string { 180 | const value = this.getEnv(key); 181 | if (!value) { 182 | throw new Error(`environment variable ${key} must be set`); 183 | } 184 | return value; 185 | } 186 | 187 | private getEnv(key: string): string | undefined { 188 | return process.env[key]; 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /cli/spec/definition_spec.rb: -------------------------------------------------------------------------------- 1 | require "tempfile" 2 | 3 | module Radicaster::CLI 4 | describe Definition do 5 | describe ".parse" do 6 | context "full schedule format" do 7 | it "returns parsed result" do 8 | yaml_def = <<~EOS 9 | id: test 10 | station: TEST 11 | area: JP13 12 | title: test title 13 | author: test author 14 | image: https://radicaster.test/example.png 15 | program_schedule: 16 | - ["Mon 08:30:00", "Mon 10:00:00"] 17 | - ["Tue 08:30:00", "Tue 10:00:00"] 18 | execution_schedule: 19 | - Mon 12:00:00 20 | - Tue 12:00:00 21 | EOS 22 | def_ = Definition.parse(yaml_def) 23 | 24 | expect(def_).to eq(Definition.new( 25 | id: "test", 26 | area: "JP13", 27 | station: "TEST", 28 | title: "test title", 29 | author: "test author", 30 | image: "https://radicaster.test/example.png", 31 | program_schedule: [ 32 | ["Mon 08:30:00", "Mon 10:00:00"], 33 | ["Tue 08:30:00", "Tue 10:00:00"], 34 | ], 35 | execution_schedule: [ 36 | ExecutionSchedule.new("Mon", 12, 0), 37 | ExecutionSchedule.new("Tue", 12, 0), 38 | ], 39 | )) 40 | end 41 | end 42 | context "simple schedule format" do 43 | it "returns parsed result" do 44 | yaml_def = <<~EOS 45 | id: test 46 | station: TEST 47 | area: JP13 48 | title: test title 49 | author: test author 50 | image: https://radicaster.test/example.png 51 | program_schedule: Tue 01:00:00 52 | execution_schedule: Tue 03:03:00 53 | EOS 54 | def_ = Definition.parse(yaml_def) 55 | 56 | expect(def_).to eq(Definition.new( 57 | id: "test", 58 | area: "JP13", 59 | station: "TEST", 60 | title: "test title", 61 | author: "test author", 62 | image: "https://radicaster.test/example.png", 63 | program_schedule: [ 64 | ["Tue 01:00:00"], 65 | ], 66 | execution_schedule: [ 67 | ExecutionSchedule.new("Tue", 3, 3), 68 | ], 69 | )) 70 | end 71 | end 72 | end 73 | 74 | describe "#to_yaml" do 75 | subject(:def_) { 76 | Definition.new( 77 | id: "test", 78 | area: "JP13", 79 | station: "TEST", 80 | title: "test title", 81 | author: "test author", 82 | image: "http://radicaster.test/example.png", 83 | program_schedule: [ 84 | "Tue 01:00:00", 85 | "Tue 02:00:00", 86 | ], 87 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 88 | ) 89 | } 90 | 91 | it "returns expected yaml string" do 92 | expect(YAML.load(def_.to_yaml)).to eq({ 93 | "id" => "test", 94 | "area" => "JP13", 95 | "station" => "TEST", 96 | "title" => "test title", 97 | "author" => "test author", 98 | "image" => "http://radicaster.test/example.png", 99 | "program_schedule" => ["Tue 01:00:00", "Tue 02:00:00"], 100 | "execution_schedule" => ["Tue 03:03:00"], 101 | }) 102 | end 103 | end 104 | 105 | describe "#==" do 106 | let(:this) { 107 | Definition.new( 108 | id: "test", 109 | title: "test title", 110 | area: "JP13", 111 | station: "TEST", 112 | author: "test author", 113 | image: "http://radicaster.test/example.png", 114 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 115 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 116 | ) 117 | } 118 | where(:other, :expected) do 119 | [ 120 | [Definition.new( 121 | id: "test", 122 | title: "test title", 123 | area: "JP13", 124 | station: "TEST", 125 | author: "test author", 126 | image: "http://radicaster.test/example.png", 127 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 128 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 129 | ), true], 130 | [Definition.new( 131 | id: "xtest", 132 | title: "test title", 133 | area: "JP13", 134 | station: "TEST", 135 | author: "test author", 136 | image: "http://radicaster.test/example.png", 137 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 138 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 139 | ), false], 140 | [Definition.new( 141 | id: "test", 142 | title: "xtest title", 143 | area: "JP13", 144 | station: "TEST", 145 | author: "test author", 146 | image: "http://radicaster.test/example.png", 147 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 148 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 149 | ), false], 150 | [Definition.new( 151 | id: "test", 152 | title: "test title", 153 | area: "JP12", 154 | station: "TEST", 155 | author: "test author", 156 | image: "http://radicaster.test/example.png", 157 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 158 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 159 | ), false], 160 | [Definition.new( 161 | id: "test", 162 | title: "test title", 163 | area: "JP13", 164 | station: "TESTX", 165 | author: "test author", 166 | image: "http://radicaster.test/example.png", 167 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 168 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 169 | ), false], 170 | [Definition.new( 171 | id: "test", 172 | title: "test title", 173 | area: "JP13", 174 | station: "TEST", 175 | author: "xtest author", 176 | image: "http://radicaster.test/example.png", 177 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 178 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 179 | ), false], 180 | [Definition.new( 181 | id: "test", 182 | title: "test title", 183 | area: "JP13", 184 | station: "TEST", 185 | author: "test author", 186 | image: "http://radicaster.test/example.x.png", 187 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 188 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 189 | ), false], 190 | [Definition.new( 191 | id: "test", 192 | title: "test title", 193 | area: "JP13", 194 | station: "TEST", 195 | author: "test author", 196 | image: "http://radicaster.test/example.png", 197 | program_schedule: [["Tue 01:00:00", "Tue 02:00:01"]], 198 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 3)], 199 | ), false], 200 | [Definition.new( 201 | id: "test", 202 | title: "test title", 203 | area: "JP13", 204 | station: "TEST", 205 | author: "test author", 206 | image: "http://radicaster.test/example.png", 207 | program_schedule: [["Tue 01:00:00", "Tue 02:00:00"]], 208 | execution_schedule: [ExecutionSchedule.new("Tue", 3, 4)], 209 | ), false], 210 | ] 211 | end 212 | subject { this == other } 213 | with_them do 214 | it { is_expected.to eq(expected) } 215 | end 216 | end 217 | end 218 | end 219 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------