diff options
author | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-21 01:14:31 +0900 |
---|---|---|
committer | Masaya Tojo <masaya@tojo.tokyo> | 2024-03-21 01:14:31 +0900 |
commit | e28ac6224300ae858076965eade658da68f118aa (patch) | |
tree | e43bc01ba6b2e2afdfeb136e89c36e4cc2c7d315 |
-rw-r--r-- | .github/workflows/ci.yml | 29 | ||||
-rw-r--r-- | .gitignore | 6 | ||||
-rw-r--r-- | LICENSE | 23 | ||||
-rw-r--r-- | README.md | 12 | ||||
-rw-r--r-- | info.rkt | 9 | ||||
-rw-r--r-- | main.rkt | 43 | ||||
-rw-r--r-- | scribblings/get-youtube-rss-url.scrbl | 10 |
7 files changed, 132 insertions, 0 deletions
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..db3e215 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,29 @@ +on: [push, pull_request] +name: CI +jobs: + build: + name: "Build on Racket '${{ matrix.racket-version }}' (${{ matrix.racket-variant }})" + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental || false }} + strategy: + fail-fast: false + matrix: + racket-version: ["stable", "current"] + racket-variant: ["BC", "CS"] + include: + - racket-version: current + experimental: true + steps: + - uses: actions/checkout@v3.1.0 + - uses: Bogdanp/setup-racket@v1.9.1 + with: + architecture: x64 + distribution: full + variant: ${{ matrix.racket-variant }} + version: ${{ matrix.racket-version }} + - name: Installing get-youtube-rss-url and its dependencies + run: raco pkg install --no-docs --auto --name get-youtube-rss-url + - name: Compiling get-youtube-rss-url and building its docs + run: raco setup --check-pkg-deps --unused-pkg-deps get-youtube-rss-url + - name: Testing get-youtube-rss-url + run: raco test -x -p get-youtube-rss-url diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1a59348 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +*~ +\#* +.\#* +.DS_Store +compiled/ +/doc/ @@ -0,0 +1,23 @@ +get-youtube-rss-url + +MIT License + +Copyright (c) 2024 Masaya Tojo <masaya@tojo.tokyo> + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..1bce1e1 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +get-youtube-rss-url +=================== + +Get youtube rss url from youtube channel url. + +Usage +===== + +``` +racket main.rkt <channel url> +``` + diff --git a/info.rkt b/info.rkt new file mode 100644 index 0000000..d1c8ee0 --- /dev/null +++ b/info.rkt @@ -0,0 +1,9 @@ +#lang info +(define collection "get-youtube-rss-url") +(define deps '("base")) +(define build-deps '("scribble-lib" "racket-doc" "rackunit-lib")) +(define scribblings '(("scribblings/get-youtube-rss-url.scrbl" ()))) +(define pkg-desc "Get youtube rss url from youtube channel url.") +(define version "0.0") +(define pkg-authors '(masaya)) +(define license '(MIT)) diff --git a/main.rkt b/main.rkt new file mode 100644 index 0000000..65e9f49 --- /dev/null +++ b/main.rkt @@ -0,0 +1,43 @@ +#lang typed/racket + +(require typed/xml) +(require typed/net/url) +(require srfi/2) + +(require/typed/provide html + [read-html-as-xml (-> Input-Port (Listof XML-Content))]) + +(: get-youtube-rss-url (-> String (Option String))) +(define (get-youtube-rss-url url) + (define-values (status-line _header in) + (http-sendrecv/url (string->url url))) + (cond + [(and-let* ([code (status-line->code status-line)] + [(= code 200)]) + (find-channel-id (map xml->xexpr (read-html-as-xml in)))) + => (lambda (channel-id) + (string-append "https://www.youtube.com/feeds/videos.xml?channel_id=" channel-id))] + [else #f])) + +(: find-channel-id (-> Any (Option String))) +(define (find-channel-id xexpr) + (match xexpr + [`(meta ((content ,content) (itemprop "identifier"))) + (and (string? content) + content)] + [(list* h t) + (or (find-channel-id h) (find-channel-id t))] + [else #f])) + +(: status-line->code (-> Bytes (Option Number))) +(define (status-line->code status-line) + (string->number (second (string-split (bytes->string/utf-8 status-line))))) + +(module+ main + (require racket/cmdline) + (command-line + #:program "get-youtube-rss-url" + #:once-each + #:args (url) + (and (string? url) + (displayln (get-youtube-rss-url url))))) diff --git a/scribblings/get-youtube-rss-url.scrbl b/scribblings/get-youtube-rss-url.scrbl new file mode 100644 index 0000000..d725805 --- /dev/null +++ b/scribblings/get-youtube-rss-url.scrbl @@ -0,0 +1,10 @@ +#lang scribble/manual +@require[@for-label[get-youtube-rss-url + racket/base]] + +@title{get-youtube-rss-url} +@author{Masaya Tojo} + +@defmodule[get-youtube-rss-url] + +Get youtube rss url from youtube channel url. |