123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323 |
- <!DOCTYPE html>
- <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
- <head>
- <meta charset="utf-8" />
- <meta name="generator" content="pandoc" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
- <title>Vids script for Peertube, LBRY and Invidious</title>
- <style>
- code{white-space: pre-wrap;}
- span.smallcaps{font-variant: small-caps;}
- span.underline{text-decoration: underline;}
- div.column{display: inline-block; vertical-align: top; width: 50%;}
- div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
- ul.task-list{list-style: none;}
- pre > code.sourceCode { white-space: pre; position: relative; }
- pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
- pre > code.sourceCode > span:empty { height: 1.2em; }
- .sourceCode { overflow: visible; }
- code.sourceCode > span { color: inherit; text-decoration: inherit; }
- div.sourceCode { margin: 1em 0; }
- pre.sourceCode { margin: 0; }
- @media screen {
- div.sourceCode { overflow: auto; }
- }
- @media print {
- pre > code.sourceCode { white-space: pre-wrap; }
- pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
- }
- pre.numberSource code
- { counter-reset: source-line 0; }
- pre.numberSource code > span
- { position: relative; left: -4em; counter-increment: source-line; }
- pre.numberSource code > span > a:first-child::before
- { content: counter(source-line);
- position: relative; left: -1em; text-align: right; vertical-align: baseline;
- border: none; display: inline-block;
- -webkit-touch-callout: none; -webkit-user-select: none;
- -khtml-user-select: none; -moz-user-select: none;
- -ms-user-select: none; user-select: none;
- padding: 0 4px; width: 4em;
- color: #aaaaaa;
- }
- pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
- div.sourceCode
- { background-color: #f8f8f8; }
- @media screen {
- pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
- }
- code span.al { color: #ef2929; } /* Alert */
- code span.an { color: #8f5902; font-weight: bold; font-style: italic; } /* Annotation */
- code span.at { color: #c4a000; } /* Attribute */
- code span.bn { color: #0000cf; } /* BaseN */
- code span.cf { color: #204a87; font-weight: bold; } /* ControlFlow */
- code span.ch { color: #4e9a06; } /* Char */
- code span.cn { color: #000000; } /* Constant */
- code span.co { color: #8f5902; font-style: italic; } /* Comment */
- code span.cv { color: #8f5902; font-weight: bold; font-style: italic; } /* CommentVar */
- code span.do { color: #8f5902; font-weight: bold; font-style: italic; } /* Documentation */
- code span.dt { color: #204a87; } /* DataType */
- code span.dv { color: #0000cf; } /* DecVal */
- code span.er { color: #a40000; font-weight: bold; } /* Error */
- code span.ex { } /* Extension */
- code span.fl { color: #0000cf; } /* Float */
- code span.fu { color: #000000; } /* Function */
- code span.im { } /* Import */
- code span.in { color: #8f5902; font-weight: bold; font-style: italic; } /* Information */
- code span.kw { color: #204a87; font-weight: bold; } /* Keyword */
- code span.op { color: #ce5c00; font-weight: bold; } /* Operator */
- code span.ot { color: #8f5902; } /* Other */
- code span.pp { color: #8f5902; font-style: italic; } /* Preprocessor */
- code span.sc { color: #000000; } /* SpecialChar */
- code span.ss { color: #4e9a06; } /* SpecialString */
- code span.st { color: #4e9a06; } /* String */
- code span.va { color: #000000; } /* Variable */
- code span.vs { color: #4e9a06; } /* VerbatimString */
- code span.wa { color: #8f5902; font-weight: bold; font-style: italic; } /* Warning */
- .display.math{display: block; text-align: center; margin: 0.5rem auto;}
- </style>
- <link rel="stylesheet" href="C:\SGZ_Pro\Hobbys\Writing\Org\pages\blog\styles.css" />
- <!--[if lt IE 9]>
- <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
- <![endif]-->
- <link rel='stylesheet' type='text/css' href='styles.css' />
- </head>
- <body>
- <header id="title-block-header">
- <h1 class="title">Vids script for Peertube, LBRY and Invidious</h1>
- </header>
- <h1 id="what-is-this-script">What is this script?</h1>
- <p>Script for searching YouTube through the invidious API, LBRY through lighthouse API and peertube through the SepiaSearch API. Played with mpv</p>
- <h1 id="imports">Imports</h1>
- <ul>
- <li><code class="verbatim">requests</code> for fetching data from API's</li>
- <li><code class="verbatim">json</code> for making json better</li>
- <li><code class="verbatim">os</code> for launching mpv</li>
- </ul>
- <div class="sourceCode" id="cb1"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> requests</span>
- <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> json</span>
- <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> os</span>
- <span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> sys</span></code></pre></div>
- <h1 id="banner">Banner</h1>
- <p>This is not at all necasary but I think it makes the script more fun</p>
- <div class="sourceCode" id="cb2"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">print</span>(<span class="st">'''</span></span>
- <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a><span class="st">/-------------------------------</span><span class="ch">\\</span></span>
- <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a><span class="st">| vids |</span></span>
- <span id="cb2-4"><a href="#cb2-4" aria-hidden="true" tabindex="-1"></a><span class="ch">\\</span><span class="st">-------------------------------/</span></span>
- <span id="cb2-5"><a href="#cb2-5" aria-hidden="true" tabindex="-1"></a><span class="st">'''</span>)</span></code></pre></div>
- <h1 id="variables">Variables</h1>
- <ul>
- <li><code class="verbatim">command</code> What the video link will get launched in most likely MPV or a browser</li>
- </ul>
- <p>The colors aren't organized well there just different python color codes. All terminals are configured differently making colors show not always perfect. Better than no color I think.</p>
- <div class="sourceCode" id="cb3"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Use either a browser or mpv</span></span>
- <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>command <span class="op">=</span> <span class="st">"mpv "</span></span>
- <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>bold <span class="op">=</span> <span class="st">"</span><span class="ch">\033</span><span class="st">[01m"</span></span>
- <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>norm <span class="op">=</span> <span class="st">"</span><span class="ch">\033</span><span class="st">[00m"</span></span>
- <span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>bright_cyan <span class="op">=</span> <span class="st">"</span><span class="ch">\033</span><span class="st">[46m"</span></span>
- <span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>colora <span class="op">=</span> <span class="st">"</span><span class="ch">\033</span><span class="st">[45m"</span></span>
- <span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>colorb <span class="op">=</span> <span class="st">"</span><span class="ch">\033</span><span class="st">[44m"</span></span></code></pre></div>
- <h1 id="invidious-search">Invidious search</h1>
- <p>The first thing that happens is this script is put in a <code class="verbatim">try</code> function, if a argument is given to the script e.g. <code class="verbatim">-i</code> it will start doing things with it. If no, it will print out the banner.</p>
- <p>The if statement detects if by <code class="verbatim">sys.argv[1]</code> value if it's <code class="verbatim">-i</code>. The invidious<sub>instance</sub> is set and can be changed to a invidious instance that I like.</p>
- <p>The <code class="verbatim">try</code> and <code class="verbatim">except</code> statement checks to see if possibly the user did a command like:</p>
- <p><code class="verbatim">python vids.py -i "search query"</code></p>
- <p>if they didn't give that 2nd argument of the search it will just prompt them.</p>
- <div class="sourceCode" id="cb4"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="cf">try</span>:</span>
- <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> sys.argv[<span class="dv">1</span>] <span class="op">==</span> <span class="st">"-i"</span>:</span>
- <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> invidious_instance <span class="op">=</span> <span class="st">"https://invidio.xamh.de/"</span></span>
- <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb4-5"><a href="#cb4-5" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> sys.argv[<span class="dv">2</span>]</span>
- <span id="cb4-6"><a href="#cb4-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">input</span>(<span class="st">"Searching for: "</span>)</span>
- <span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">str</span>(query)</span></code></pre></div>
- <h1 id="print-out-search-results">Print out search results</h1>
- <p>Using the invidious search API we fetch the search results and print them out numbered in a for loop.</p>
- <div class="sourceCode" id="cb5"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>size <span class="op">=</span> <span class="bu">str</span>(<span class="dv">19</span>)</span>
- <span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>invidious_search <span class="op">=</span> invidious_instance <span class="op">+</span> <span class="st">"api/v1/search?q="</span> <span class="op">+</span> query</span>
- <span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a>wol_api <span class="op">=</span> <span class="st">"https://scrap.madiator.com/api/get-lbry-video?url="</span></span>
- <span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>data <span class="op">=</span> requests.get(invidious_search)</span>
- <span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>json_stuff <span class="op">=</span> json.loads(data.text)</span>
- <span id="cb5-7"><a href="#cb5-7" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i, vid <span class="kw">in</span> <span class="bu">enumerate</span>(json_stuff):</span>
- <span id="cb5-8"><a href="#cb5-8" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, colora<span class="op">+</span>vid[<span class="st">"title"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>colorb<span class="op">+</span>vid[<span class="st">"author"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>bright_cyan<span class="op">+</span>vid[<span class="st">"videoId"</span>]<span class="op">+</span>norm)</span></code></pre></div>
- <h1 id="pick-a-search-result">Pick a search result</h1>
- <p>This while loop asks the user for a video they want to play and see the comments of. Storing the number they give in a variable so that later it can be used when parsing the json for specific stuff. The reason for a while loop with the special argument is to keep prompting the user over and over to pick the result. It has to be either greater than or equal to <strong>0</strong> or less than or equal to <strong>19</strong>.</p>
- <div class="sourceCode" id="cb6"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>c <span class="op">=</span> <span class="dv">100000</span></span>
- <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> <span class="kw">not</span> c <span class="op">>=</span> <span class="dv">0</span> <span class="kw">or</span> <span class="kw">not</span> c <span class="op"><=</span> <span class="dv">19</span>:</span>
- <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">input</span>(<span class="st">'Number from 1-'</span> <span class="op">+</span> size <span class="op">+</span> <span class="st">" of the URL you want to open: "</span>)</span>
- <span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">int</span>(c)</span>
- <span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="dv">100000</span></span></code></pre></div>
- <h1 id="comments">Comments</h1>
- <p>Using the invidious comment api we fetch the comments of a video with the videoId, there maybe a <strong>error</strong> in the resulting json, most likely because there are no comments. Because of this the if statement prints <code class="verbatim">could not fetch comments</code>.</p>
- <div class="sourceCode" id="cb7"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>comments <span class="op">=</span> invidious_instance <span class="op">+</span> <span class="st">"/api/v1/comments/"</span> <span class="op">+</span> json_stuff[c][<span class="st">"videoId"</span>]</span>
- <span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>data_comment <span class="op">=</span> requests.get(comments)</span>
- <span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a>json_comment <span class="op">=</span> json.loads(data_comment.text)</span>
- <span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> <span class="st">"error"</span> <span class="kw">in</span> json_comment:</span>
- <span id="cb7-5"><a href="#cb7-5" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">"could not fetch comments"</span>)</span>
- <span id="cb7-6"><a href="#cb7-6" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
- <span id="cb7-7"><a href="#cb7-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, comment <span class="kw">in</span> <span class="bu">enumerate</span>(json_comment[<span class="st">"comments"</span>]):</span>
- <span id="cb7-8"><a href="#cb7-8" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, colora<span class="op">+</span>comment[<span class="st">"author"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>colorb<span class="op">+</span>comment[<span class="st">"content"</span>]<span class="op">+</span>norm)</span></code></pre></div>
- <h1 id="wol-api-check">WOL-api check</h1>
- <p>Using the WOL-API we can check if the video is available on LBRY and play with mpv from a odysee.com link over using youtube/invidious. If the lbry check gave <code class="verbatim">null</code> or what python calls it <code class="verbatim">None</code>, the link will be a youtube link, since it's what yt-dlp uses anyways. If the lbry check gave a value that's a lbry url it will play with mpv a odysee link.</p>
- <div class="sourceCode" id="cb8"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="co"># wol-api check</span></span>
- <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a>lbry_check <span class="op">=</span> requests.get(wol_api <span class="op">+</span> json_stuff[c][<span class="st">"videoId"</span>])</span>
- <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>lbry_check <span class="op">=</span> json.loads(lbry_check.text)</span>
- <span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a><span class="co"># For now using odysee because yt-dlp doesn't support librarian</span></span>
- <span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>librarian_instance <span class="op">=</span> <span class="st">"https://odysee.com/"</span></span>
- <span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> lbry_check[<span class="st">"lbryurl"</span>] <span class="op">==</span> <span class="va">None</span>:</span>
- <span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> <span class="co"># Using youtube.com since yt-dlp on any given invidious url redirects to youtube.com anyways.</span></span>
- <span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a> selected_url <span class="op">=</span> <span class="st">"https://youtube.com/watch?v="</span> <span class="op">+</span> json_stuff[c][<span class="st">"videoId"</span>]</span>
- <span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a><span class="cf">else</span>:</span>
- <span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">"Playing with LBRY!"</span>)</span>
- <span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a> selected_url <span class="op">=</span> librarian_instance <span class="op">+</span> lbry_check[<span class="st">"lbryurl"</span>]</span>
- <span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a> selected_url <span class="op">=</span> selected_url.replace(<span class="st">"#"</span>, <span class="st">":"</span>)</span></code></pre></div>
- <h1 id="launch-in-mpv">Launch in MPV!</h1>
- <div class="sourceCode" id="cb9"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Do stuff with it.</span></span>
- <span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a>os.system(command <span class="op">+</span> selected_url)</span>
- <span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a>quit()</span></code></pre></div>
- <h1 id="peertube">Peertube</h1>
- <p>A lot of what I discussed in the invidious part of the script applies to the PeerTube part, there are just different values and API's that are worked with.</p>
- <div class="sourceCode" id="cb10"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a><span class="cf">elif</span> sys.argv[<span class="dv">1</span>] <span class="op">==</span> <span class="st">"-p"</span>:</span>
- <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> sys.argv[<span class="dv">2</span>]</span>
- <span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">input</span>(<span class="st">"Searching for: "</span>)</span>
- <span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">str</span>(query)</span>
- <span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> size <span class="op">=</span> <span class="bu">str</span>(<span class="dv">19</span>)</span>
- <span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> search <span class="op">=</span> <span class="st">"https://sepiasearch.org/api/v1/search/videos?search="</span> <span class="op">+</span> query</span>
- <span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> data <span class="op">=</span> requests.get(search)</span>
- <span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> json_stuff <span class="op">=</span> json.loads(data.text)</span>
- <span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, vid <span class="kw">in</span> <span class="bu">enumerate</span>(json_stuff[<span class="st">"data"</span>]):</span>
- <span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, colora<span class="op">+</span>vid[<span class="st">"name"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>colorb<span class="op">+</span>vid[<span class="st">"channel"</span>][<span class="st">"displayName"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>bright_cyan<span class="op">+</span>vid[<span class="st">"url"</span>]<span class="op">+</span>norm)</span>
- <span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb10-14"><a href="#cb10-14" aria-hidden="true" tabindex="-1"></a> <span class="co"># Choose a result</span></span>
- <span id="cb10-15"><a href="#cb10-15" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="dv">100000</span></span>
- <span id="cb10-16"><a href="#cb10-16" aria-hidden="true" tabindex="-1"></a> <span class="cf">while</span> <span class="kw">not</span> c <span class="op">>=</span> <span class="dv">0</span> <span class="kw">or</span> <span class="kw">not</span> c <span class="op"><=</span> <span class="dv">19</span>:</span>
- <span id="cb10-17"><a href="#cb10-17" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">input</span>(<span class="st">'Number from 1-'</span> <span class="op">+</span> size <span class="op">+</span> <span class="st">" of the URL you want to open: "</span>)</span>
- <span id="cb10-18"><a href="#cb10-18" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb10-19"><a href="#cb10-19" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">int</span>(c)</span>
- <span id="cb10-20"><a href="#cb10-20" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb10-21"><a href="#cb10-21" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="dv">100000</span></span>
- <span id="cb10-22"><a href="#cb10-22" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb10-23"><a href="#cb10-23" aria-hidden="true" tabindex="-1"></a> selected_url <span class="op">=</span> json_stuff[<span class="st">"data"</span>][c][<span class="st">"url"</span>]</span></code></pre></div>
- <h1 id="peertube-comments">PeerTube Comments</h1>
- <p>This is a lot of work in progress code, it's very inefficient and only acompleshes:</p>
- <ul>
- <li>Printing out comments</li>
- <li>Detect if a video has replies
- <ul>
- <li>Tell how many replies</li>
- </ul></li>
- <li>Print just <strong>1</strong> of those replies</li>
- <li>Detect if one of the json groups is a deleted comment and if so <code class="verbatim">pass</code> and don't deal with it.</li>
- </ul>
- <div class="sourceCode" id="cb11"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a>comments <span class="op">=</span> <span class="st">"https://"</span> <span class="op">+</span> json_stuff[<span class="st">"data"</span>][c][<span class="st">"account"</span>][<span class="st">"host"</span>] <span class="op">+</span> <span class="st">"/api/v1/videos/"</span> <span class="op">+</span> json_stuff[<span class="st">"data"</span>][c][<span class="st">"uuid"</span>] <span class="op">+</span> <span class="st">"/comment-threads/"</span></span>
- <span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a>data_comment <span class="op">=</span> requests.get(comments)</span>
- <span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a>json_comment <span class="op">=</span> json.loads(data_comment.text)</span>
- <span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a><span class="co"># PRINT COMMENTS!</span></span>
- <span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i, comment <span class="kw">in</span> <span class="bu">enumerate</span>(json_comment[<span class="st">"data"</span>]):</span>
- <span id="cb11-6"><a href="#cb11-6" aria-hidden="true" tabindex="-1"></a> <span class="co"># Sometimes peertube likes to give nonsese json</span></span>
- <span id="cb11-7"><a href="#cb11-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> comment[<span class="st">"account"</span>] <span class="op">==</span> <span class="va">None</span>:</span>
- <span id="cb11-8"><a href="#cb11-8" aria-hidden="true" tabindex="-1"></a> <span class="cf">pass</span></span>
- <span id="cb11-9"><a href="#cb11-9" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb11-10"><a href="#cb11-10" aria-hidden="true" tabindex="-1"></a> <span class="co"># This detects if a comment has replies.</span></span>
- <span id="cb11-11"><a href="#cb11-11" aria-hidden="true" tabindex="-1"></a> <span class="cf">elif</span> comment[<span class="st">"totalReplies"</span>] <span class="op">></span> <span class="dv">0</span>:</span>
- <span id="cb11-12"><a href="#cb11-12" aria-hidden="true" tabindex="-1"></a> replies <span class="op">=</span> comments <span class="op">+</span> <span class="bu">str</span>(comment[<span class="st">"id"</span>])</span>
- <span id="cb11-13"><a href="#cb11-13" aria-hidden="true" tabindex="-1"></a> data_replies <span class="op">=</span> requests.get(replies)</span>
- <span id="cb11-14"><a href="#cb11-14" aria-hidden="true" tabindex="-1"></a> json_replies <span class="op">=</span> json.loads(data_replies.text)</span>
- <span id="cb11-15"><a href="#cb11-15" aria-hidden="true" tabindex="-1"></a> total_replies <span class="op">=</span> <span class="bu">str</span>(json_replies[<span class="st">"comment"</span>][<span class="st">"totalReplies"</span>])</span>
- <span id="cb11-16"><a href="#cb11-16" aria-hidden="true" tabindex="-1"></a> <span class="co"># Print out that this comment has replies and also say how many</span></span>
- <span id="cb11-17"><a href="#cb11-17" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, colora<span class="op">+</span>comment[<span class="st">"account"</span>][<span class="st">"displayName"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>colorb<span class="op">+</span>comment[<span class="st">"text"</span>]<span class="op">+</span>norm<span class="op">+</span>bright_cyan<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">REPLIES: "</span><span class="op">+</span>total_replies<span class="op">+</span>norm)</span>
- <span id="cb11-18"><a href="#cb11-18" aria-hidden="true" tabindex="-1"></a> <span class="co"># Here in this for loop inside of a for loop for replys</span></span>
- <span id="cb11-19"><a href="#cb11-19" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, reply <span class="kw">in</span> <span class="bu">enumerate</span>(json_replies[<span class="st">"children"</span>]):</span>
- <span id="cb11-20"><a href="#cb11-20" aria-hidden="true" tabindex="-1"></a> <span class="co"># Same thing can happen where it gives nonsense json.</span></span>
- <span id="cb11-21"><a href="#cb11-21" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> reply[<span class="st">"comment"</span>][<span class="st">"account"</span>] <span class="op">==</span> <span class="va">None</span>:</span>
- <span id="cb11-22"><a href="#cb11-22" aria-hidden="true" tabindex="-1"></a> <span class="cf">pass</span></span>
- <span id="cb11-23"><a href="#cb11-23" aria-hidden="true" tabindex="-1"></a> <span class="co"># This prints out the first reply.</span></span>
- <span id="cb11-24"><a href="#cb11-24" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span>:</span>
- <span id="cb11-25"><a href="#cb11-25" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">" "</span> <span class="op">+</span> <span class="bu">str</span>(i) <span class="op">+</span> <span class="st">" "</span> <span class="op">+</span> colora<span class="op">+</span>reply[<span class="st">"comment"</span>][<span class="st">"account"</span>][<span class="st">"displayName"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st"> "</span><span class="op">+</span>colorb<span class="op">+</span>reply[<span class="st">"comment"</span>][<span class="st">"text"</span>]<span class="op">+</span>norm)</span>
- <span id="cb11-26"><a href="#cb11-26" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb11-27"><a href="#cb11-27" aria-hidden="true" tabindex="-1"></a> <span class="co"># This is the final thing, the comment has no replys so it just</span></span>
- <span id="cb11-28"><a href="#cb11-28" aria-hidden="true" tabindex="-1"></a> <span class="co"># prints it as a comment.</span></span>
- <span id="cb11-29"><a href="#cb11-29" aria-hidden="true" tabindex="-1"></a> <span class="cf">else</span>:</span>
- <span id="cb11-30"><a href="#cb11-30" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, colora<span class="op">+</span>comment[<span class="st">"account"</span>][<span class="st">"displayName"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>colorb<span class="op">+</span>comment[<span class="st">"text"</span>]<span class="op">+</span>norm)</span>
- <span id="cb11-31"><a href="#cb11-31" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb11-32"><a href="#cb11-32" aria-hidden="true" tabindex="-1"></a>os.system(command <span class="op">+</span> selected_url)</span></code></pre></div>
- <h1 id="lbry">LBRY</h1>
- <p>This section is for LBRY, and printing out the search results of the search.</p>
- <div class="sourceCode" id="cb12"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a><span class="cf">elif</span> sys.argv[<span class="dv">1</span>] <span class="op">==</span> <span class="st">"-l"</span>:</span>
- <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> sys.argv[<span class="dv">2</span>]</span>
- <span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">input</span>(<span class="st">"Searching for: "</span>)</span>
- <span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> query <span class="op">=</span> <span class="bu">str</span>(query)</span>
- <span id="cb12-7"><a href="#cb12-7" aria-hidden="true" tabindex="-1"></a> size <span class="op">=</span> <span class="bu">str</span>(<span class="dv">30</span>)</span>
- <span id="cb12-8"><a href="#cb12-8" aria-hidden="true" tabindex="-1"></a> search <span class="op">=</span> <span class="st">'https://lighthouse.lbry.com/search?s='</span> <span class="op">+</span> query <span class="op">+</span> <span class="st">'&include=channel,channel_claim_id,title&size='</span> <span class="op">+</span> size</span>
- <span id="cb12-9"><a href="#cb12-9" aria-hidden="true" tabindex="-1"></a> lbry <span class="op">=</span> <span class="st">"https://lbry.ix.tc/"</span></span>
- <span id="cb12-10"><a href="#cb12-10" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb12-11"><a href="#cb12-11" aria-hidden="true" tabindex="-1"></a> data <span class="op">=</span> requests.get(search)</span>
- <span id="cb12-12"><a href="#cb12-12" aria-hidden="true" tabindex="-1"></a> json_stuff <span class="op">=</span> json.loads(data.text)</span>
- <span id="cb12-13"><a href="#cb12-13" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb12-14"><a href="#cb12-14" aria-hidden="true" tabindex="-1"></a> <span class="co"># Results</span></span>
- <span id="cb12-15"><a href="#cb12-15" aria-hidden="true" tabindex="-1"></a> <span class="cf">for</span> i, x <span class="kw">in</span> <span class="bu">enumerate</span>(json_stuff):</span>
- <span id="cb12-16"><a href="#cb12-16" aria-hidden="true" tabindex="-1"></a> pre <span class="op">=</span> <span class="st">"lbry://"</span></span>
- <span id="cb12-17"><a href="#cb12-17" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> x[<span class="st">"channel"</span>]:</span>
- <span id="cb12-18"><a href="#cb12-18" aria-hidden="true" tabindex="-1"></a> pre <span class="op">+=</span> x[<span class="st">"channel"</span>] <span class="op">+</span> <span class="st">"/"</span></span>
- <span id="cb12-19"><a href="#cb12-19" aria-hidden="true" tabindex="-1"></a> url <span class="op">=</span> pre <span class="op">+</span> x[<span class="st">"name"</span>]</span>
- <span id="cb12-20"><a href="#cb12-20" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, bright_cyan<span class="op">+</span>x[<span class="st">"title"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>url)</span></code></pre></div>
- <h1 id="lbry-comments">LBRY comments</h1>
- <p>Using the librarian comment api after gathering a lot of information about the publication it is possible to get the comments.</p>
- <div class="sourceCode" id="cb13"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="co"># Choose a result</span></span>
- <span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a>c <span class="op">=</span> <span class="dv">100000</span></span>
- <span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a><span class="cf">while</span> <span class="kw">not</span> c <span class="op">>=</span> <span class="dv">0</span> <span class="kw">or</span> <span class="kw">not</span> c <span class="op"><=</span> <span class="dv">29</span>:</span>
- <span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">input</span>(<span class="st">'Number from 1-'</span> <span class="op">+</span> size <span class="op">+</span> <span class="st">" of the URL you want to open: "</span>)</span>
- <span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="cf">try</span>:</span>
- <span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="bu">int</span>(c)</span>
- <span id="cb13-7"><a href="#cb13-7" aria-hidden="true" tabindex="-1"></a> <span class="cf">except</span>:</span>
- <span id="cb13-8"><a href="#cb13-8" aria-hidden="true" tabindex="-1"></a> c <span class="op">=</span> <span class="dv">100000</span></span>
- <span id="cb13-9"><a href="#cb13-9" aria-hidden="true" tabindex="-1"></a>selected_url <span class="op">=</span> json_stuff[c]</span>
- <span id="cb13-10"><a href="#cb13-10" aria-hidden="true" tabindex="-1"></a><span class="co"># Do stuff with it.</span></span>
- <span id="cb13-11"><a href="#cb13-11" aria-hidden="true" tabindex="-1"></a>channel_name <span class="op">=</span> selected_url[<span class="st">"channel"</span>]</span>
- <span id="cb13-12"><a href="#cb13-12" aria-hidden="true" tabindex="-1"></a>channel_ID <span class="op">=</span> selected_url[<span class="st">"channel_claim_id"</span>]</span>
- <span id="cb13-13"><a href="#cb13-13" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb13-14"><a href="#cb13-14" aria-hidden="true" tabindex="-1"></a>claim_ID <span class="op">=</span> selected_url[<span class="st">"claimId"</span>]</span>
- <span id="cb13-15"><a href="#cb13-15" aria-hidden="true" tabindex="-1"></a>url <span class="op">=</span> <span class="bu">str</span>(lbry <span class="op">+</span> <span class="st">"api/comments?claim_id="</span> <span class="op">+</span> claim_ID <span class="op">+</span> <span class="st">"&channel_id="</span> <span class="op">+</span> channel_ID <span class="op">+</span> <span class="st">"&channel_name="</span> <span class="op">+</span> channel_name <span class="op">+</span> <span class="st">"&page=1&page_size=15"</span>)</span>
- <span id="cb13-16"><a href="#cb13-16" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb13-17"><a href="#cb13-17" aria-hidden="true" tabindex="-1"></a>comments <span class="op">=</span> requests.get(url)</span>
- <span id="cb13-18"><a href="#cb13-18" aria-hidden="true" tabindex="-1"></a>json_comments <span class="op">=</span> json.loads(comments.text)</span>
- <span id="cb13-19"><a href="#cb13-19" aria-hidden="true" tabindex="-1"></a><span class="cf">for</span> i, x <span class="kw">in</span> <span class="bu">enumerate</span>(json_comments[<span class="st">"comments"</span>]):</span>
- <span id="cb13-20"><a href="#cb13-20" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(i, bright_cyan<span class="op">+</span>x[<span class="st">"Channel"</span>][<span class="st">"Name"</span>]<span class="op">+</span>norm<span class="op">+</span><span class="st">"</span><span class="ch">\n</span><span class="st">"</span><span class="op">+</span>x[<span class="st">"Comment"</span>])</span>
- <span id="cb13-21"><a href="#cb13-21" aria-hidden="true" tabindex="-1"></a></span>
- <span id="cb13-22"><a href="#cb13-22" aria-hidden="true" tabindex="-1"></a>url <span class="op">=</span> <span class="st">"https://odysee.com/"</span> <span class="op">+</span> selected_url[<span class="st">"channel"</span>] <span class="op">+</span> <span class="st">"/"</span> <span class="op">+</span> selected_url[<span class="st">"name"</span>]</span>
- <span id="cb13-23"><a href="#cb13-23" aria-hidden="true" tabindex="-1"></a>os.system(command <span class="op">+</span> url)</span>
- <span id="cb13-24"><a href="#cb13-24" aria-hidden="true" tabindex="-1"></a>quit()</span></code></pre></div>
- <h1 id="help">HELP</h1>
- <p>Using the -h argument the user can get some help aobut how to use the program.</p>
- <div class="sourceCode" id="cb14"><pre class="sourceCode python"><code class="sourceCode python"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="cf">elif</span> sys.argv[<span class="dv">1</span>] <span class="op">==</span> <span class="st">"-h"</span>:</span>
- <span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">'''</span></span>
- <span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="st">Command:</span></span>
- <span id="cb14-4"><a href="#cb14-4" aria-hidden="true" tabindex="-1"></a><span class="st">python vids.py <arg></span></span>
- <span id="cb14-5"><a href="#cb14-5" aria-hidden="true" tabindex="-1"></a><span class="st">After doing this you will be prompted to make a search</span></span>
- <span id="cb14-6"><a href="#cb14-6" aria-hidden="true" tabindex="-1"></a><span class="st">If you want you can make the search in the command by doing</span></span>
- <span id="cb14-7"><a href="#cb14-7" aria-hidden="true" tabindex="-1"></a><span class="st">python vids.py <arg> "search"</span></span>
- <span id="cb14-8"><a href="#cb14-8" aria-hidden="true" tabindex="-1"></a><span class="st">-l for lighthouse (LBRY network)</span></span>
- <span id="cb14-9"><a href="#cb14-9" aria-hidden="true" tabindex="-1"></a><span class="st">-p for sepia (Peertube)</span></span>
- <span id="cb14-10"><a href="#cb14-10" aria-hidden="true" tabindex="-1"></a><span class="st">-i for invidious) (YouTube) </span></span>
- <span id="cb14-11"><a href="#cb14-11" aria-hidden="true" tabindex="-1"></a><span class="st">NOTE: All youtube links will be checked with the Watch on LBRY API. If</span></span>
- <span id="cb14-12"><a href="#cb14-12" aria-hidden="true" tabindex="-1"></a><span class="st">the video is available on the lbry network, the youtube search result</span></span>
- <span id="cb14-13"><a href="#cb14-13" aria-hidden="true" tabindex="-1"></a><span class="st">will be opened in a odysee.com link.</span></span>
- <span id="cb14-14"><a href="#cb14-14" aria-hidden="true" tabindex="-1"></a><span class="st">'''</span>)</span>
- <span id="cb14-15"><a href="#cb14-15" aria-hidden="true" tabindex="-1"></a><span class="cf">except</span>:</span>
- <span id="cb14-16"><a href="#cb14-16" aria-hidden="true" tabindex="-1"></a> <span class="bu">print</span>(<span class="st">''</span>)</span></code></pre></div>
- <hr>
- <footer>
- <a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'><img alt='Creative Commons License' style='border-width:0' width='88' height='31' src='../images/cc-by-sa.png' /></a><br>
- Unless otherwise noted, all content on this website is Copyright Zortazert 2021-2022 and is licensed under <a rel='license' href='http://creativecommons.org/licenses/by-sa/4.0/'>CC BY-SA 4.0</a>.
- </footer>
- </body>
- </html>
|