<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://www.nuxified.org" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>Nuxified GNU/Linux Help Forums - tips - Comments</title>
 <link>http://www.nuxified.org/blogs/tips</link>
 <description>Comments for &quot;tips&quot;</description>
 <language>en</language>
<item>
 <title>&gt;&gt; tbuitenh: download one</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11993</link>
 <description> &lt;p&gt;&amp;gt;&amp;gt; tbuitenh: download one script to download another script... d&#039;oh&lt;br /&gt;
&amp;gt;&amp;gt; libervisco: lol&lt;/p&gt;
&lt;p&gt;Yes, it is funny, but the logic I saw was that the first script could be throw away while the second one would reside in a permanent place.&lt;/p&gt;
&lt;p&gt;Some people might really find it useful to use the installer for the real script. The best part for me was just reading through the code (and understanding it) even though nothing too special was done. I don&#039;t want to use it to install youtube-dl though since I will be experimenting with youtube-dl in its own directory (and not as root).&lt;/p&gt;
&lt;p&gt;As for the installer being GPL, whoever is serious about growing that file may want to check out other installers to gain as much experience as possible. Educational purposes is one thing; otherwise, we should try and reuse others&#039; work whenever possible (even if indirectly by studying how others have solved the problem or to learn what are the difficulties not yet solved).&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 21:45:41 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11993 at http://www.nuxified.org</guid>
</item>
<item>
 <title>Fair enough. 
I actually</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11992</link>
 <description> &lt;p&gt;Fair enough. &lt;img src=&quot;/misc/smileys/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I actually updated the script to download to /tmp first. But I also added a recommendation for &lt;a href=&quot;http://keepvid.com/&quot;&gt;KeepVid.com&lt;/a&gt; which is probably the best way to download FLV videos (like on YouTube) anyway. &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 21:34:20 +0100</pubDate>
 <dc:creator>libervisco</dc:creator>
 <guid isPermaLink="false">comment 11992 at http://www.nuxified.org</guid>
