Advertisement
akovia

Untitled

Jul 29th, 2014
349
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 10.50 KB | None | 0 0
  1. #!/bin/bash
  2. #set -xv
  3.  
  4. # Version 1.2
  5. #***********************************************************NOTES *************************************************************************#
  6. # If you're using FireFox install the addon: Copy Urls Expert.                                                                             #
  7. # If you're using Chrome install the extension: Copy All Urls.                                                                             #
  8. # Simply browse any number of myfont pages in FireFox or Chrome. When done, simply copy all tab urls using one of the above addons         #
  9. # (doesn't matter if you got tabs open that are NOT myfonts! the script file will cleanse them!).                                          #
  10. # Paste the links in tab.txt (Ctrl+V) and then run mtfontrip.sh which will download the woff files and convert them to both woff and ttf.  #
  11. #                                                                                                                                          #
  12. # 20 web font previews are allowed if you are NOT signed in.                                                                               #
  13. # 50 web font previews are allowed if you ARE signed in.                                                                                   #
  14. #                                                                                                                                          #
  15. # wuts great is u can always create new IDs (username/passwords) without the hassle of providing REAL emails!                              #
  16. # so then just export the cookie.txt file for each user and use them! :)                                                                   #
  17. #                                                                                                                                          #
  18. # Go here first to generate a random English name+surname                                                                                  #
  19. # http://www.behindthename.com/random/random.php?number=1&gender=m&surname=&randomsurname=yes&all=no&usage_eng=1                           #
  20. #                                                                                                                                          #
  21. # Then here to create a new myfonts user account                                                                                           #
  22. # https://www.myfonts.com/secure/newuser/                                                                                                  #
  23. #                                                                                                                                          #
  24. # Enter like the below example                                                                                                             #
  25. # Your name         Sanford Howe                                                                                                           #
  26. # Email address     howe56@gmail.com                                                                                                       #
  27. # Password          howe56                                                                                                                 #
  28. # Password again        howe56                                                                                                             #
  29. #                                                                                                                                          #
  30. # Then install this                                                                                                                        #
  31. # http://wiert.me/2011/05/30/exporting-google-chrome-cookies-for-wget-usage-cookie-txt-export-google-chrome-extension-gallery/             #
  32. # click the button to see cookie info then Ctrl+A, Ctrl+C it then Ctrl+V it in a new txt file and name it wutever (ie. howe56.txt)         #
  33. # then Ctrl+D the wget line in myfontrip.sh and rename the previous cookie txt file to the new one. ie.                                    #
  34. # sed "s/.*/wget --load-cookies howe56.txt -P MyFonts\/ &webfont_preview.html/" myfonts_html.txt > myfonts_html.bat                        #
  35. # Make sure u got ur myfont links in tab.txt and you can simply run myfontrip.sh!                                                          #
  36. #***********************************************************NOTES *************************************************************************#
  37.  
  38.  
  39.  
  40. #:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: SET VARIABLES :::::::::::::::::::::::::::::::::::::::::::::::::::::
  41. export BINDIR=~/bin/MyFontDownloader/bin
  42. export TTFTEMP=~/bin/MyFontDownloader/bin/MyFonts
  43. export TTFTARGET=~/Fonts_Other/font-unarchive/merlin
  44. export FILEMAN=thunar
  45.  
  46. PATH=/usr/local/bin:$PATH
  47. FONTFORGE_LANGUAGE=ff
  48. export PATH FONTFORGE_LANGUAGE
  49.    
  50.    
  51. #
  52. # LETS START!!
  53. #
  54. #Change to bin Directory
  55. cd $BINDIR
  56. #
  57. # delete all lines NOT containing myfonts links from tabs.txt
  58. sed '/myfonts\.com\/fonts/!d' tabs.txt > myfonts_html.txt
  59. cat myfonts_html.txt | sort -u > myfonts_html1.txt
  60. rm myfonts_html.txt
  61. mv myfonts_html1.txt myfonts_html.txt
  62.  
  63. # Convert Dos Line Endings to Unix Format
  64. sed 's/.$//' myfonts_html.txt
  65.  
  66. #:::::::::::::::::::::::::::::::::::::::: CHOOSE COOKIE OPTIONS ::::::::::::::::::::::::::::::::::::::::
  67. #
  68. # ============================ WITH COOKIES (Better)===================================================
  69. #********NOTE************
  70. # I was unable to figure out how to use the $TTFTEMP variable in this command. (Won't expant properly) So these are the only commands with hard-coded paths.
  71.  
  72. # uncomment only the line with the cookie u want to use
  73. sed 's/\(^.*\)/wget --load-cookies cookies\/harve67.txt -PMyFonts\/ \1webfont_preview.html/' myfonts_html.txt > myfonts_html.sh
  74. # sed 's/\(^.*\)/wget --load-cookies cookies\/hamm45.txt -PMyFonts\/ \1webfont_preview.html/' myfonts_html.txt > myfonts_html.sh
  75. # sed 's/\(^.*\)/wget --load-cookies cookies\/croberts119.txt -PMyFonts\/ \1webfont_preview.html/' myfonts_html.txt > myfonts_html.sh
  76.  
  77. # Format Script to Bash and Enable
  78. echo '#!/bin/bash
  79. set -x' | cat - myfonts_html.sh > temp && mv temp myfonts_html.sh
  80. chmod +x myfonts_html.sh
  81.  
  82. # ============================ WITHOUT COOKIES =========================================================
  83. # uncomment all lines in section and don't forget to comment out the lines in the "with coockies" section above
  84. # sed "s/.*/wget -PMyFonts\/ &webfont_preview.html/" myfonts_html.txt > myfonts_html.sh
  85.  
  86. # Format Script to Bash and Enable
  87. # echo '#!/bin/bash
  88. # set -x' | cat - myfonts_html.sh > temp && mv temp myfonts_html.sh
  89. # chmod +x myfonts_html.sh
  90.  
  91.  
  92. #:::::::::::::::::::::::::::::::::::::::: EXECUTE THE BASH SCRIPT FILE THAT WILL DOWNLOAD ALL THE HTML FILES ::::::::::::::::::::::::::::::
  93. ./myfonts_html.sh
  94.  
  95. # concatenate all html files into 1 big txt file
  96. find "$TTFTEMP"/ -type f -print0 | sort -z | xargs -0 cat > allhmtls.txt
  97. # Clean up
  98. find "$TTFTEMP"/ -type f -delete
  99.  
  100.  
  101. #:::::::::::::::::::::::::::::::::::::::: PROCESSING HTMLs TO GET THE CSS LINKS ::::::::::::::::::::::::::::::::::::::::
  102.  
  103. # delete all lines NOT containing the word easy
  104. sed '/easy\.myfonts\.net/!d' allhmtls.txt > myfonts_css.txt
  105. # clean it up...
  106. sed -i "s/<link.*\/\/\|'>//g" myfonts_css.txt
  107.  
  108. # add curl command
  109. sed -i 's/.*/curl -o MyFonts\/cssxplaceholder &/' myfonts_css.txt
  110. # now we have to put a counter to each css file so they dont get overwritten!
  111. perl -ple 's/placeholder/$n++/e' myfonts_css.txt > myfonts_css.sh
  112. # Format Script to Bash and Enable
  113. echo '#!/bin/bash
  114. set -x' | cat - myfonts_css.sh > temp && mv temp myfonts_css.sh
  115. chmod +x myfonts_css.sh
  116.  
  117. #:::::::::::::::::::::::::::::::::::::::: EXECUTE THE BASH FILE THAT WILL DOWNLOAD ALL THE CSS FILES ::::::::::::::::::::::::::::::::::::::::
  118. ./myfonts_css.sh
  119.  
  120. # concatenate all css files into 1 big txt file
  121. find "$TTFTEMP"/ -type f -print0 | sort -z | xargs -0 cat > allcss.txt
  122. # Clean up
  123. find "$TTFTEMP"/ -type f -delete
  124.  
  125. # remove all of the base fonts
  126. sed "/Rooney\|ClickBits\|Network/d" allcss.txt > lesscss.txt
  127.  
  128. #:::::::::::::::::::::::::::::::::::::::: PROCESSING CSSs TO GET THE FONT LINKS ::::::::::::::::::::::::::::::::::::::::
  129.  
  130. # now we start matching the ttf font links
  131. grep -o -P "(v[0-9]/ttf)(.*?)(?=\))" lesscss.txt > myfonts_font.txt
  132.  
  133. # add curl command
  134. sed -i "s/.*/curl -o MyFonts\/fontxplaceholder 'easy.myfonts.net\/&'/" myfonts_font.txt
  135. sed -i "s/'/\"/g" myfonts_font.txt
  136.  
  137. # now we have to put a counter to each font file so they dont get overwritten!
  138. perl -ple 's/placeholder/$n++/e' myfonts_font.txt > myfonts_font.sh
  139.  
  140. # Format Script to Bash and Enable
  141. echo '#!/bin/bash
  142. set -x' | cat - myfonts_font.sh > temp && mv temp myfonts_font.sh
  143. chmod +x myfonts_font.sh
  144.  
  145. #:::::::::::::::::::::::::::::::::::::::: EXECUTE THE BASH FILE TO RETRIEVE FONTS & PROCESS ::::::::::::::::::::::::::::::::::::::::
  146. ./myfonts_font.sh
  147.  
  148. # Rename to .ttf Files
  149. find "$TTFTEMP"/ -type f -print0 | xargs -0 -I{} mv "{}" "{}".ttf
  150.  
  151. # this will reencode the fonts to utf8, which we can then convert to otf using transtype pro 3 if we wish
  152. ./convert2ttf
  153.  
  154. #::::::::::::::::::::::::::::::::::::::::: CLEANUP ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  155. # Clean Up temp fonts
  156. rm "$TTFTEMP"/fontx*.ttf
  157. #find "$TTFTEMP"/*.ttf -regextype posix-extended -regex '^(.*[^_][^0-9]{1,2}\.ttf)' -delete
  158.  
  159. # remove the _numbers from the font filenames. Any fonts left with trailing rm allcss.txt allhmtls.txt myfonts_css.sh myfonts_css.txt myfonts_html.txt myfonts_html.sh myfonts_font.sh myfonts_font.txtnumbers in the filenames (fontname_##.ttf) are duplicates
  160. rename 's/_\d+\././' $TTFTEMP/*.ttf
  161.  
  162. # cleanup gererated files (everything BUT lesscss.txt!!!!)
  163. rm allcss.txt allhmtls.txt myfonts_css.sh myfonts_css.txt myfonts_html.txt myfonts_html.sh myfonts_font.sh myfonts_font.txt
  164.  
  165. # here we empty tabs.txt to signify that we are done with those fonts. im placing this at the very end of the script so that if no fonts were downloaded i can quit the procedure b4 hand
  166. sed -i "s/.*//g" tabs.txt
  167. sed -i "/^\s*$/d" tabs.txt
  168.  
  169. #:::::::::::::::::::::::::::::::::::::::::: POST PROCCESSING ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  170. # Move Fonts to their final destination
  171. mv $TTFTEMP/*.ttf $TTFTARGET
  172.  
  173. #:: ALL DONE!!! CHECK THE TTFTARGET FOLDER FOR THE FONTS!!!  or have these commands do it for u :)
  174. $FILEMAN $TTFTARGET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement