2015. december 5., szombat
Mount SD card as executable
sudo mount /dev/mmcblk0p1 /mnt/sdcard/ --options rw,user,noauto,exec
2015. november 9., hétfő
Solve shared libraries error on Ubuntu 14.04 x64: libgconf, libudev
error while loading shared libraries: libgconf-2.so.4: cannot open shared object file: No such file or directory
error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory
Futtasd a Terminálból - Run from Terminal:
sudo apt-get install libgconf-2-4:i386
sudo apt-get install libudev1 && cd /lib/i386-linux-gnu/ && sudo ln -s libudev.so.1 libudev.so.0
error while loading shared libraries: libudev.so.0: cannot open shared object file: No such file or directory
Futtasd a Terminálból - Run from Terminal:
sudo apt-get install libgconf-2-4:i386
sudo apt-get install libudev1 && cd /lib/i386-linux-gnu/ && sudo ln -s libudev.so.1 libudev.so.0
2015. október 3., szombat
Programok processzorhasználatának korlátozása Linuxon
EN: How to Limit The CPU Usage of Any Process in Linux
Do your applications eat up all the CPU resources causing overheat? Not anymore with cpulimit:
https://github.com/sicambria/sh/blob/master/system/cpulimiter.sh
Edit:
BES should do something similar on Windows:
http://mion.faireal.net/BES/
Do your applications eat up all the CPU resources causing overheat? Not anymore with cpulimit:
https://github.com/sicambria/sh/blob/master/system/cpulimiter.sh
Edit:
BES should do something similar on Windows:
http://mion.faireal.net/BES/
2015. július 14., kedd
Firefox hardening - extra biztonságos beállítások
Leírás - description:
https://github.com/pyllyukko/user.js/
https://github.com/pyllyukko/user.js/
cd ~/.mozilla/firefox
git clone 'https://github.com/pyllyukko/user.js.git'
cd XXXXXXXX.your_profile_name
ln -s ../user.js/user.js user.js
Error code: ssl_error_no_cypher_overlap
CIB problem in Firefox - Error code: ssl_error_no_cypher_overlap
Open about:config
Set to false:
security.ssl3.rsa_des_ede3_sha
Open about:config
Set to false:
security.ssl3.rsa_des_ede3_sha
2015. június 30., kedd
Create Jmeter tests on Linux VPS and measure system resource usage with dstat
To run jmeter test from the command line:
http://forraskod.blogspot.hu/2015/06/jmeter-futtatasa-linux-parancssorbol-es.html
sudo service sqoop-metastore stop
sudo service flume-master stop
sudo service flume-ng-agent stop
sudo service oozie stop
sudo service hiveserver2 stop
sudo service hive-metastore stop
sudo service hbase-thrift stop
sudo service hbase-master stop
sudo service hadoop-hbase-regionserver stop
sudo service hadoop-0.20-mapreduce-jobtracker stop
sudo service hadoop-0.20-mapreduce-tasktracker stop
sudo service hadoop-mapreduce-historyserver stop
sudo service hadoop-yarn-nodemanager stop
sudo service hadoop-httpfs stop
sudo service hadoop-hdfs-namenode stop
sudo service hadoop-hdfs-secondarynamenode stop
sudo service hadoop-hdfs-datanode stop
sudo service zookeeper-server stop
sudo service zookeeper stop
sudo pkill -f python
sudo pkill -f java
sudo service munin-node stop
sudo service cloudera-scm-agent stop
wput out.tar.gz ftp://USERNAME:PASSWORD@HOSTNAME/FOLDERNAME/
http://forraskod.blogspot.hu/2015/06/jmeter-futtatasa-linux-parancssorbol-es.html
- Prepare for test - stop all other services
sudo service sqoop-metastore stop
sudo service flume-master stop
sudo service flume-ng-agent stop
sudo service oozie stop
sudo service hiveserver2 stop
sudo service hive-metastore stop
sudo service hbase-thrift stop
sudo service hbase-master stop
sudo service hadoop-hbase-regionserver stop
sudo service hadoop-0.20-mapreduce-jobtracker stop
sudo service hadoop-0.20-mapreduce-tasktracker stop
sudo service hadoop-mapreduce-historyserver stop
sudo service hadoop-yarn-nodemanager stop
sudo service hadoop-httpfs stop
sudo service hadoop-hdfs-namenode stop
sudo service hadoop-hdfs-secondarynamenode stop
sudo service hadoop-hdfs-datanode stop
sudo service zookeeper-server stop
sudo service zookeeper stop
sudo pkill -f python
sudo pkill -f java
sudo service munin-node stop
sudo service cloudera-scm-agent stop
- Running dstat to measure CPU, RAM and disk usage
- Running Jmeter 20 seconds later from the load tester VM:
- Stop dstat 20+ seconds after the Jmeter test has finished
- Repeat the test with other settings (e.g. 50 and 100 users)
- Upload results to an FTP server and download to local computer
wput out.tar.gz ftp://USERNAME:PASSWORD@HOSTNAME/FOLDERNAME/
- Open the results in the local Jmeter GUI and create the graphs
Jmeter futtatása Linux parancssorból és haladó grafikonok használata
EN: Running Jmeter from Linux command line
.jmx teszteset felkészítése a paraméterek kezelésére:
Preparing the .jmx test case for handling parameters
${__P(<variable name>,<default value>)}
to read command line property in JMeter. To pass value as arguments, the command will be:
Futtatás paraméterekkel - 300 másodperces teszt 4 felhasználóval:
Futtatás paraméterekkel - 300 másodperces teszt 4 felhasználóval:
jmeter -n -t PerformanceTest.jmx -Jusers=4 -Jduration=300
${__P(users,2)}
${__P(duration,2)}
${__P(rampup,2)}
${__P(graphcsv,2)}
wget http://mirrors.myaegean.gr/apache//jmeter/binaries/apache-jmeter-2.13.tgz
tar xvzf apache-jmeter-2.13.tgz
ln -s apache-jmeter-2.13/bin/jmeter ./jmeter
Fejlettebb grafikonok kiegészítőkkel:
Creating more advanced graphs with extra plugins
The extra graph options are available after installation in Jmeter > Test plan > Add > Listener
wget http://jmeter-plugins.org/downloads/file/JMeterPlugins-Extras-1.2.1.zip
sudo apt-get install unzip
unzip JMeterPlugins-Extras-1.2.1.zip -d jmeter-extras
cp jmeter-extras/lib/ext/JMeterPlugins-Extras.jar apache-jmeter-2.13/lib/ext/
echo 'OK'
Lessons learned from JAVA (Eclipse) and BPEL (Apache ODE) web service development with a VPS
Bad WSDL address
[WARN] triggerActionNotSupportedFault: messageContext: [MessageContext: logID=cc1127241225dcb1bd08f60239b92862fd39e1c6561a8e27] problemAction: http://transportinc.com/orderTransport/OrderTransport
[ERROR] The [action] cannot be processed at the receiver.
org.apache.axis2.AxisFault: The [action] cannot be processed at the receiver.
Solution: open WSDL and correct the EPR
Memory issues
DU org.apache.catalina.startup.Catalina stop
SEVERE: Catalina.stop
org.apache.catalina.LifecycleException: Failed to stop component [StandardServer[8005]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.startup.Catalina.stop(Catalina.java:762)
at org.apache.catalina.startup.Catalina.start(Catalina.java:724)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:321)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:455)
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardService[Catalina]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.core.StandardServer.stopInternal(StandardServer.java:760)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 8 more
Caused by: org.apache.catalina.LifecycleException: Failed to stop component [StandardEngine[Catalina]]
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:236)
at org.apache.catalina.core.StandardService.stopInternal(StandardService.java:502)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 10 more
Caused by: org.apache.catalina.LifecycleException: A child container failed during stop
at org.apache.catalina.core.ContainerBase.stopInternal(ContainerBase.java:1186)
at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
... 12 more
Exception in thread "RMI RenewClean-[127.0.1.1:39370]"
java.lang.OutOfMemoryError: PermGen space
Add it to Server startup arguments:
You may use 1024M if you have enough RAM:
-XX:MaxPermSize=512M -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
Note from Eclipse console:
- Use CMSClassUnloadingEnabled in place of CMSPermGenSweepingEnabled in the future
Enable MySQL remote connections
sudo perl -pi -e 's?bind-address = 127.0.0.1?bind-address = 0.0.0.0 ?g' /etc/mysql/tomcat-users.xml
Set Tomcat mgmt interface password
sudo perl -pi -e 's?</tomcat-users>?<role rolename="manager-gui"/>\n<user username="ENTER_USERNAME_HERE" password="VERYSECRET_PASS_WORD" roles="manager-gui"/>\n</tomcat-users>?g' /etc/tomcat7/tomcat-users.xml
Copy MySQL connector DLL to VPS Tomcat 7 folder
scp 'WebContent/WEB-INF/lib/mysql-connector-java-5.1.21-bin.jar' USERNAME@IP_OR_HOSTNAME:/usr/share/tomcat7/lib
scp 'WebContent/WEB-INF/lib/mysql-connector-java-5.1.21-bin.jar' USERNAME@IP_OR_HOSTNAME:/usr/share/tomcat7/lib
See JAVA console output on VPS
cd /var/log/tomcat7
- LIVE output:
cd /var/log/tomcat7
tail -f catalina.out
- See last 50 lines:
Címkék:
BPEL,
java,
Tomcat,
web services,
WSDL
2015. június 3., szerda
Exception occurred during code generation for the WSDL java.lang.NullPointerException
Want to generate Web Service skeletons using Eclipse and Axis2 (v1.6.2)?
Don't use extra folder levels relative to Eclipse workspace folder - it's not going to work.
OK
Eclipse_workspace\Eclipse_project_folder...
ERROR
Eclipse_workspace\ONE_MORE_FOLDER_BREAK_AXIS2\Eclipse_project_folder...
Exception occurred during code generation for the WSDL : null
java.lang.NullPointerException
at org.eclipse.jst.ws.axis2.core.utils.ClassLoadingUtil.getAxis2Libs(ClassLoadingUtil.java:97)
at org.eclipse.jst.ws.axis2.core.utils.ClassLoadingUtil.init(ClassLoadingUtil.java:50)
at org.eclipse.jst.ws.axis2.creation.core.command.Axis2WSDL2JavaCommand.execute(Axis2WSDL2JavaCommand.java:105)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.runCommand(CommandFragmentEngine.java:419)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.visitTop(CommandFragmentEngine.java:359)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.moveForwardToNextStop(CommandFragmentEngine.java:254)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager$6.run(SimpleCommandEngineManager.java:294)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:466)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:374)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1059)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager.runForwardToNextStop(SimpleCommandEngineManager.java:264)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.runForwardToNextStop(WizardPageManager.java:91)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.getNextPage(WizardPageManager.java:154)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleWizardPage.getNextPage(SimpleWizardPage.java:136)
at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:935)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:434)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:619)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4454)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3799)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3409)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:832)
at org.eclipse.jface.window.Window.open(Window.java:808)
at org.eclipse.wst.command.internal.env.ui.widgets.popup.DynamicPopupWizard.run(DynamicPopupWizard.java:130)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:253)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4454)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3799)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3409)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Don't use extra folder levels relative to Eclipse workspace folder - it's not going to work.
OK
Eclipse_workspace\Eclipse_project_folder...
ERROR
Eclipse_workspace\ONE_MORE_FOLDER_BREAK_AXIS2\Eclipse_project_folder...
Exception occurred during code generation for the WSDL : null
java.lang.NullPointerException
at org.eclipse.jst.ws.axis2.core.utils.ClassLoadingUtil.getAxis2Libs(ClassLoadingUtil.java:97)
at org.eclipse.jst.ws.axis2.core.utils.ClassLoadingUtil.init(ClassLoadingUtil.java:50)
at org.eclipse.jst.ws.axis2.creation.core.command.Axis2WSDL2JavaCommand.execute(Axis2WSDL2JavaCommand.java:105)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.runCommand(CommandFragmentEngine.java:419)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.visitTop(CommandFragmentEngine.java:359)
at org.eclipse.wst.command.internal.env.core.fragment.CommandFragmentEngine.moveForwardToNextStop(CommandFragmentEngine.java:254)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager$6.run(SimpleCommandEngineManager.java:294)
at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:466)
at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:374)
at org.eclipse.jface.wizard.WizardDialog.run(WizardDialog.java:1059)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleCommandEngineManager.runForwardToNextStop(SimpleCommandEngineManager.java:264)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.runForwardToNextStop(WizardPageManager.java:91)
at org.eclipse.wst.command.internal.env.ui.widgets.WizardPageManager.getNextPage(WizardPageManager.java:154)
at org.eclipse.wst.command.internal.env.ui.widgets.SimpleWizardPage.getNextPage(SimpleWizardPage.java:136)
at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:935)
at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:434)
at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:619)
at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4454)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3799)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3409)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:832)
at org.eclipse.jface.window.Window.open(Window.java:808)
at org.eclipse.wst.command.internal.env.ui.widgets.popup.DynamicPopupWizard.run(DynamicPopupWizard.java:130)
at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:253)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:595)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:511)
at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:420)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4454)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1388)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3799)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3409)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$9.run(PartRenderingEngine.java:1151)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1032)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:148)
at org.eclipse.ui.internal.Workbench$5.run(Workbench.java:636)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:579)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:150)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:135)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:380)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:648)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:603)
at org.eclipse.equinox.launcher.Main.run(Main.java:1465)
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
2015. május 24., vasárnap
Richard Stallman: A Free Digital Society (podcast)
"There are many threats to freedom in the digital society. They include massive surveillance, censorship, digital handcuffs, nonfree software that controls users, and the War on Sharing. Other threats come from use of web services. Finally, we have no positive right to do anything in the Internet; every activity is precarious, and can continue only as long as companies are willing to cooperate with it."
https://archive.org/details/freedigitalsociety20150522
https://archive.org/details/freedigitalsociety20150522
Convert MP3 to OGG with AVCONV
/usr/bin/avconv -y -i "input.mp3" -acodec libvorbis -b:a 256k -vol 256 "output.ogg"
-vol kapcsoló: hangerő állítása:
128: fele hangerő
256: nincs változás
512: kétszeres hangerő
-vol kapcsoló: hangerő állítása:
128: fele hangerő
256: nincs változás
512: kétszeres hangerő
2015. május 23., szombat
YouTube feliratok automatikus fordítása
Get YouTube automatically generated subtitles:
#include<iostream> #include<fstream> #include<cstring> #include<cmath> #include<dirent.h> using namespace std; struct content { string strTime; string text; }; struct Time { int h; int m; int s; int ms; int tms; }; content getNext(ifstream &fin); string &nextch(ifstream &fin, string &test, int length); Time str2time(string t); void showTime(Time, ofstream &fout); void convert(ofstream &fout, ifstream &fin, content A, int line); int main() { dirent *ep; DIR *dp; dp = opendir("./"); ep = readdir(dp); while (ep != NULL) { string name = ep->d_name; if (name.find(".txt") != string::npos) { ifstream fin; fin.open(&name[0]); content test = getNext(fin); if (test.strTime.size() > 0) { string oname = string(&(name[0]), name.size() - 4) + ".YTBCC_eng.srt"; ofstream fout; fout.open(&oname[0]); convert(fout, fin, test, 1); fout.close(); } fin.close(); } ep = readdir(dp); } } void convert(ofstream &fout, ifstream &fin, content A, int line) { content N = getNext(fin); if (N.strTime.size() > 0) { Time F = str2time(A.strTime); Time L = str2time(N.strTime); if (F.tms + 10000 >= L.tms) { fout << line << endl; showTime(F, fout); fout << " --> "; showTime(L, fout); fout << endl; fout << A.text << endl << endl; } else { fout << line << endl; showTime(F, fout); fout << " --> "; Time temp; temp.tms = F.tms + 10000; //limit 10 seconds per line temp.h = temp.tms / 3600000; temp.m = (temp.tms - temp.h * 3600000) / 60000; temp.s = (temp.tms - temp.h * 3600000 - temp.m * 60000) / 1000; temp.ms = F.ms; showTime(temp, fout); fout << endl; fout << A.text << endl << endl; } convert(fout, fin, N, line + 1); } else { fout << line << endl; Time Pr = str2time(A.strTime); showTime(Pr, fout); fout << " --> "; Time Ne; Ne.ms = Pr.ms; int all_t = Pr.h * 3600 + Pr.m * 60 + Pr.s + 6; Ne.h = all_t / 3600; Ne.m = (all_t - Ne.h * 3600) / 60; Ne.s = all_t - Ne.h * 3600 - Ne.m * 60; showTime(Ne, fout); fout << endl; fout << A.text << endl; } } content getNext(ifstream &fin) { string strTime, text; string keyTime = "data-time=\""; string keyText = "<div class=\"caption-line-text\">"; int size_ktime = keyTime.size(); int size_ktext = keyText.size(); bool jud = 1; //judge if our time and text are //contained in txt file //1 == be not contained string test; //get strTime test = nextch(fin, test, size_ktime); if (test != "\0") { do { if (test == keyTime) { jud = 0; break; } else test = nextch(fin, test, size_ktime); }while (test != "\0"); if (jud) return {"\0", "\0"}; else { char ch = fin.get(); while(ch != '\"') { strTime = strTime + ch; ch = fin.get(); } //ensure the form of strTime is XXX.XXX jud = 1;//here jud = 1 means that the form is XXX,no '.' for (int i = 0; i < strTime.size(); i++) { if(strTime[i] == '.') { jud = 0; break; } } if (jud) strTime = strTime + ".0"; } } else return {"\0", "\0"}; //get text jud = 1; test = string(); test = nextch(fin, test, size_ktext); if (test != "\0") { do { if (test == keyText) { jud = 0; break; } else test = nextch(fin, test, size_ktext); } while (test != "\0"); if (jud) return {"\0", "\0"}; else { char ch = fin.get(); while (ch != '<') { text = text + ch; ch = fin.get(); } } } else return {"\0", "\0"}; return {strTime, text}; } string &nextch(ifstream &fin, string &test, int length) { int n = test.size(); if(n > 0) { char ch = fin.get(); if (!fin.eof()) { for (int i = 0; i < n - 1; i++) test[i] = test[i + 1]; test[n - 1] = ch; return test; } else { test = "\0"; return test; } } else { char ch = fin.get(); for (int i = 0; i < length; i++) { if (!fin.eof()) { test = test + ch; if (i < length - 1) ch = fin.get(); } else { test = "\0"; return test; } } return test; } } Time str2time(string t) { int k = 0; while (t[k] != '.') { k++; } int h, m, s, ms, tms, time; time = 0; for (int i = 0; i < k; i++) { time = time + (t[i] - 48) * int(pow(10.0, k - i - 1)); } h = time / 3600; m = (time - h * 3600) / 60; s = time - h * 3600 - m * 60; ms = 0; int length = t.size(); for (int i = k + 1; i < length; i++) ms = ms + (t[i] - 48) * int(pow(10.0, 3 - i + k)); tms = time * 1000 + ms; Time E = {h, m, s, ms, tms}; return E; } void showTime(Time T, ofstream &fout) { if (T.h < 10) fout << "0" << T.h; else fout << T.h; fout << ":"; if (T.m < 10) fout << "0" << T.m; else fout << T.m; fout << ":"; if (T.s < 10) fout << "0" << T.s; else fout << T.s; if (T.ms == 0) fout << ",000"; else { fout << ","; if (T.ms < 10) fout << "00" << T.ms; else if (T.ms < 100) fout << "0" << T.ms; else fout << T.ms; } }
https://code.google.com/p/youtube-subtitles-download/
Feliratkozás:
Bejegyzések (Atom)