</item>
<item>
 <title>I got carried away. The</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11991</link>
 <description> &lt;p&gt;I got carried away. The problem was that I could not understand why a simpler variation of the 4 line &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term460&quot;&gt;&lt;acronym title=&quot;BASH: Bourne Again SHell (common CLI and scripting language on GNU/Linux)&quot;&gt;bash&lt;/acronym&gt;&lt;/a&gt; script was not working for me. That 4line script itself seems not to have worked for someone else. I thought there might be a simple reason why, but no one has volunteered anything in these last couple of days since I first posted. For that reason, I thought of taking the large python program apart since presumably that one works (I haven&#039;t tried it since the main point was for educational purposes as you stated). In the meantime, I&#039;d hope that someone would point out what was wrong or at least say that everything worked for them (the 4 liner, the 1 liner, or the much larger youtube-dl).&lt;/p&gt;
&lt;p&gt;Both the analysis of youtube-dl and the regular expression mini tutorial are a topic unto themselves. I agree.&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 21:33:03 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11991 at http://www.nuxified.org</guid>
</item>
<item>
 <title>copied from</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11990</link>
 <description> &lt;p&gt;copied from IRC...&lt;/p&gt;
&lt;p&gt;(08:55:55 PM) ***tbuitenh just had a look at libervisco&#039;s youtube install script&lt;br /&gt;
(08:56:56 PM) tbuitenh: I&#039;m sorry to say it is both useless and problematic&lt;br /&gt;
(08:58:00 PM) tbuitenh: you shouldn&#039;t download programs directly to the system directory you want to install them in&lt;br /&gt;
(08:58:40 PM) tbuitenh: if the download fails, you&#039;ll have junk in a place the user doesn&#039;t expect&lt;br /&gt;
(08:58:58 PM) tbuitenh: also, you&#039;re not actually saving much work&lt;br /&gt;
(08:59:16 PM) tbuitenh: in other words... WHAT WERE YOU THINKING? &lt;img src=&quot;/misc/smileys/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; /&gt;&lt;br /&gt;
(08:59:55 PM) libervisco: &lt;img src=&quot;/misc/smileys/lol.png&quot; title=&quot;Laughing out loud&quot; alt=&quot;Laughing out loud&quot; /&gt;&lt;br /&gt;
(09:00:44 PM) libervisco: convenience mostly I suppose&lt;br /&gt;
(09:01:14 PM) libervisco: I guess I could&#039;ve made it download in home directory somewhere and then linked it to /usr/bin..&lt;br /&gt;
(09:01:43 PM) tbuitenh: no, not linked, and definitely not to /usr/bin&lt;br /&gt;
(09:02:10 PM) tbuitenh: download it to /root, and if the download is successful, then mv it to /usr/local/bin&lt;br /&gt;
(09:02:22 PM) tbuitenh: or maybe cp&lt;br /&gt;
(09:02:32 PM) tbuitenh: then chmod 755 it&lt;br /&gt;
(09:03:07 PM) libervisco: isn&#039;t the result the same?&lt;br /&gt;
(09:03:10 PM) tbuitenh: and tell the user it was installed there in /usr/local/bin&lt;br /&gt;
(09:03:12 PM) libervisco: Who ever looks at /root? &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;br /&gt;
(09:03:21 PM) libervisco: oh&lt;br /&gt;
(09:03:27 PM) libervisco: well that&#039;d help ok..&lt;br /&gt;
(09:03:36 PM) tbuitenh:  /root is the home directory of root&lt;br /&gt;
(09:03:44 PM) libervisco: yeah..&lt;br /&gt;
(09:03:56 PM) tbuitenh: you will see it there if you&#039;re root&lt;br /&gt;
(09:04:00 PM) libervisco: but nobody is logged in as root to be there by default and this was obviously for noobs..&lt;br /&gt;
(09:04:08 PM) tbuitenh: true&lt;br /&gt;
(09:04:32 PM) tbuitenh: then use /tmp, so it will be gone after the next reboot if the download failed&lt;br /&gt;
(09:04:47 PM) libervisco: right&lt;br /&gt;
(09:04:51 PM) tbuitenh: still, the script is useless &lt;img src=&quot;/misc/smileys/tongue.png&quot; title=&quot;Sticking out tongue&quot; alt=&quot;Sticking out tongue&quot; /&gt;&lt;br /&gt;
(09:05:42 PM) tbuitenh: download one script to download another script... d&#039;oh&lt;br /&gt;
(09:05:58 PM) libervisco: lol&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 21:06:39 +0100</pubDate>
 <dc:creator>tbuitenh</dc:creator>
 <guid isPermaLink="false">comment 11990 at http://www.nuxified.org</guid>
</item>
<item>
 <title>It&#039;s nice you&#039;re analyzing</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11989</link>
 <description> &lt;p&gt;It&#039;s nice you&#039;re analyzing all this for educative purposes, but maybe you should make a separate thread...&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 20:41:53 +0100</pubDate>
 <dc:creator>tbuitenh</dc:creator>
 <guid isPermaLink="false">comment 11989 at http://www.nuxified.org</guid>
</item>
<item>
 <title>Regular expression tutorial.. for .. uh.... fun?</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11987</link>
 <description> &lt;p&gt;In the discussion so far an ugly looking piece of text showed up:&lt;/p&gt;
&lt;p&gt;^((?:http://)?(?:\w+\.)?youtube\.com/(?:v/|(?:watch(?:\.php)?)?\?(?:.+&amp;amp;)?v=))?([0-9A-Za-z_-]+)(?(1)[&amp;amp;/].*)?$&lt;/p&gt;
&lt;p&gt;This gibberish is a regular expression. Though it&#039;s not important to know regular expression notation to basically follow along the youtube-dl python script discussion, regular expressions (re&#039;s for short) are very useful so we might as well take a detour to look them over [follow along if you are curious]. &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term415&quot;&gt;&lt;acronym title=&quot;BTW: By the way&quot;&gt;BTW&lt;/acronym&gt;&lt;/a&gt;, regular expressions don&#039;t have to look ugly. For example,&lt;/p&gt;
&lt;p&gt;a&lt;/p&gt;
&lt;p&gt;is a regular expression. It can be used to match/find an &quot;a&quot; within a sample of text.&lt;/p&gt;
&lt;p&gt;Another example is&lt;/p&gt;
&lt;p&gt;dog&lt;/p&gt;
&lt;p&gt;which matches &quot;dog&quot; within the sample of text being tested.&lt;/p&gt;
&lt;p&gt;RE&#039;s are potentially huge time savers for doing many types of text processing. Perl got its reputation as the language for text manipulation because of its great support for regular expressions and integration into the perl language itself. The web protocols are based on English looking text and so perl made a name for itself early on as being the web language. Today, lots of programming languages have access to great RE capabilities through bindings to some of the same libraries that perl uses. One great thing about RE&#039;s is that they frequently enable you to do many types of searches with almost no knowledge of any syntax of the underlying language/tool since most of the work is done through re&#039;s and not through language &quot;loop&quot; expressions/statements. Of course, what was done in the past through re&#039;s (eg, lots of backend web processing) now is hidden behind function calls that do all that work and then some. This is so because the web is a platform that hasn&#039;t changed much in years. In many respects, that &quot;problem&quot; has been solved. The wheel was made and homed, and now we just use the results of that work without having to dip into RE&#039;s. But for custom or new applications, RE&#039;s continue to be as useful as ever. In fact, the better &quot;Find&quot; tools you see on the web or on the desktop allow you to do more advanced searches by accepting regular expression notation.&lt;/p&gt;
&lt;p&gt;The idea for taking advantage of re&#039;s is to pair up a regular expression (the template) with some text and see if there is a match (and if so where and what). Regular expressions look just like text (so be careful you don&#039;t loose track of which is the template and which is the text). What makes it a regular expression is you. You basically say, this will be a template. Voila! Of course, you have to let the computer know your intentions, so you would use it in the proper function calls. Generally, each re symbol matches a character/byte of text that &quot;looks&quot; just like it, but there are some symbols that have special meaning.&lt;/p&gt;
&lt;p&gt;Warm-up pre-exercises [informal notation]:&lt;br /&gt;
&amp;gt; dog|cat matches &quot;dog&quot; as well as &quot;fsfsfddogdfsdfsdf&quot; as well as &quot;dsdsdsdsdcatfsdfdf&quot;. Did you notice the dog and cat hidden in the middle?&lt;br /&gt;
&amp;gt; (dog)+(cat)* matches &quot;dog&quot; &quot;dogdog&quot; &quot;dogcat&quot; &quot;dogdogcat&quot; &quot;dogdogcatcatcatcat&quot; &quot;dogcatcatcatcatcatcatcatcatcatcat&quot; &quot;dogdogdogdogdogdogdogcatcatcat&quot; and many more things like &quot;asdfasdfasdfdogdogdogdogdogcatcatcatdfsafsdfasdfsdf&quot; and more.&lt;br /&gt;
&amp;gt; dog+cat* matches &quot;dogggggcattttt&quot; &quot;dogca&quot; and many more things.&lt;/p&gt;
&lt;p&gt;OK, when dealing with regular expressions, we have to be careful with quotation marks and in general marks of any kind. I&#039;ll try to be consistent and use quotations around text and text matches while using no quotations when referring to the re itself. The examples won&#039;t be that advanced. At the end though, we&#039;ll go over the &quot;monster&quot; re that led to this diversion, ie,&lt;/p&gt;
&lt;p&gt;^((?:http://)?(?:\w+\.)?youtube\.com/(?:v/|(?:watch(?:\.php)?)?\?(?:.+&amp;amp;)?v=))?([0-9A-Za-z_-]+)(?(1)[&amp;amp;/].*)?$&lt;/p&gt;
&lt;p&gt;Let&#039;s start by covering the symbols/characters/bytes/etc that have special meaning when used inside a regular expression.&lt;/p&gt;
&lt;p&gt;Note the &quot;^&quot; at the beginning and the &quot;$&quot; at the end of the monster RE above. These have special meaning. These are said to &quot;anchor&quot; the expression to the beginning of the test text (^) and to the end ($). These are optional like any other symbol. You generally avoid these if you want to find a pattern anywhere. You use them if you want to confine the pattern or be extra restrictive.&lt;/p&gt;
&lt;p&gt;Let&#039;s see what some of the other special characters are. Note that preceding any of these characters with a &quot;\&quot; (that basically isn&#039;t itself preceded by a &quot;\&quot;) allows them to match themselves. One thing you will notice is that these special symbols carry implicit conditional logic. Through this they allow compact templates to be created, even allowing you to express infinities within the matching, allowing you to express compactly what would otherwise involve potentially lots of programming constructs.&lt;/p&gt;
&lt;p&gt;Alright...&lt;/p&gt;
&lt;p&gt;\ this is used to escape symbols. Most of the symbols that follow have special meaning unless escaped. When escaped, they represent their ordinary looking selves. Also, some ordinary characters (eg, &quot;n&quot;) when escaped become special (eg, &quot;\n&quot; represents end of line, ie, byte x0A).&lt;/p&gt;
&lt;p&gt;^ is used to match the beginning of the text being tested. Or rather, for there to be a match, this symbol has to match up with the beginning of the text being tested. If this can&#039;t be done, then there is no match, ie, the re template does not match the text being tested.&lt;/p&gt;
&lt;p&gt;$ is used to match the end of the stream of text being tested.&lt;/p&gt;
&lt;p&gt;() this is for grouping. It allows for tremendous simplification of notation since it has the highest order of precedence. I&#039;ll clarify later through contrasting examples.&lt;/p&gt;
&lt;p&gt;(?: ) this is identical to () as far as testing for a match. The difference is in whether or not we can find out immediately what matched (and not just that there was a match). Why the distinction? Because it&#039;s more efficient if you can forget what matched but simply know that something did. For some heavy duty applications, you want speed and to know yea/nay. Afterwards, there is time to go back and get the actual text that you know exists near a particular area. In other uses, however, going back repeatedly can result in a huge processing time sink and require extra coding (and time coding). It&#039;s an engineering call to be made depending on the problem being solved and the characteristics of the stream. Anyway, (xxx) gives you an immediate link to the actual matched text (if any) and (?:xxx) does not. (?:xxx) is used only for grouping (no capture).&lt;/p&gt;
&lt;p&gt;? means that what precedes it is optional (in other words, what precedes it appears exactly one time or zero time for there to be a match).&lt;/p&gt;
&lt;p&gt;* means that what precedes it can appear zero or any number of times.&lt;/p&gt;
&lt;p&gt;+ means that what precedes it can appear once or more only. Ie, what precedes it must appear at least once for there to be a match.&lt;/p&gt;
&lt;p&gt;[] is used to enclose a group of characters, any single one of which can/must be matched at that location.&lt;/p&gt;
&lt;p&gt;[^] is used to enclose a group of characters that cannot be matched. This also only represents a single item.&lt;/p&gt;
&lt;p&gt;[f-t] this is a specific example and it means that any letter between &quot;f&quot; and &quot;t&quot; inclusive can be matched. It&#039;s a short-hand for writing out all the letters in this range.&lt;/p&gt;
&lt;p&gt;[-ft] in this case we can match either of &quot;-&quot; &quot;f&quot; or &quot;t&quot; In fact, if you want to include &quot;-&quot; it has to be in the initial or final position; otherwise it will designate a range.&lt;/p&gt;
&lt;p&gt;[a^] means either &quot;a&quot; or &quot;^&quot; only is to be matched.&lt;/p&gt;
&lt;p&gt;[^a] means any byte at all except &quot;a&quot;. Thus at the beginning of a [], ^ means exclusion.&lt;/p&gt;
&lt;p&gt;| matches either what precedes it or what follows it. It has a low order of precedence relative to everything else. [I&#039;ll give examples of order of precedence scenarios below.] Eg, av|bv means match &quot;av&quot; or match &quot;bv&quot;.&lt;/p&gt;
&lt;p&gt;. is used to match any single character. Eg, a.b matches &quot;azb&quot; and &quot;a.b&quot; and &quot;a#b&quot;.&lt;/p&gt;
&lt;p&gt;Almost anything else matches only itself and exactly once. [Remember, the above match themselves only when preceded by a \]&lt;/p&gt;
&lt;p&gt;Also, there are a few otherwise ordinary characters that when preceded by a \ acquire special meaning (so they sort of work the opposite as these prior examples). For example, \w matches any letter or number or &quot;_&quot;. Thus \w+ would match a word of such text.&lt;/p&gt;
&lt;p&gt;[Keep in mind I am not looking at the python descriptions of these so there may be some subtle differences from what I say.]&lt;/p&gt;
&lt;p&gt;OK, now for some simple examples to help clarify a bit more.&lt;/p&gt;
&lt;p&gt;I&#039;ll list the re on one line and then below it I&#039;ll give examples (one per line) of sample text that would match. Then below that, I&#039;ll list sample text that would not match. I&#039;ll use ***** to separate the two groups of examples from each other and from the RE.&lt;/p&gt;
&lt;p&gt;Keep this in mind. The lines in the first group all match but the actual matched text is a subtext of the whole line. If you want to know exactly what part matches and what part doesn&#039;t, use the tool provided &lt;a href=&quot;http://www.regular-expressions.info/javascriptexample.html&quot;&gt;http://www.regular-expressions.info/javascriptexample.html&lt;/a&gt; . The &quot;Replace&quot; button will indirectly show all the parts that match by putting in the word &quot;replaced&quot; in place of what was matched. The portions that are not matched are kept in place. Still, the line itself would be a match if any portion of the line matched. No match means there was no match anywhere within the line.&lt;/p&gt;
&lt;p&gt;[You can practice whenever by going to that link &lt;a href=&quot;http://www.regular-expressions.info/javascriptexample.html&quot;&gt;http://www.regular-expressions.info/javascriptexample.html&lt;/a&gt; . The re syntax there is whatever the javascript running on your browser understands (so javascript must be enabled). This is basically what I am describing in this posting, and it should be basically what python uses.]&lt;/p&gt;
&lt;p&gt;As an excercise make sure you believe that all examples in the first groups match and none of those in the second groups match. I may make a mistake, so ask if in doubt. In fact, I won&#039;t generally test these myself with the website tool to increase the chances of making a mistake. For practice, try testing these examples yourself in the link mentioned in the prior paragraph. Put the re into the top slot, then put the text string to test into the next slot, then hit &quot;Test Match&quot;. If the javascript finds a match but you don&#039;t believe it, try hitting the bottom button &quot;Replace&quot; as it will show you where the match(es) occured. If you still don&#039;t believe it, post the example here. I discovered a bug in the re matching in mozilla some years ago [it may still be there]. ..and yes, I do make mistakes.&lt;/p&gt;
&lt;p&gt;I know the examples can get tedious, but testing some of these with the linked tool as you find time will help out. You&#039;ll see better examples and the payoff further down after this section.&lt;/p&gt;
&lt;p&gt;Here is a single isolated example to make the other examples clearer:&lt;br /&gt;
a&lt;br /&gt;
*****&lt;br /&gt;
a&lt;br /&gt;
*****&lt;br /&gt;
b&lt;br /&gt;
c&lt;/p&gt;
&lt;p&gt;This means that the RE is a. There is one example provided of a line that matches (&quot;a&quot;). And there are two examples provided of lines each that fail to match (&quot;b&quot; is one line and &quot;c&quot; is the other line).&lt;/p&gt;
&lt;p&gt;^ab&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
ab&lt;br /&gt;
*****&lt;br /&gt;
a&lt;br /&gt;
b&lt;br /&gt;
ba&lt;br /&gt;
aab&lt;br /&gt;
c&lt;br /&gt;
54645ygfs54ytfdgsdrytg  afsret43t  asdfv 4 hello everyone i don&#039;t match it&lt;br /&gt;
^ab&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^(ab)&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
ab&lt;br /&gt;
*****&lt;br /&gt;
(ab)&lt;br /&gt;
(bas)&lt;br /&gt;
ab)&lt;br /&gt;
^(ab)&amp;amp;&lt;br /&gt;
(((sdfsfasdf)f((9(dsf]]]]]]]]][dkfksdlpfkas;ldkf;lsdf these dont match because the text line MUST begin with a and end with b immediately.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
(ab)&lt;br /&gt;
*****&lt;br /&gt;
ab&lt;br /&gt;
(ab)&lt;br /&gt;
(ab&lt;br /&gt;
^(ab)&amp;amp;&lt;br /&gt;
ab)sfasdf these are all ok since the ab can match anywhere.&lt;br /&gt;
*****&lt;br /&gt;
(a b) this has a space&lt;br /&gt;
(bas)&lt;br /&gt;
(((sdfsfasdf)f((9(dsf]]]]]]]]][dkfksdlpfkas;ldkf;lsdf these dont match because they don&#039;t have a followed immediately by b.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^(?:ab)&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
ab&lt;br /&gt;
*****&lt;br /&gt;
^(?:ab)&amp;amp;&lt;br /&gt;
previous line and this one don&#039;t match. for example, previous line starts with &quot;^&quot; not &quot;a&quot; as it should.&lt;br /&gt;
alksdjkflkasjd klfjasklfj klsdjfklsdjfk hope you get the idea. basically only &quot;ab&quot; matches &quot;ab&quot; or &quot;(ab)&quot; or &quot;(?:ab)&quot;&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^(a|b)&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
a&lt;br /&gt;
b&lt;br /&gt;
*****&lt;br /&gt;
ab&lt;br /&gt;
ba&lt;br /&gt;
basdfsdfasfdsadf&lt;br /&gt;
aa&lt;br /&gt;
(a|b) .. in other words, either &quot;a&quot; or &quot;b&quot; but nothing else will match including this long line.. duh.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^\(a|b\)&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
(a&lt;br /&gt;
b)&lt;br /&gt;
*****&lt;br /&gt;
no other lines besides these prior 2 will match. note how | is low order of precedence so ^ \( and a are one item as is b \) and &amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
\&amp;amp;&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
&amp;amp;&lt;br /&gt;
afsfasdfasdf   &amp;amp;sf sadfasdf &amp;amp;&amp;amp;&amp;amp;&amp;amp; fasdf &amp;amp;&amp;amp;&amp;amp;&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
the above match because they end in &quot;&amp;amp;&quot;&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
&amp;amp;\&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
nothing can match &amp;amp;\&amp;amp; since it would have to end and then be followed by a &quot;&amp;amp;&quot; which is impossible if the text stream ended.&lt;br /&gt;
note that the first grouping has no lines in it. that isn&#039;t a double ***** used to separate examples.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^\((a|b)\)&amp;amp;&lt;br /&gt;
*****&lt;br /&gt;
(a)&lt;br /&gt;
(b)&lt;br /&gt;
*****&lt;br /&gt;
nothing else will match not even&lt;br /&gt;
^\((a|b)\)&amp;amp;&lt;br /&gt;
and certainly not&lt;br /&gt;
(ab)&lt;br /&gt;
a&lt;br /&gt;
b&lt;br /&gt;
(a&lt;br /&gt;
etc&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
(a|b)&lt;br /&gt;
*****&lt;br /&gt;
sdfsdf  i match believe it or not (the reason is that if a single a or a single b appears anywhere then we match at the 1st such location).&lt;br /&gt;
note that I too match. the difference with the above cases is that we didn&#039;t anchor the text to the beginning and end.&lt;br /&gt;
*****&lt;br /&gt;
I don&#039;t mtch, sorry.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^a|^b&lt;br /&gt;
*****&lt;br /&gt;
a i match because I start with a or with b (with a actually) note that ^a|^b is the same as ^(a|b) as far as matching goes&lt;br /&gt;
*****&lt;br /&gt;
sorry, I could have a&#039;s and b&#039;s like crazy but I do not match&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
^a|b&lt;br /&gt;
*****&lt;br /&gt;
a i match because I start with a or have a b anywhere(with a actually)&lt;br /&gt;
*****&lt;br /&gt;
don&#039;t start with a or have lc B somewhere&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a|b$&lt;br /&gt;
*****&lt;br /&gt;
zsdfsjdfsdfdb&lt;br /&gt;
zsdfsjdfsdfda&lt;br /&gt;
zadfsjdfsdfdc&lt;br /&gt;
*****&lt;br /&gt;
zsdfsjdfsdfdc&lt;br /&gt;
these lines don&#039;t hAve An A lc Anywhere or end in b.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a$|b&lt;br /&gt;
*****&lt;br /&gt;
we match just by having a single b anywhere&lt;br /&gt;
or alternatively, without any, we can end in an a&lt;br /&gt;
*****&lt;br /&gt;
anything that doesn&#039;t have a lower case B or end in an a won&#039;t match.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
ab(cd$|ef)gh|ij&lt;br /&gt;
*****&lt;br /&gt;
wow, here we match if we have an ij anywhere (so we match).&lt;br /&gt;
we also match if we have anywhere the following &quot;abefgh&quot;. note that we have to have all of these letters exactly&lt;br /&gt;
*****&lt;br /&gt;
I don&#039;t match because i don&#039;t have Ij lowercase nor do i have aBefgh lower case.&lt;br /&gt;
I don&#039;t match abcd&lt;br /&gt;
i don&#039;t match abcdgh&lt;br /&gt;
the reason the above 2 don&#039;t match is that you can&#039;t meet the requirement of *ending* in a &quot;cd&quot; yet be followed by a &quot;gh&quot;. it&#039;s impossible.&lt;br /&gt;
that was a bit tricky, i know. i even had to test it out because i wasn&#039;t sure if the re was really legal, [editor: i added a similar example above when proofing this reply]&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a*b*&lt;br /&gt;
*****&lt;/p&gt;
&lt;p&gt;the prior empty line matches as does this one. this one matches first at the very beginning WHAT? the match is &quot;&quot;&lt;br /&gt;
b i match too. i match first at the beginning. the match is &quot;b&quot;&lt;br /&gt;
since &quot;&quot; is possible, any line matches.&lt;br /&gt;
Also the algorithm/rules that are used will likely match once after every single character except&lt;br /&gt;
if there is a run of a&#039;s or a&#039;s and b&#039;s, in which case, there will be a single match for that entire run&lt;br /&gt;
go to the testing page link and try out the following&lt;br /&gt;
zaazaaaaabbzbbbbbbbzbababaz&lt;br /&gt;
try the &quot;Replace&quot; button to see exactly what gets replaced. Go ahead, try it.&lt;br /&gt;
OK, i&#039;ll tell you. there is a match before the first z (match is &quot;&quot;), again before the next z (this match includes &quot;aa&quot; as a single match), and then again (match is &quot;&quot; right before z), again before the next z (the match is aaaaabb), then right after (match is &quot;&quot;), again before the next z (match is bbbbbbb), then again (&quot;&quot;), again before the next a (match is b), and before the next a (match is ab), and before the next and final a (match is ab), and before the ending z (match is a), and again (match is &quot;&quot;), and then once more after the ending z (match is &quot;&quot;).&lt;br /&gt;
This is a crazy case. Usually, you want to avoid degenerate cases where you match &quot;&quot; because that seems rather useless in *almost* every scenario. So be careful.&lt;br /&gt;
Anyway, any line will necessarily match so I am going to have an empty second group and go on the the next example.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a?bc?de|fg&lt;br /&gt;
*****&lt;br /&gt;
 this line matches because it has de.&lt;br /&gt;
this line matches because it has fg.&lt;br /&gt;
this line has ade.&lt;br /&gt;
this line has bcde&lt;br /&gt;
this line has abcde&lt;br /&gt;
this line has abcde as well as fg (abcde is the first match).&lt;br /&gt;
ditto here abcdefg.&lt;br /&gt;
and here fgabcde&lt;br /&gt;
*****&lt;br /&gt;
this line does not match despite having a bde. the reason is that concatenation (ie, two symbols next to each other)&lt;br /&gt;
function as one unit when placed next to an &quot;?&quot; since ? has a lower order of operation. see the next example.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a?b(c?de)|fg&lt;br /&gt;
*****&lt;br /&gt;
bde matches in this case. here the b is not optional at all (unless i have fg).&lt;br /&gt;
i can have bde, bcde, abde, abcde, or fg .. and these need not be isolated, eg, zbdet matches at the b. and bdebde matches in two places.&lt;br /&gt;
*****&lt;br /&gt;
don&#039;t match&lt;/p&gt;
&lt;p&gt;naturally, the previous blank line doesn&#039;t match either.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a?b(c?d)e|fg&lt;br /&gt;
*****&lt;br /&gt;
as far as matching goes, this regular expression is identical with the prior one (eg, bde and the rest match)&lt;br /&gt;
*****&lt;br /&gt;
the only difference, the () placement, in this specific case, doesn&#039;t affect the possible matches but it does something i&#039;ll cover later.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a?b(c?de|)fg&lt;br /&gt;
*****&lt;br /&gt;
the | inside () has lowest order of precedence so everything to the left &quot;or&quot; everything to the right (within the ()) can match. bfg&lt;br /&gt;
*****&lt;br /&gt;
we can have &quot;&quot; match up inside (). that&#039;s how we ended up with Bfg.&lt;br /&gt;
note that all matches will necessarily include a b and end in fg. i don&#039;t mean fg is at end of line, but fg will&lt;br /&gt;
be the ending part of any match.&lt;br /&gt;
bdefG bcdefG w or w/o initial a would all match if these were in lower case.&lt;br /&gt;
also matching if in lc would be abfg.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a?b(c?de|f)g&lt;br /&gt;
*****&lt;br /&gt;
here we have a optional a followed by b followed by either cde, de, or f, followed by g as the possibilities, eg, abcdeg&lt;br /&gt;
*****&lt;br /&gt;
is this making sense?&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
a\?b(c?de|f)g&lt;br /&gt;
*****&lt;br /&gt;
the only difference here is that a is now mandatory as is a &quot;?&quot; that would follow it immediately in all cases, eg, a?bfg matches&lt;br /&gt;
*****&lt;br /&gt;
lot&#039;s of things don&#039;t match including abfg and ?bfg and a?bc?deg. however, a?bCdeg would match if all lc. as would a?Bdeg&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
[ab]cd[ef]gh&lt;br /&gt;
*****&lt;br /&gt;
matches acdfgh acdegh bcdegh bcdfgh&lt;br /&gt;
*****&lt;br /&gt;
but not abcdefgh nor abcdegh nor cdgh nor acdgh nor many other things.&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
[ab]*cd[ef]gh&lt;br /&gt;
*****&lt;br /&gt;
matches cdegh and other stuff&lt;br /&gt;
*****&lt;br /&gt;
fails to match @&lt;br /&gt;
*****&lt;br /&gt;
*****&lt;br /&gt;
~!@#\$%\^&amp;amp;*()_+|=&lt;br /&gt;
*****&lt;br /&gt;
~!@#$%^_!!!!!!&lt;br /&gt;
1=2&lt;br /&gt;
*****&lt;br /&gt;
i don&#039;t match; above note the escaped $ and ^. that was necessary or there would be no matching possible. Also the &amp;amp; was not necessary because of the * after it. Also, the () are invisible (the group nothing &quot;&quot;) and the _ could have appeared more than once.&lt;br /&gt;
The !!! at the end are irrelevant since the important part appears somewhere.&lt;br /&gt;
finally, the | at the end means that you can also match with a line having =.&lt;br /&gt;
*****&lt;/p&gt;
&lt;p&gt;OK, well I got sort of tired of doing this. Let&#039;s move on.&lt;/p&gt;
&lt;p&gt;The parentheses are used to group and as well to capture the text within them that matched. This works for () but it specifically does not work for (?: ) which is otherwise identical.&lt;/p&gt;
&lt;p&gt;Thus (a|b) matches a and it matches b. Ditto for (?:a|b). However, in the first case, I can query to find out if the match was a or b. This is very powerful. It saves many lines of coding. [I won&#039;t give python code examples, sorry]&lt;/p&gt;
&lt;p&gt;Speaking about grabbing matched text, the * and + work as follows. These match the longest match possible. Sometimes you want the shortest match possible, for those cases use *? and +?. [examples will follow to help clarify]&lt;/p&gt;
&lt;p&gt;You should also know that there is a shorthand for matching a specific number of occurances (or any range) without having to list out the pattern that many times. You can follow the portion you want repeated by {m, n} (instead of * or + or ?). This means at least m but no more than n. Also {m} for exactly m times and {m,} for m or more times. Also {m,n}? {m}? {m,}? also exists. Also ?? exists.&lt;/p&gt;
&lt;p&gt;OK, now for examples to make some sense of this.&lt;/p&gt;
&lt;p&gt;&quot;aaaa&quot; is text matched by all of the following re&#039;s (the comma is used for separation purposes to keep the discussion compact but is not a part of any re): a, aa, aaa, aaaa, a+,a+?, a{1}, a{1}?, a{2,}, a{2,}?, a{2,3}, a{2,3}?, aa?, aa??, aa*, aa*?, and numerous other things. Let&#039;s see what these match and where if allowed to repeat (always throwing away what has matched so far). [I&#039;ll use &quot;:&quot; as separator to keep discussion compact]&lt;/p&gt;
&lt;p&gt;a: matches first &quot;a&quot;; will also match each of the next a&#039;s when the match is repeated from where left off. [as many as 4 matches]&lt;br /&gt;
aa: matches first &quot;aa&quot; pair and can also match the final pair. [as many as 2 matches]&lt;br /&gt;
aaa: will match only once starting with the first &quot;a&quot; (so &quot;aaa&quot; is matched but not the final &quot;a&quot;). After the initial match and consumption, you will get that no more matches are possible.&lt;br /&gt;
aaaa: matches once as expected&lt;br /&gt;
a+: will match only once just like aaaa.&lt;br /&gt;
a+?: will match four times just like a&lt;br /&gt;
a{1}: will match just like a&lt;br /&gt;
a{1}?: will match just like a&lt;br /&gt;
a{2,}: will match 1 times just like aaaa did.&lt;br /&gt;
a{2,}?: will match 2 times just like aa did&lt;br /&gt;
a{2,3}: will match 1 time just like aaa did&lt;br /&gt;
a{2,3}?: will match 2 times just like aa did&lt;br /&gt;
aa?: will match just like aa&lt;br /&gt;
aa??: will match just like a. Note that we are saying (a)(a??) but NOT ((aa)??). The latter can match &quot;&quot; but the former doesn&#039;t.&lt;br /&gt;
aa*: will match just like aaaa&lt;br /&gt;
aa*?: will match just like a&lt;/p&gt;
&lt;p&gt;Note that when I say &quot;will match just like&quot; I don&#039;t necessarily mean in all cases. For example consider &quot;aaa&quot;. Here aa* will match like aaa but not like aaaa (as stated in this previous example).&lt;/p&gt;
&lt;p&gt;Consider &quot;aabbbaabbaab&quot;. It is matched by aab{1,} (it matches the whole thing once) aab{1,}? (it matches &quot;aab&quot; then &quot;aab&quot; then final &quot;aab&quot;) aab (matches &quot;aab&quot; then &quot;aab&quot; then final &quot;aab&quot;) aab{2,3} (matches &quot;aabbb&quot; then &quot;aabb&quot; and no more) etc. Try these out on the javascript re test page in the link above.&lt;/p&gt;
&lt;p&gt;Also know that the non ascii symbols can be matched. Yes they can! Some shorthands exist in some cases (eg, \t matches a tab character), but you can always rely on octal (\777) or hexadeciaml notation (\xFF). Eg, in perl/javascript and maybe python, you can use \x47 to match &quot;F&quot;. You can match any byte even the ones that show up as invisible or with funky symbols on a simple text editor or terminal. Thus we can process binary files as well as text files (there are some differences in approach between general binary and text processing should you want to get fancy and/or efficient).&lt;/p&gt;
&lt;p&gt;There are more rules. I covered quite a bit though.&lt;/p&gt;
&lt;p&gt;Now lets look at bit at the &quot;monster&quot; that started all of this.&lt;/p&gt;
&lt;p&gt;^((?:http://)?(?:\w+\.)?youtube\.com/(?:v/|(?:watch(?:\.php)?)?\?(?:.+&amp;amp;)?v=))?([0-9A-Za-z_-]+)(?(1)[&amp;amp;/].*)?$&lt;/p&gt;
&lt;p&gt;Here is a brief interpretation of this [ingoring the (?(1)[&amp;amp;/].*)? at the end because I don&#039;t think I know that rule -- not to imply that it would be difficult to google and learn]:&lt;/p&gt;
&lt;p&gt;The argument we are matching has an optional component at the front. This optional component must start with an optional &quot;http://&quot; followed by an optional word and a dot (eg, &quot;www.&quot; or &quot;uk.&quot;) followed by &quot;youtube.com/&quot; (not optional) followed by either &quot;v/&quot; or &quot;&quot; or &quot;watch&quot; or &quot;watch.php&quot; followed by &quot;?&quot; followed by either &quot;v=&quot; or &quot;xxxxxx&amp;amp;v=&quot; where each &quot;x&quot; represents some character (each x can be a different character) and there can be any number of such x&#039;s but at least 1. OK, that was the optional part at the beginning.&lt;/p&gt;
&lt;p&gt;This is followed by a grouping of characters composed of one or more lc, uc, digit, &quot;_&quot;, and/or &quot;-&quot;. Eg, &quot;fBWoWFF3OYU&quot; fits this pattern. Also note that this part is () and not (?: ) because we want to &quot;grab&quot; it.&lt;/p&gt;
&lt;p&gt;Finally the last part is an extension with which I am not familiar. I think it was introduced fairly recently in perl (last few years). Whatever it matches must follow what has been covered here up to this point and must also match through to the end of the argument that is being tested.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;
&lt;p&gt;There you have it for Regular Expressions 101 and 102-pre. If this did not make that much sense, maybe you skipped the exercises &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;. Do use the link provided to try out examples.&lt;/p&gt;
&lt;p&gt;Corrections, complaints, etc are welcomed.&lt;/p&gt;
&lt;p&gt;Oooops, I can&#039;t leave yet without at least talking a bit about the &quot;pay-off&quot; of using regular expressions.&lt;/p&gt;
&lt;p&gt;A simple example:&lt;/p&gt;
&lt;p&gt;You want to know if any of the words &quot;apple&quot; &quot;bear&quot; &quot;cat&quot; &quot;zoology&quot; is found in some prose (eg, some website page). You also want to know if certain derivatives of these words are found, eg, apples, bearish, catty, etc. Finally, you want to know which words were found and where.&lt;/p&gt;
&lt;p&gt;OK, try coding that without regular expressions. It isn&#039;t that that complicated but it is tedious and error prone. Meanwhile, I can do a regular expression that would look ugly to the uninitiated but would otherwise capture this requirement in a tiny compact space and be readable once you have mastered the art.&lt;/p&gt;
&lt;p&gt;For example, there are many possibilities to structure this, in part depending on whether you have even more requirements than what I just finished mentioning; however, consider this re for finding matches and knowing the word that is matched:&lt;/p&gt;
&lt;p&gt;(aaples?|bear(?:s|ish|er)|cat(?:ty|s|ch-up)|zoology)&lt;/p&gt;
&lt;p&gt;Note that we would have access to the actual word and where it was located (because we used () on the outside). We also used (?: ) on the inside to make the searching more efficient since we would not care (in this hypothetical example) of having a link to the beginning of the particular ending; thus, the searching done behind the scenes (by the RE machine) wouldn&#039;t have to slow down and take extra processing instructions to grab links/pointers to the subparts each and every time.&lt;/p&gt;
&lt;p&gt;Caution: regular expressions cannot all by themselves accurately find any type of match you may want, but usually by adding some code (some loops with re&#039;s embedded inside of them) you can do almost anything you may require. An example of where to pass on REs is if you need to do massive xml/html/etc processing and manipulation. RE&#039;s won&#039;t work without a bunch of other code anyway, so you would be better off cleanly using an xml parsing library (RE&#039;s don&#039;t generally accurately identify the sort of nesting one needs to be able to find in XML parsing).&lt;/p&gt;
&lt;p&gt;You may also have noted that I did not explain how to do a single match or a match/consume cycle. Basically, this can be done by calling different functions or using extra arguments to the functions. Essentially, that is a topic that depends on the language and is not really important for understanding REs. Just know that this capability is included as part of the deal and is part of what makes re&#039;s useful since many times knowing what matched and/or where it matched is really what you want and not just to know that something?? did match somewhere??&lt;/p&gt;
&lt;p&gt;Still can&#039;t get enough? OK, continue your RE 102 education with &lt;a href=&quot;http://www.regular-expressions.info/named.html&quot;&gt;http://www.regular-expressions.info/named.html&lt;/a&gt;&lt;/p&gt;
 </description>
 <pubDate>Sun, 17 Feb 2008 20:30:42 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11987 at http://www.nuxified.org</guid>
</item>
<item>
 <title>Continuing where left</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11980</link>
 <description> &lt;p&gt;Continuing where left off...&lt;/p&gt;
&lt;p&gt;So we are at the comment line &quot;# Verify video URL format and convert to &quot;standard&quot; format&quot;. The last thing done was to put the main argument to this script (eg, fBWoWFF3OYU) into video_url_cmdl&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; video_url_mo = const_video_url_re.match(video_url_cmdl)&lt;br /&gt;
&amp;gt;&amp;gt; if video_url_mo is None: ...&lt;br /&gt;
Now we use what is called a &quot;regular expression&quot; to verify that this argument (eg, fBWoWFF3OYU) fits the pattern we expect. A regular expression is like a template that can be used to verify any text and can be used to grab subtext from a larger text. I won&#039;t explain the rules but the template is const_video_url_re which we look up at near the top initialization portion of this script and find to be the following monster:&lt;br /&gt;
^((?:http://)?(?:\w+\.)?youtube\.com/(?:v/|(?:watch(?:\.php)?)?\?(?:.+&amp;amp;)?v=))?([0-9A-Za-z_-]+)(?(1)[&amp;amp;/].*)?$&lt;/p&gt;
&lt;p&gt;Roughly what this template (ie, the regular expression) says is that the argument can be something like fBWoWFF3OYU, but it can also take any of numerous other forms, eg, &lt;a href=&quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;&gt;http://www.youtube.com/watch?v=fBWoWFF3OYU&lt;/a&gt; .&lt;/p&gt;
&lt;p&gt;Also, at the same time that this argument is matched/verified, the fBWoWFF3OYU portion is saved. We see part of the power of regular expression handling since whether we had &quot;fBWoWFF3OYU&quot; or &quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot; or something else that fits the template, the fBWoWFF3OYU portion would be isolated and stored apart.&lt;/p&gt;
&lt;p&gt;Next we come to:&lt;br /&gt;
&amp;gt;&amp;gt; video_url_id = video_url_mo.group(2)&lt;br /&gt;
which is where we take the fBWoWFF3OYU and save it into the variable video_url_id&lt;/p&gt;
&lt;p&gt;Next:&lt;br /&gt;
&amp;gt;&amp;gt; video_url = const_video_url_str % video_url_id&lt;br /&gt;
would put into the variable video_url the following string of text: &quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;. [Look back to the top of the file to verify what const_video_url_str is]&lt;/p&gt;
&lt;p&gt;To recap what looks like the most important part of these last two mini sections, we have set two variables. Using our running example of fBWoWFF3OYU, we have:&lt;br /&gt;
video_url_id = &quot;fBWoWFF3OYU&quot;&lt;br /&gt;
video_url = &quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;&lt;/p&gt;
&lt;p&gt;Note that if our original &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term519&quot;&gt;&lt;acronym title=&quot;CLI: Command Line Interface&quot;&gt;cli&lt;/acronym&gt;&lt;/a&gt; command had been (borrowing the example from the parent post and fixing it a bit):&lt;br /&gt;
./youtube-dl --title sometitle --username myusernameIguess --password asupersecretyoutubepasswordIguess fBWoWFF3OYU&lt;br /&gt;
or&lt;br /&gt;
./youtube-dl --title sometitle --username myusernameIguess --password asupersecretyoutubepasswordIguess &lt;a href=&quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;&gt;http://www.youtube.com/watch?v=fBWoWFF3OYU&lt;/a&gt;&lt;br /&gt;
or even&lt;br /&gt;
./youtube-dl --title sometitle --username myusernameIguess --password asupersecretyoutubepasswordIguess &lt;a href=&quot;http://uk.youtube.com/watch.php?v=fBWoWFF3OYU&quot;&gt;http://uk.youtube.com/watch.php?v=fBWoWFF3OYU&lt;/a&gt;&lt;br /&gt;
... in all three cases (and anything else that fit the template), we would end up with exactly:&lt;br /&gt;
video_url_id = &quot;fBWoWFF3OYU&quot;&lt;br /&gt;
video_url = &quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;&lt;br /&gt;
The magic was that no matter which of the ways we use to enter the info, the regular expression processing allowed us to pluck out the fBWoWFF3OYU and then use that to construct a very specific url &lt;a href=&quot;http://www.youtube.com/watch?v=fBWoWFF3OYU&quot;&gt;http://www.youtube.com/watch?v=fBWoWFF3OYU&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;OK.&lt;/p&gt;
&lt;p&gt;The next section, as the comments in the script indicate [comments start with &quot;#&quot;], are just some tests on the flags that were passed in if any. From reading the error messages, we get a better idea of what the flags represent. For example, it seems you can&#039;t specify a specific name for the output file (ie, the name under which the download will be saved, or so that seems to be where this is leading) as well as specify that you want the title of the download to be used as the name of the file under which the download will be saved. Ie, this is a conflict, so the script ends end displays an error message. You can only specify one of --output --title or --literal.&lt;/p&gt;
&lt;p&gt;We also note that --netrc seems to be incompatible with either --username or (--username and) --password. I don&#039;t yet know what this means though.&lt;/p&gt;
&lt;p&gt;The next section does some testing to determine the variables account_username and account_password [the goal of this section seems to be to come up with these two values]. netrc was something we imported at the top. I am guessing netrc is used to access some system or computer wide username/password that is attached to the youtube domain and can be used for authentication. Maybe python can be configured to use system defaults. Maybe ldap.. I don&#039;t know. I am guessing. In any case, we can forget about netrc (ie, no need to worry about the --netrc flag). It&#039;s looking like we supply to this script the username and password we have for youtube. Now, is this mandatory? Well, if we keep reading the script, we should find out. We should also find out how it is that we can authenticate with youtube automatically (I&#039;ve only done so through the browser by clicking on login or whatever as is the usual procedure). Let me also bring up that it looks like youtube uses cookies to know that you are returning so as to keep you logged in. Thus I expect that a dialogue with youtube through this script, if it requires logging in and if it uses the http protocol, will probably involve passing cookies back and forth to the youtube servers in the http header files. If anyone is confused, don&#039;t worry. We should get a better idea of what is going on as we make our way through this script. If cookies are used, I&#039;ll try and explain that as simply as I can at such time.. for anyone that wants to know how that works.&lt;/p&gt;
&lt;p&gt;So, to use the running example, from this section we end up with:&lt;br /&gt;
account_username = myusernameIguess&lt;br /&gt;
account_password = asupersecretyoutubepasswordIguess&lt;/p&gt;
&lt;p&gt;OK, time for me to take a time out. I may not get back until tomorrow since I&#039;ll be busy for a while.&lt;/p&gt;
&lt;p&gt;Something that I will probably have to end up trying when I get stuck (and you people might want to do too) will be to load up python and run this script, but before doing so, add print statements to list out the values in variables or to poke as the need/curiosity dictates. Python can be run interactively, so you can run only a fraction of these script lines and even modify it throughout. However, running interactively, while more powerful in some ways, means you have to simulate the environment where the cli command was passed in. So to make things easy, just forget about starting up the interpreter by itself. Instead add print statements (not sure what python&#039;s version of print/echo is) so that you can see what happens (the script file we modify is youtube-dl.. ie, the file being dissected). If you are really curious, consider also adding your login info is you have a youtube account, but I don&#039;t know if that is needed.&lt;/p&gt;
&lt;p&gt;Again, if anyone wants to share insight or continue exploring the code...&lt;/p&gt;
&lt;p&gt;[Just looked at libervisco&#039;s script (youtube-install.sh) a little closer. It&#039;s just an installation script (gee, the name should have given it away). I guess I misunderstood the top post. Anyway, if you don&#039;t want the actual script you call, youtube-dl, to be installed into /usr/local/bin, then DON&#039;T run libervisco&#039;s script. I&#039;m not saying there is any harm in installing it that way. Just pointing it out in case you like to install it somewhere under your home directory, within the current scratch directory, or just somewhere else or just don&#039;t have root access. If you opt out of running youtube-install.sh, then you still have to download youtube-dl somehow. Use for example &quot;wget -c &lt;a href=&quot;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&quot;&gt;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&lt;/a&gt;&quot; to download it. Then to run youtube-dl, make sure you have the execute bit set (that is part of what libervisco&#039;s installer does).]&lt;/p&gt;
 </description>
 <pubDate>Sat, 16 Feb 2008 23:32:02 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11980 at http://www.nuxified.org</guid>
</item>
<item>
 <title>OK, Here is a first crack</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11979</link>
 <description> &lt;p&gt;OK, Here is a first crack at dissecting the python program/script.&lt;/p&gt;
&lt;p&gt;The url for it is &lt;a href=&quot;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&quot;&gt;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&lt;/a&gt; . Reference it because I don&#039;t want to post it here all at once (though if someone really wants to they can -- it uses a very &quot;liberal&quot; license). I may quote heavily from the script though.&lt;/p&gt;
&lt;p&gt;It is important to know right now that I make guesses throughout whenever I think I can pull it off based on context. At some point we should verify our hunches by looking up the source code for these external libraries/objects being used indirectly (eg, external python imported through the &quot;import&quot; statement).&lt;/p&gt;
&lt;p&gt;...&lt;/p&gt;
&lt;p&gt;The first section shows that some existing python libraries will be used. We can ignore this section until we get to the actual function calls later on that we don&#039;t understand. Guessing from the names of these libraries, it looks to me like they will (among other things) handle the technical details of fetching from the web what we want as well as building up the queries perhaps.&lt;/p&gt;
&lt;p&gt;Next we have a bunch of variable/constant definitions. We can ignore these also until we get to them. The point here is probably to allow the rest of the script to be easier to read and to maintain.&lt;/p&gt;
&lt;p&gt;Next we get into a bunch of function definitions. We ignore these too for the moment.&lt;/p&gt;
&lt;p&gt;At this point the script actually starts to do real work (prior to this, the python interpreter would &quot;just&quot; be initializing itself up properly storing definitions).&lt;/p&gt;
&lt;p&gt;Lets look at the first small section after &#039;# Create the command line options parser and parse command line&#039; consisting of a group of similar looking lines. This part is like administrative overhead but let&#039;s cover it quickly.&lt;/p&gt;
&lt;p&gt;The first 3 lines set up and start to make use of one of the objects/libraries we loaded up before, &quot;optparse&quot;. [There was an &quot;import optparse&quot; line earlier in the program.]&lt;/p&gt;
&lt;p&gt;One of the main thing done by the lines that follow is to store values entered at the command line (when calling this script) into variables that can be accessed througout the script as needed. [This is a case of me making a guess so as to avoid looking up the &quot;optparse&quot; source code.] For example, a variable named &quot;username&quot; would store whatever word followed the &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term519&quot;&gt;&lt;acronym title=&quot;CLI: Command Line Interface&quot;&gt;CLI&lt;/acronym&gt;&lt;/a&gt; flag &quot;--username&quot;. Other values are saved under &quot;password&quot; &quot;outfile&quot; &quot;quiet&quot; &quot;simulate&quot; &quot;use_title&quot; and some others.&lt;/p&gt;
&lt;p&gt;The next line (..socket..) sets the time out period when making a call out to google (or anywhere else). [Note again that I am guessing whenever I refer to something that was imported (&quot;import socket&quot;) unless I specifically state that I will look at that source code (in which case, I should provide a link).] The script author probably has an idea of what constitutes a healthy time out period for this script and doesn&#039;t want to rely on the defaults set up by whoever wrote the &quot;socket&quot; code. The actual value &quot;const_timeout&quot; is a variable, so we look back to find it and note that it is set to &quot;120&quot; at the top of the script. My guess is that this 120 represents seconds to the socket object. That&#039;s a long timeout if you are there waiting interactively but can be useful if you were running the script overnight or automatically as part of some batch processing (eg, downloading while you sleep or in the background a bunch of videos you looked at during the day). In this latter case, you want to give the network or the google servers some time to recover if they are busy. [Corrections are welcomed.. since I am not looking at source code to verify this.]&lt;/p&gt;
&lt;p&gt;The next statement (&quot;if&quot; statement across 3 lines) in conjunction with the one just above the socket code, ie:&lt;br /&gt;
&amp;gt;&amp;gt; (cmdl_opts, cmdl_args) = cmdl_parser.parse_args()&lt;br /&gt;
&amp;gt;&amp;gt; if len(cmdl_args) != 1: ....&lt;/p&gt;
&lt;p&gt;just checks that this script is called with any number of flags but only a single other argument. If not the program ends and a message is printed. That argument &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term415&quot;&gt;&lt;acronym title=&quot;BTW: By the way&quot;&gt;btw&lt;/acronym&gt;&lt;/a&gt; is stored into the &quot;cmdl_args&quot; array (or list or whatever else python uses through the &quot;(..)=..&quot; syntax) and represents the name of the video to download. So you might call this script as follows:&lt;/p&gt;
&lt;p&gt;youtube-dl --title sometitle --username myusernameIguess --password asupersecretyoutubepasswordIguess fBWoWFF3OYU&lt;/p&gt;
&lt;p&gt;.. or so I am guessing at this point since not too many clues have been provided (but we&#039;ll keep reading the source code to see what is up &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt; ).&lt;/p&gt;
&lt;p&gt;&amp;gt;&amp;gt; video_url_cmdl = cmdl_args[0]&lt;br /&gt;
Here we place (eg) &quot;fBWoWFF3OYU&quot; from the storage space cmdl_args[0] into video_url_cmdl. Ie, we simply now have a &quot;nicer&quot; variable name through which to access the value we entered at the command line (I&#039;m assuming at this point that this value is the name of the video, but we&#039;ll eventually see how the script uses this value to see what it actually represents -- probably the name of the video &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt; .. like fBWoWFF3OYU for one of the freedomware videos).&lt;/p&gt;
&lt;p&gt;I&#039;ll stop here for now.&lt;/p&gt;
 </description>
 <pubDate>Sat, 16 Feb 2008 09:49:21 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11979 at http://www.nuxified.org</guid>
</item>
<item>
 <title>Why does wget</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11977</link>
 <description> &lt;p&gt;Why does ..&lt;/p&gt;
&lt;p&gt;wget &quot;http://www.youtube.com/get_video?video_id=fBWoWFF3OYU&amp;amp;t=&quot;&lt;/p&gt;
&lt;p&gt;.. not work? Google returns 404 not found error reply.&lt;/p&gt;
&lt;p&gt;[Reply is directed at the bashist 4-line shell script and assumes (based on some testing) that &quot;t:&#039;.....&#039;&quot; does not appear in the &quot;watch?v=.....&quot; page so that t=&quot;&quot; is essentially what is grep&#039;d out of that page.]&lt;/p&gt;
 </description>
 <pubDate>Sat, 16 Feb 2008 08:12:03 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11977 at http://www.nuxified.org</guid>
</item>
<item>
 <title>The script libervisco&#039;s</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11978</link>
 <description> &lt;p&gt;The script libervisco&#039;s script uses to do the heavy lifting is written in python ( &lt;a href=&quot;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&quot;&gt;http://www.arrakis.es/~rggi3/youtube-dl/youtube-dl&lt;/a&gt; ). I don&#039;t know python that well (at least I haven&#039;t used it before), but I think it would be interesting to take it apart and see what it is that makes it tick. We can post the results on this forum.&lt;/p&gt;
&lt;p&gt;I had hoped that the 4 line shell script presented by bashist would do that trick, but that one is not working for me. [I did not run it as directed but someone else claims it does not work. My attempt at doing the equivalent one line script (equiv for all intents and purposes) did not pan out either.]&lt;/p&gt;
&lt;p&gt;So does anyone else think it would be a good idea to analyze and explain the python script?&lt;/p&gt;
&lt;p&gt;I think I will attempt it but despite being relatively easy I don&#039;t speak python very well. Thus I may give up on it if I don&#039;t get results quickly (this would be where someone else chipping in would be beneficial to this effort).&lt;/p&gt;
 </description>
 <pubDate>Sat, 16 Feb 2008 08:10:03 +0100</pubDate>
 <dc:creator>Jose</dc:creator>
 <guid isPermaLink="false">comment 11978 at http://www.nuxified.org</guid>
</item>
<item>
 <title>If you just wanna download</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11974</link>
 <description> &lt;p&gt;If you just wanna download youtube videos you could also follow the three step instructions in the original post. &lt;img src=&quot;/misc/smileys/smile.png&quot; title=&quot;Smiling&quot; alt=&quot;Smiling&quot; /&gt;&lt;/p&gt;
&lt;p&gt;But if you want to get on it even faster, &lt;a href=&quot;http://keepvid.com/&quot;&gt;Keepvid.com&lt;/a&gt; might be for you. You just enter a video URL, select the site from which the video is and click download.&lt;/p&gt;
&lt;p&gt;But if you really want to run the mini script by bashist KIAaze&#039;s answers should help.&lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
 </description>
 <pubDate>Wed, 13 Feb 2008 22:57:33 +0100</pubDate>
 <dc:creator>libervisco</dc:creator>
 <guid isPermaLink="false">comment 11974 at http://www.nuxified.org</guid>
</item>
<item>
 <title>Copy the &quot;code&quot; into a text</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11973</link>
 <description> &lt;p&gt;Copy the &quot;code&quot; into a text file, save it (with a *.sh extension so you know it&#039;s a shellscript), set the execute permission and then run it.&lt;/p&gt;
&lt;p&gt;If you save it as &quot;dl_vid.sh&quot; for example, you can download videos by running:&lt;br /&gt;
&lt;code class=&quot;bb-code&quot;&gt;./dl_vid.sh xyz123&lt;/code&gt;&lt;br /&gt;
to download &lt;a href=&quot;http://www.youtube.com/watch?v=xyz123&quot;&gt;http://www.youtube.com/watch?v=xyz123&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[edit]Not sure about that. It doesn&#039;t seem to work for me that way...[/edit]&lt;/p&gt;
&lt;p&gt;To run the script from anywhere, just copy it into /usr/local/bin:&lt;br /&gt;
&lt;code class=&quot;bb-code&quot;&gt;sudo cp script.sh /usr/local/bin&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Note:&lt;br /&gt;
You could also create a script directory in your home and add it to the PATH variable in the .bashrc or .&lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term460&quot;&gt;&lt;acronym title=&quot;BASH: Bourne Again SHell (common CLI and scripting language on GNU/Linux)&quot;&gt;bash&lt;/acronym&gt;&lt;/a&gt;_profile files.&lt;br /&gt;
more info here: &lt;a href=&quot;http://www.troubleshooters.com/linux/prepostpath.htm&quot;&gt;http://www.troubleshooters.com/linux/prepostpath.htm&lt;/a&gt;&lt;/p&gt;
 </description>
 <pubDate>Wed, 13 Feb 2008 21:42:43 +0100</pubDate>
 <dc:creator>KIAaze</dc:creator>
 <guid isPermaLink="false">comment 11973 at http://www.nuxified.org</guid>
</item>
<item>
 <title>ThanX</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11972</link>
 <description> &lt;p&gt;problem was with rights. but i still don&#039;t know how to run scripts eg.&lt;br /&gt;
&lt;div class=&quot;quote-msg&quot;&gt;
&lt;div class=&quot;quote-author&quot;&gt;bashist wrote:&lt;/div&gt;
&lt;p&gt;#!/bin/&lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term460&quot;&gt;&lt;acronym title=&quot;BASH: Bourne Again SHell (common CLI and scripting language on GNU/Linux)&quot;&gt;bash&lt;/acronym&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;[ $# -eq 1 ] || exit -1&lt;/p&gt;
&lt;p&gt;t=$(wget -O- &quot;http://www.youtube.com/watch?v=$1&quot; | grep -o &quot;t:&#039;[^&#039;]\+&quot;)&lt;/p&gt;
&lt;p&gt;wget -O $1.flv &quot;http://www.youtube.com/get_video?video_id=$1&amp;amp;t=${t##*\&#039;}&quot;&lt;/div&gt;
&lt;p&gt;how to run it?&lt;/p&gt;
 </description>
 <pubDate>Wed, 13 Feb 2008 19:36:14 +0100</pubDate>
 <dc:creator>ponco</dc:creator>
 <guid isPermaLink="false">comment 11972 at http://www.nuxified.org</guid>
</item>
<item>
 <title>If you can&#039;t understand the</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11971</link>
 <description> &lt;p&gt;If you can&#039;t understand the explanations given in the first post, I&#039;ll assume you don&#039;t know how to use the command line yet.&lt;/p&gt;
&lt;p&gt;So please read those pages first:&lt;br /&gt;
&lt;a href=&quot;http://www.psychocats.net/ubuntu/terminal&quot;&gt;http://www.psychocats.net/ubuntu/terminal&lt;/a&gt;&lt;br /&gt;
&lt;a href=&quot;https://help.ubuntu.com/community/UsingTheTerminal&quot;&gt;https://help.ubuntu.com/community/UsingTheTerminal&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Once you know how to use basic commands like ls, cd, etc, you should be able to run scripts without any problems since a script works like a command.&lt;/p&gt;
&lt;p&gt;Note that once you&#039;ve downloaded the script, you will also have to make it executable by running the command:&lt;br /&gt;
&lt;code class=&quot;bb-code&quot;&gt;chmod 755 youtube-install.sh&lt;/code&gt;&lt;br /&gt;
This can also be done by right-clicking on the file, then &quot;properties&quot;-&amp;gt;&quot;permissions&quot;-&amp;gt;check &quot;allow executing file as a program&quot;&lt;/p&gt;
&lt;p&gt;P.S: This youtube download script appears to be trustworthy, however you should read this: &lt;a href=&quot;http://ubuntuforums.org/announcement.php?f=73&quot;&gt;http://ubuntuforums.org/announcement.php?f=73&lt;/a&gt;&lt;br /&gt;
Do not use scripts from people you don&#039;t trust, especially not with the sudo command!&lt;/p&gt;
&lt;p&gt;PPS: I&#039;m quite sure there are &lt;a class=&quot;glossary-term&quot; href=&quot;/glossary#term518&quot;&gt;&lt;acronym title=&quot;GUI: Graphical User Interface&quot;&gt;GUI&lt;/acronym&gt;&lt;/a&gt; apps or firefox plugins to download youtube videos. That way you wouldn&#039;t even have to touch the command line.&lt;br /&gt;
Unfortunately I don&#039;t know any specific one.&lt;br /&gt;
A quick gogle search gave me this:&lt;br /&gt;
&lt;a href=&quot;http://linux.softpedia.com/get/Multimedia/Video/Youtube-Downloader-GUI-28348.shtml&quot;&gt;http://linux.softpedia.com/get/Multimedia/Video/Youtube-Downloader-GUI-28348.shtml&lt;/a&gt;&lt;/p&gt;
 </description>
 <pubDate>Wed, 13 Feb 2008 18:28:25 +0100</pubDate>
 <dc:creator>KIAaze</dc:creator>
 <guid isPermaLink="false">comment 11971 at http://www.nuxified.org</guid>
</item>
<item>
 <title>freshman</title>
 <link>http://www.nuxified.org/blog/download_youtube_video_files_with_youtube_dl#comment-11970</link>
 <description> &lt;p&gt;Hi!!&lt;/p&gt;
&lt;p&gt;i sterted Using ubuntu before few weeks... can you tell me how to use your script?&lt;/p&gt;
&lt;p&gt;thank you very much.&lt;/p&gt;
 </description>
 <pubDate>Wed, 13 Feb 2008 15:21:19 +0100</pubDate>
 <dc:creator>ponco</dc:creator>
 <guid isPermaLink="false">comment 11970 at http://www.nuxified.org</guid>
</item>
</channel>
</rss>
