Korisne skripte, kodovi ...

Korisne skripte, kodovi ...

offline
  • Pridružio: 14 Feb 2008
  • Poruke: 12405

Sigurno ste nekad naleteli na neki deo koda koji je univerzalan i koristan ili možda neku skripticu za nešto.

Evo teme gde takve kodove možete podeliti.

Sledeća autohotkey skripta piše naziv pesme koja se reprodukuje u txt fajl.
Pre kompajliranja je potrebno podesiti parametre, ovi ispod su podešeni za Youtube i Google Chrome.

  1. ; Stream-Friendly Music Ticker v1
  2. ; https://github.com/gustafsonk/SFMT
  3.  
  4. ; Description:
  5. ; This script is intended to make it possible to share the currently playing song from your media
  6. ; player through a streaming program. It works by scraping the title of your media player's window,
  7. ; outputting the part you want to a file, and reading the file through a streaming program.
  8.  
  9. ; Supported Media Players?
  10. ; Winamp, foobar2000, Spotify, YouTube (via web browser), MusicBee, MediaMonkey, VLC, WMP, iTunes,
  11. ; and any other media player that can display the currently playing song in the title of its window.
  12.  
  13. ; Supported Streaming Programs?
  14. ; OBS, XSplit, FFsplit, and any other streaming program that can read text from a file.
  15.  
  16. ; Pros and Cons?
  17. ; + No dependency on any specific media player
  18. ; + Supports Unicode characters
  19. ; + Easy to trim junk off the beginning and end of a window title
  20. ; + Fix for padding out scrolling text in OBS
  21. ; + Multi-platform (untested, but use IronAHK instead of AutoHotkey_L)
  22. ; + Open-source, well-documented, and easy-to-edit
  23. ; - No GUI for configuration (yet)
  24.  
  25. ; Instructions:
  26. ; 1. Download and install AutoHotkey_L from http://www.autohotkey.com (should be the default one).
  27. ; 2. Save/Extract the SFMT.ahk file to your computer (ZIP button in the top left of GitHub).
  28. ; 3. Run this file by double-clicking on it to generate the output file, which is where your now
  29. ;    playing song will be later. By default, it's "nowplaying.txt" and refreshes every 3 seconds.
  30. ; 4. Open your media player of choice and begin playing music.
  31. ; 5. Using your streaming program, add a text source for the output file.
  32. ; 6. Right-click the .ahk file, click Edit Script, and edit the CONFIGURE ME section below for your
  33. ;    media player/streaming program (see example below for help).
  34. ; 7. While configuring the file, you should perform the following workflow: edit the file,
  35. ;    save the file, right-click the H icon in the system tray, click Reload This Script,
  36. ;    and finally open the output file/preview the stream to see if it looks the way you want.
  37.  
  38. ; Example Configuration:
  39. ; First get the title of your media player's window. You can do this by hovering over the program
  40. ; in the taskbar or system tray and waiting a bit for text to appear. If you're having trouble with
  41. ; this or you can't find it, you can still figure it out by looking at the contents of the output
  42. ; file after you do this next step. This is an example title I see when playing a song in Winamp:
  43. ; "16. Carly Rae Jepsen - Call Me Maybe - Winamp".
  44. ;
  45. ; Now you need to pick a part of the window title that will always be there while playing songs,
  46. ; which can usually be the program's name itself. In this example, "Winamp" will always be in the
  47. ; window's title so I can use that. Note that any other window with "Winamp" in it could interfere
  48. ; and be grabbed instead. Finally, place this value by the spot marked PART 1 in the CONFIGURE ME
  49. ; section. You can now perform Step 7 above to test if this part works for you.
  50. ;
  51. ; Now you need to trim off the parts that you don't want to share on the stream, like the playlist
  52. ; number on the left and the media player's name on the right in this example. To trim the left side,
  53. ; identify the block of text closest to the left side of the untrimmed text that does not change from
  54. ; song to song. In this example, you could use " " (a space), or ". " (a period then space). Now,
  55. ; working from left-to-right, check if this block of text won't occur before you want; otherwise, it
  56. ; will trim from there instead. For example, if the title began with "Curiosity - 16. " and I was
  57. ; using " ", then it would trim off "Curiosity " when I wanted to trim off all of it. Using ". "
  58. ; instead would fix this problem. Many media players give you near full control over the look and
  59. ; ordering of the title elements so keep this in mind if you can't get what you want. To trim the
  60. ; right side, repeat this procedure working from right-to-left instead. In this example, I want to
  61. ; trim " - Winamp" so I can't use " ", but I can use " -" or even " - Winamp". Finally, place these
  62. ; values by the two spots marked PART 2 in the CONFIGURE ME section.
  63. ;
  64. ; If you're using OBS to stream and scrolling the text, then you may want to edit PART 3 to make it
  65. ; look nicer. Other than that, you should be good to go and comfortable editing other things in the
  66. ; CONFIGURE ME section at the very least.
  67.  
  68. ; CONFIGURE ME (START)
  69.   ; Getting the media player's window title, assumes no other window titles have this text
  70.   windowTitle := "Google Chrome"  ; PART 1: The media player's window title needs to always have this text
  71.   SetTitleMatchMode 2  ; Look everywhere in window titles for a match, not just the beginning
  72.   DetectHiddenWindows, on  ; Also check window titles minimized to the system tray
  73.  
  74.   ; Parsing the media player's window title, use "" to not trim one or both of the sides
  75.   firstAfter := ""  ; PART 2: Everything left of the first instance of this and itself is trimmed
  76.   lastBefore := "- Youtube"  ; PART 2: Same idea above except this trims right and reads right-to-left
  77.  
  78.   ; Set the output file
  79.   outputFile := "C:\Users\srki9\Desktop\d\SFMT-master\SFMT-master\nowplaying.txt"
  80.  
  81.   ; Refresh rate in milliseconds for repeating this script
  82.   refreshRate = 3000
  83.  
  84.   ; For scrolling text that wraps continuously without spacing (OBS), use "" to not use this
  85.   scrollSeparator := "Song : "  ; PART 3: Separate the first character from the last character
  86.   AutoTrim, off  ; Leading/trailing space is ignored by AHK by default
  87.  
  88.   ; All 3 streaming programs can use UTF-8 to display Unicode characters
  89.   FileEncoding, UTF-8
  90. ; CONFIGURE ME (END)
  91.  
  92.  
  93. ; PROBABLY DON'T CONFIGURE ME
  94.   ; Part of the AHK template
  95.   #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  96.   ; #Warn  ; Enable warnings to assist with detecting common errors.
  97.   SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  98.   SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  99.  
  100.   ; Keep the script running forever
  101.   #Persistent
  102.  
  103.   ; Main logic of the script
  104.   Gosub, Update  ; Update immediately on script start
  105.   SetTimer, Update, %refreshRate%  ; Update forever on a periodic interval
  106.   return
  107.  
  108.   Update:
  109.     ; Get the unparsed title of the media player's window
  110.     WinGetTitle, title, %windowTitle%
  111.  
  112.     ; Remove junk at the beginning and end of the title
  113.     TrimText(title, firstAfter, lastBefore)
  114.  
  115.     ; Separate the first and last character with a separator for better continuous text scrolling
  116.     title = %scrollSeparator%%title%
  117.  
  118.     ; Check if the file needs to be updated with a new title (avoids unneeded disk writing)
  119.     if !FileEqualsText(outputFile, title)
  120.     {
  121.       ; Replace the file for a new title
  122.       OverwriteFile(outputFile, title)
  123.     }
  124.     return
  125.  
  126.   ; Removes all text before and including the first instance of a substring,
  127.   ; as well as all text after and including the last instance of another substring
  128.   TrimText(ByRef text, firstAfter, lastBefore)
  129.   {
  130.     StringGetPos, leftIndex, text, %firstAfter%
  131.     if leftIndex != -1
  132.     {
  133.       ; text found, trim the left
  134.       start := leftIndex + 1 + StrLen(firstAfter)
  135.     }
  136.     else
  137.     {
  138.       ; text not found, don't trim the left
  139.       start := 1
  140.     }
  141.  
  142.     StringGetPos, rightIndex, text, %lastBefore%, R
  143.     if (rightIndex != -1 && rightIndex != 0)  ; 0 = empty string even though it's right-to-left
  144.     {
  145.       ; text found, trim the right
  146.       length := rightIndex + 1 - start
  147.     }
  148.     else
  149.     {
  150.       ; text not found, don't trim the right
  151.       length := StrLen(text) + 1 - start
  152.     }
  153.  
  154.     text := SubStr(text, start, length)
  155.   }
  156.  
  157.   ; See if a file's text equals another text
  158.   FileEqualsText(ByRef file, ByRef text)
  159.   {
  160.     FileRead, fileText, %file%
  161.     if fileText = %text%
  162.     {
  163.       return true
  164.     }
  165.     else
  166.     {
  167.       return false
  168.     }
  169.   }
  170.  
  171.   ; Overwrites a file's text with new text
  172.   OverwriteFile(ByRef outputFile, ByRef outputText)
  173.   {
  174.     FileDelete, %outputFile%
  175.     FileAppend, %outputText%, %outputFile%
  176.   }



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 954 korisnika na forumu :: 54 registrovanih, 8 sakrivenih i 892 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: amaterSRB, Apok, Bajker 72, Boris BM, Bosnjo, brkan1, BZ, Car89, ccoogg123, crazydkure, cuculo, Denaya, dj.ape, Djole3621, Dolinc, Dorcolac, filip1326, GH69, gregorxix, HrcAk47, Kobrim, Kruger, kulus, KUZMAR, kybonacci, Lazokobra, ljuba.b, loon123, lukisa, Macalone, Makarid, MaksicZoran, MarkoD, mercedesamg, mushroom, Nemanja Opalić, Orc, Papadubi, Pilence, Pv123, Ran, samojednoimeznam, sekretar, sony771, Srle993, synergia, Vlada1389, Vladko, vlahale, vuk77, vuksa72, x011, XBMC, Đurđevdan