Author Topic: Tumblr page viewer  (Read 3268 times)

0 Members and 1 Guest are viewing this topic.

Offline loudar

  • Newbie
  • Posts: 73
  • improve it bit by bit.
    • View Profile
Tumblr page viewer
« on: July 27, 2020, 11:05:54 pm »
Hey everyone!

Since I personally love having a little board of inspiration up sometimes, I always wanted a way to display many images at once, organized in a grid. I know the image handling is far from optimal, but it's the best I came up with for today.

Just put in the subdomain-name (name.tumblr.com), then the program will use wget (make sure you have it installed, I've attached it) to fetch the images.
 

Scroll through! :D

Code: QB64: [Select]
  1. 'Tumblr viewer
  2. maxblogs = 50
  3. DIM SHARED bn$(maxblogs)
  4. DIM SHARED lu$(maxblogs)
  5. DIM SHARED foldername$
  6.  
  7. SCREEN _NEWIMAGE(250, 200, 32)
  8.  
  9. maxpages = 5
  10.  
  11. INPUT "blogname: ", blogname$
  12.  
  13. folder$ = _STARTDIR$
  14. IF _FILEEXISTS(folder$ + "\view\lastupdate.txt") = 0 THEN OPEN folder$ + "\view\lastupdate.txt" FOR OUTPUT AS #1: CLOSE #1
  15. OPEN folder$ + "\view\lastupdate.txt" FOR INPUT AS #1
  16. IF LOF(1) > 0 THEN
  17.     DO
  18.         b = b + 1
  19.         INPUT #1, bn$(b), lu$(b)
  20.         IF bn$(b) = blogname$ AND lu$(b) = DATE$ THEN
  21.             dontupdate = 1
  22.         END IF
  23.     LOOP UNTIL EOF(1) = -1
  24. maxb = b
  25.  
  26. LOCATE 3, 1
  27. PRINT "Downloading..."
  28. PRINT "[" + CHR$(176) + longchar$(" ", 9) + "] 0%"
  29.  
  30. IF dontupdate = 0 THEN
  31.     OPEN folder$ + "\view\lastupdate.txt" FOR OUTPUT AS #1
  32.     b = 0
  33.     found = 0
  34.     IF maxb > 0 THEN
  35.         DO
  36.             b = b + 1
  37.             IF bn$(b) = blogname$ THEN
  38.                 found = 1
  39.                 lu$(b) = DATE$
  40.             END IF
  41.             WRITE #1, bn$(b), lu$(b)
  42.         LOOP UNTIL b = maxb
  43.     END IF
  44.     IF found = 0 THEN
  45.         WRITE #1, blogname$, DATE$
  46.     END IF
  47.     CLOSE #1
  48.     url$ = "https://" + blogname$ + ".tumblr.com/"
  49.     formats$ = "jpg"
  50.     foldername$ = "view\" + blogname$
  51.     options$ = "-nd -rH -p -D64.media.tumblr.com -A " + formats$ + " -e robots=off " + url$ + " -P " + folder$ + "\" + foldername$
  52.     SHELL "wget " + options$
  53.  
  54.     baseurl$ = "https://" + blogname$ + ".tumblr.com/page/"
  55.     pagecount = 1: DO: pagecount = pagecount + 1
  56.         LOCATE 3, 1
  57.         PRINT "Downloading page " + LTRIM$(STR$(pagecount)) + "..."
  58.         PRINT "[" + longchar$(CHR$(219), (pagecount - 1) / maxpages * 10) + CHR$(176) + longchar$(" ", (maxpages - pagecount) / maxpages * 10) + "] " + LTRIM$(STR$((pagecount - 1) / maxpages * 100)) + "%"
  59.  
  60.         url$ = baseurl$ + LTRIM$(STR$(pagecount)) + "/"
  61.         formats$ = "jpg"
  62.         options$ = "-nd -rH -p -D64.media.tumblr.com -A " + formats$ + " -e robots=off " + url$ + " -P " + folder$ + "\" + foldername$
  63.  
  64.         IF pagecount < maxpages THEN
  65.             SHELL _DONTWAIT "wget " + options$
  66.         ELSE
  67.             SHELL "wget " + options$
  68.         END IF
  69.     LOOP WHILE pagecount < maxpages
  70.     foldername$ = "view\" + blogname$
  71.  
  72. SCREEN _NEWIMAGE(maxx, maxy, 32)
  73.  
  74. maximages = 500
  75. DIM SHARED image&(maximages)
  76. DIM SHARED posx(-5 TO maximages)
  77. DIM SHARED posy(-5 TO maximages)
  78. DIM SHARED columns
  79. DIM SHARED pwidth
  80. DIM SHARED autoscroll
  81.  
  82. columns = 5
  83. pwidth = maxx / columns
  84. autoscroll = 0
  85.  
  86. spec$ = _STARTDIR$ + "\" + foldername$
  87. file$ = DiR$(spec$) 'use a file spec ONCE to find the last file name listed
  88. IF DiRCount% > 1 THEN
  89.     posx(0) = pwidth * (columns - 1)
  90.     i = 0: DO
  91.         file$ = _STARTDIR$ + "\" + foldername$ + "\" + DiR$("") 'use an empty string parameter to return a list of files!
  92.         IF file$ <> _STARTDIR$ + "\" + foldername$ + "\" AND MID$(file$, LEN(file$) - 6, 3) <> "500" THEN
  93.             i = i + 1
  94.             image&(i) = _LOADIMAGE(file$, 32)
  95.             'IF image&(i) < -1 THEN
  96.             posx(i) = posx(i - 1) + pwidth
  97.             IF posx(i) > pwidth * (columns - 1) THEN
  98.                 posx(i) = 0
  99.             END IF
  100.             IF i > 4 THEN
  101.                 posy(i) = posy(i - columns) + (_HEIGHT(image&(i - columns)) * (pwidth / _WIDTH(image&(i - columns))))
  102.             ELSE
  103.                 posy(i) = 0
  104.             END IF
  105.             _PUTIMAGE (posx(i), posy(i))-(posx(i) + pwidth, posy(i) + (_HEIGHT(image&(i)) * (pwidth / _WIDTH(image&(i))))), image&(i)
  106.             IF highest < posy(i) + (_HEIGHT(image&(i)) * (pwidth / _WIDTH(image&(i)))) THEN
  107.                 highest = posy(i) + (_HEIGHT(image&(i)) * (pwidth / _WIDTH(image&(i))))
  108.             END IF
  109.             'ELSE
  110.             '    i = i - 1
  111.             'END IF
  112.         ELSEIF file$ <> _STARTDIR$ + "\" + foldername$ + "\" THEN
  113.             KILL file$
  114.         END IF
  115.     LOOP UNTIL file$ = _STARTDIR$ + "\" + foldername$ + "\" OR i = maximages - 1 'file list ends with an empty string
  116.     maxi = i - 1
  117.  
  118.     Taste$ = INKEY$
  119.     IF Taste$ = CHR$(0) + CHR$(133) THEN
  120.         IF _FULLSCREEN = 0 THEN
  121.             _FULLSCREEN _SQUAREPIXELS
  122.         ELSE
  123.             _FULLSCREEN _OFF
  124.         END IF
  125.     END IF
  126.     'IF Taste$ = "a" THEN
  127.     '    IF autoscroll = 1 THEN autoscroll = 0 ELSE autoscroll = 1
  128.     'END IF
  129.     IF autoscroll = 1 THEN
  130.         IF (TIMER MOD 1) MOD 0.05 = 0 THEN
  131.             change = 1
  132.             IF scrollpos + _HEIGHT < posy(maxi) + (_HEIGHT(image&(maxi)) * (pwidth / _WIDTH(image&(maxi)))) THEN
  133.                 scrollpos = scrollpos + 1
  134.             ELSE
  135.                 scrollpos = 0
  136.             END IF
  137.         END IF
  138.     ELSE
  139.         mouseinput = _MOUSEINPUT
  140.         mousewheel = _MOUSEWHEEL
  141.         IF mouseinput = -1 THEN
  142.             IF mousewheel = -1 THEN
  143.                 change = 1
  144.                 IF scrollpos + _HEIGHT < posy(maxi) + (_HEIGHT(image&(maxi)) * (pwidth / _WIDTH(image&(maxi)))) THEN
  145.                     scrollpos = scrollpos + (maxy / 10)
  146.                 END IF
  147.             ELSEIF mousewheel = 1 THEN
  148.                 change = 1
  149.                 IF scrollpos > 0 THEN
  150.                     scrollpos = scrollpos - (maxy / 10)
  151.                 END IF
  152.             END IF
  153.         END IF
  154.     END IF
  155.     IF change = 1 AND maxi > 0 THEN
  156.         change = 0
  157.         CLS
  158.         FOR i = 1 TO maxi
  159.             IF posy(i) - scrollpos < maxy AND posy(i) + (_HEIGHT(image&(i)) * (pwidth / _WIDTH(image&(i)))) - scrollpos > -1 THEN
  160.                 _PUTIMAGE (posx(i), posy(i) - scrollpos)-(posx(i) + pwidth, posy(i) + (_HEIGHT(image&(i)) * (pwidth / _WIDTH(image&(i)))) - scrollpos), image&(i)
  161.             END IF
  162.         NEXT
  163.         _DISPLAY
  164.     END IF
  165.     '_LIMIT 60
  166. LOOP UNTIL Taste$ = CHR$(27)
  167.  
  168. FUNCTION DiR$ (spec$)
  169.     CONST TmpFile$ = "DiR$iNF0.iNF", ListMAX% = 500 'change maximum to suit your needs
  170.     SHARED DiRCount% 'returns file count if desired
  171.     STATIC Ready%, index%, DirList$()
  172.     IF NOT Ready% THEN REDIM DirList$(ListMAX%): Ready% = -1 'DiM array first use
  173.     IF spec$ > "" THEN 'get file names when a spec is given
  174.         SHELL _HIDE "DiR " + spec$ + " /b > " + TmpFile$
  175.         index% = 0: DirList$(index%) = "": ff% = FREEFILE
  176.         OPEN TmpFile$ FOR APPEND AS #ff%
  177.         size& = LOF(ff%)
  178.         CLOSE #ff%
  179.         IF size& = 0 THEN KILL TmpFile$: EXIT FUNCTION
  180.         OPEN TmpFile$ FOR INPUT AS #ff%
  181.         DO WHILE NOT EOF(ff%) AND index% < ListMAX%
  182.             index% = index% + 1
  183.             LINE INPUT #ff%, DirList$(index%)
  184.         LOOP
  185.         DiRCount% = index% 'SHARED variable can return the file count
  186.         CLOSE #ff%
  187.         KILL TmpFile$
  188.     ELSE IF index% > 0 THEN index% = index% - 1 'no spec sends next file name
  189.     END IF
  190.     DiR$ = DirList$(index%)
  191.  
  192. FUNCTION longchar$ (char$, length) 'returns a string consisting of one character repeated (length) times
  193.     temp$ = ""
  194.     IF length > 0 THEN
  195.         l = 0: DO: l = l + 1
  196.             temp$ = temp$ + char$
  197.         LOOP UNTIL l = length
  198.     END IF
  199.     longchar$ = temp$
Check out what I do besides coding: http://loudar.myportfolio.com/

Offline SpriggsySpriggs

  • Forum Resident
  • Posts: 1145
  • Larger than life
    • View Profile
    • GitHub
Re: Tumblr page viewer
« Reply #1 on: July 28, 2020, 07:09:14 am »
Nice!
Shuwatch!